Java用Jedis连接阿里云的Redis时的配置
1、修改配置redis.conf 文件:
- 将bind 127.0.0.1注释掉,
- 将protected-mode yes 改为 no。
2、开放端口
- firewall-cmd --zone=public --add-port=6379/tcp --permanet # 开放端口
- systemctl restart firewalld.service # 重启防火墙
- 阿里云控制台配置安全组
- 重启redis
引入依赖:
<dependencies>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
</dependencies>
测试:
Jedis jedis = new Jedis("8.131.*.*",6379);//阿里云服务器的公网IP
System.out.println(jedis.ping());