如果单机的情况下,使用
Jedis jedis = new Jedis("172.16.255.231",6379);
jedis.set("name","lijia");
System.out.println(jedis.get("name"));
如果集群的情况下
import java.util.HashSet;
import java.util.Set;
public class RedisUtils {
public static void main(String[] args) {
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
JedisCluster jc=null;
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7001));
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7002));
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7003));
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7004));
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7005));
jedisClusterNodes.add(new HostAndPort("172.16.255.231", 7006));
jc=new JedisCluster(jedisClusterNodes);
long starttime=System.currentTimeMillis();
System.out.println(jc.get("foo")); //传入key值
}
如果都不报错说明正常,但是连接之前先检查服务器防火墙是否关闭。
网友评论