jedis使用

public class JedisTest {
/**
* 单机版jedis测试
*/
@Test
public void jedisTest() {
Jedis jedis=new Jedis("192.168.25.131", 6379);
jedis.set("zsc1", "zsc1");
String string = jedis.get("zsc1");
System.out.println(string);
jedis.close();
}
/**
* 连接池jedispool测试
*/
@Test
public void jedisPoolTest() {
JedisPool jedisPool=new JedisPool("192.168.25.131", 6379);
Jedis jedis = jedisPool.getResource();
jedis.set("zsc2", "zsc2");
String string = jedis.get("zsc2");
System.out.println(string);
jedis.close();
jedisPool.close();
}
/**
* 集群jedisCluster测试
*/
@Test
public void jedisClusterTest() {
Set<HostAndPort> nodes=new HashSet<>();
nodes.add(new HostAndPort("192.168.25.131", 7001));
nodes.add(new HostAndPort("192.168.25.131", 7002));
nodes.add(new HostAndPort("192.168.25.131", 7003));
nodes.add(new HostAndPort("192.168.25.131", 7004));
nodes.add(new HostAndPort("192.168.25.131", 7005));
nodes.add(new HostAndPort("192.168.25.131", 7006));
JedisCluster cluster=new JedisCluster(nodes);
cluster.set("zsc3", "zsc3");
String string = cluster.get("zsc3");
System.out.println(string);
cluster.close();
}
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页