RedisRedis

redis 配置远程连接

2021-08-22  本文已影响0人  yjtuuige

开启远程连接的一般步骤:

  1. 屏蔽本地绑定信息,修改 redis.conf
  1. 设置 requirepass(可不设置)
    查找 # requirepass foobared,去掉注释 requirepass 自定义密码
    设置后的连接方式:
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.     # 提示需要登录
127.0.0.1:6379> auth "yourpassword"         # 输入密码
  1. 重启 reids:
  1. 加入防火墙规则
    iptables -I INPUT -p tcp -m state –state NEW -m tcp –dport 6379 -j ACCEPT

java 连接测试

package com.demo;
import redis.clients.jedis.Jedis;
public class TestPing {
    public static void main(String[] args) {
//        Jedis jedis = new Jedis("127.0.0.1", 6379);
        Jedis jedis = new Jedis("IP", 6379);
        jedis.auth("密码");
        String response = jedis.ping();
        System.out.println(response);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读