redis集群链接-java

java链接redis集群报错:

redis.clients.jedis.exceptions.JedisDataException: MOVED 13102 127.0.0.1


MOVED indicates that you're using Redis Cluster. ShardedJedis is not for Redis Cluster, so you should use JedisCluster instead. Please note that JedisCluster doesn't have pipeline mode, so you may want to send your operation one by one.

大概意思就是ShardedJedis 不能用于Redis集群,要用JedisCluster 代替ShardedJedis 才可以,而且JedisCluster 还没有pipeline 模式,所以一次只能执行一个操作


JedisCluster jedisCluster = RedisUtils.getJedisCluster(
new HostAndPort("192.168.0.140", 7000),
new HostAndPort("192.168.0.140", 7001),
new HostAndPort("192.168.0.140", 7002),
new HostAndPort("192.168.0.140", 7003),
new HostAndPort("192.168.0.140", 7003),
new HostAndPort("192.168.0.140", 7004)
);

jedisCluster.hset("hashs", "hello2", "world2");
print("判断是否存在key001:"+jedisCluster.hexists("hashs", "hello2"));
print("查找key001的值:"+jedisCluster.hget("hashs", "hello2"));

猜你喜欢

转载自blog.csdn.net/lb7758zx/article/details/72303120
今日推荐