以下是从jedis github页面直接复制的Jedis文档:
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
JedisShardInfo si = new JedisShardInfo("localhost", 6379);
si.setPassword("foobared");
shards.add(si);
si = new JedisShardInfo("localhost", 6380);
si.setPassword("foobared");
shards.add(si);
那么,ShardedJedis
有两种使用方式。直接连接或使用 ShardedJedisPool
。为了可靠运行,后者必须在多线程环境中使用。
2.a) 直接连接:
ShardedJedis jedis = new ShardedJedis(shards);
jedis.set("a", "foo");
jedis.disconnect;
2.b) 池化连接:
ShardedJedisPool pool = new ShardedJedisPool(new Config(), shards);
ShardedJedis jedis = pool.getResource();
jedis.set("a", "foo");
.... // do your work here
pool.returnResource(jedis);
.... // a few moments later
ShardedJedis jedis2 = pool.getResource();
jedis.set("z", "bar");
pool.returnResource(jedis);
pool.destroy();
上面的例子展示了如何使用ShardedJedis
。
在我当前的设置中,我使用的是 RedisTemplate
和 JedisConnectionFactory
。
我的问题是
How do I use
ShardedJedis
withRedisTemplate
?
最佳答案
我认为它不直接支持您的情况。 RedisTemplate 为 Redis 交互提供了高级抽象。 而 RedisConnection 提供了接受和返回二进制值(字节数组)的低级方法。
关于java - 将 ShardedJedis 与 RedisTemplate 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29616706/