通过使用jedis.jar
public static void main(String[] args) {
Jedis jedis = new Jedis("linux系统的ip地址", redis 的端口号);
System.out.println(jedis.ping());
}
如果出现异常Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException
主要有三个原因
1.ip,端口不正确
2.linux开启了防火墙
(centos6.5关闭防火墙:service iptables stop && chkconfig iptables off,
查看防火墙是否已关闭:service iptables status)
3.redis.conf中的bind 127.0.0.1未用#注释掉
如果连接依然报错,可把redis.conf中的protected-mode改为no