报错:redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required
- jedis单机使用jedis.auth来进行设置
Jedis jedis = new Jedis("127.0.0.1",6379); jedis.auth("password");
- JedisCluster设置
import java.io.IOException; import java.util.HashSet; import java.util.Set; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPoolConfig; public class GetData { public static void main(String[] args) throws IOException { JedisPoolConfig config = new JedisPoolConfig(); config .setMaxTotal(500); config .setMinIdle(2); config .setMaxIdle(500); config .setMaxWaitMillis(10000); config .setTestOnBorrow(true); config .setTestOnReturn(true); Set<HostAndPort> nodes = new HashSet<>(); nodes.add(new HostAndPort("xxxx", 6379)); nodes.add(new HostAndPort("xxxx", 6380)); nodes.add(new HostAndPort("xxxx", 6381)); nodes.add(new HostAndPort("xxxx", 6382)); JedisCluster jedis = new JedisCluster(nodes, 10000, 10000, 100, "password", i2); } }
通过JedisCluster jedis = new JedisCluster(nodes, 10000, 10000, 100, “password”, config); 来设置集群密码:但是jedis版本必须是2.9及以上