Redis error -Unable to connect to 127.0.0.1:6379

2,631 阅读1分钟

错误描述

Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379

Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 1 minute(s)

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379

原因

redis默认只支持本地连接

修改为0.0.0.0时,这样就可以支持外机连接了

redis3.2版本后新增protected-mode配置,默认是yes,即开启。设置外部网络连接redis服务,设置方式如下:

1、关闭protected-mode模式,此时外部网络可以直接访问

2、开启protected-mode保护模式,需配置bind ip或者设置访问密码

解决办法

修改redis.windows.conf如下:

requirepass 123456 #设置密码

#bind 127.0.0.1

#protected-mode yes 

protected-mode no

使用

redis-cli -h 127.0.0.1 -p 6379 -a 123456

ping

select 1

keys *

get XXX