Jedis connected to Redis error: java.net.ConnectException: Connection refused: connect

Test code:

public class TestJedis {
    
    
    @Test
    public void test01(){
    
    
        //1:创建一个Jedis对象   创建一个连接,参1 ip地址 参2 端口
        Jedis jedis = new Jedis("localhost", 6379);
        //2:执行Redis的指令(set指令)
        //写入数据
        jedis.set("name","[email protected]");//添加 string-string
        jedis.sadd("set","hello","[email protected]","Welcome to use");//添加string-set集合类型
        //读取数据
        System.out.println(jedis.get("name"));
        System.out.println(jedis.smembers("set"));
        //关闭连接
        jedis.close();
    }
}

wrong description

redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect

Insert picture description here

Cause of the error: The Redis connected by Jedis did not start the server.

Solution:

Start the Redis server connected by Jedis, because here I am connecting to localhost, so I just start redis-server.exeit.

redis-server.exeRun successfully after startup !
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/108736292