全部异常如下
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196)
at redis.main(redis.java:9)
错误原因:这是一个有密码的redis,你需要输入密码,最简单的连接如下
import redis.clients.jedis.Jedis;
public class redis {
public static void main(String[] args) {
//连接本地的 Redis 服务
Jedis jedis = new Jedis("redis的ip",6379);
//设置密码
jedis.auth("123456");
System.out.println("连接成功");
//查看服务是否运行
System.out.println("服务正在运行: "+jedis.ping());
}
}