Using java to operate redis

HairLossException 2022-01-26 11:28:34 阅读数:636

using java operate redis

1、 establish maven java engineering

 Insert picture description here

2、 Add dependency

stay <dependencies> Add under label jedis Dependence and fastjson rely on

<!--jedis rely on -->
<!--fastjson rely on -->

3、 establish Jedis object

public class AppTest {

public void test(){

/* host:ip Address port: Port number */
Jedis jedis = new Jedis("",6379);
//ping redis The server Returns if the connection is successful pong
String returnMessage =;
// Save the data 
// Take the data 
String name = jedis.get("name");
String age = jedis.get("age");

4、 start-up redis service

redis-server redis6379.conf & // start-up redis service
systemctl stop firewalld // Turn off firewall

 Insert picture description here

5、 test

 Insert picture description here

copyright:author[HairLossException],Please bring the original link to reprint, thank you.