Skip to content

Instantly share code, notes, and snippets.

@ishiis
Last active October 15, 2016 07:22
Show Gist options
  • Save ishiis/9b5b8d008ac02b13581411faff4242b6 to your computer and use it in GitHub Desktop.
Save ishiis/9b5b8d008ac02b13581411faff4242b6 to your computer and use it in GitHub Desktop.
<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
  <version>2.9.0</version>
</dependency>
Set<String> hosts = new HashSet<>();
hosts.add("127.0.0.1:26379");
hosts.add("127.0.0.1:26380");
hosts.add("127.0.0.1:26381");
JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster", hosts);
Jedis jedis = jedisSentinelPool.getResource();
jedis.select(5);
for (int i = 0 ; i < 100 ; i ++){
  jedis.set("key_" + i, "value_" + i);
}
jedisSentinelPool.close();
redis-cli -n 5 -p 6379
127.0.0.1:6379[5]> keys *
  1) "key_54"
  2) "key_67"
  3) "key_12"
  4) "key_0"

https://github.com/sectlvy/jdata/blob/master/src/main/java/com/lkl/redis/RedisDao.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment