问题:通过jedisCluster.auth(”password”);
报错:redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required
如果是jedis单机模式的话,我们可以直接使用jedis.auth来进行设置
Jedis jedis = new Jedis("127.0.0.1",6379);
jedis.auth("password");
但是 jedisCluster.auth(”password”);查看源码发现只是实现了异常处理,并没有什么用。
/**
* @deprecated No key operation doesn't make sense for Redis Cluster and Redis Cluster doesn't
* support authorization scheduled to be removed on next major release
*/
@Deprecated
@Override
public String auth(String password) {
throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
}
查看JedisCluster构造方法发现,有一个这样的
new JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout, int soTimeout,int maxAttempts, String password, final GenericObjectPoolConfig poolConfig);
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及以上
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/182108.html原文链接:https://javaforall.cn