连接
redis-cli -h {server_ip} -p {port} -a {password}
常用错误
使用Jedis连接redis出现Cannot get Jedis connection; Could not get a resource from the pool错误
具体报错信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
出现错误的原因可能有以下几点:
- 查看Jedis配置redis的信息是否有误,主要是ip,端口和密码是否写错。
- 查看服务器防火墙是否关闭,查看指令:systemctl status firewall,如果出现Active:active(running)则表示防火墙是处于开启状态的,需要关闭。 关闭指令:systemctl stop firewall。关闭后是Active: inactive (dead)。
- 修改redis配置文件redis.conf。找到bind 127.0.0.1,把它进行注释掉;找到protected-mode yes 把它改成no。
- 如果是使用spring-session需要依赖redis2.8.0以上版本,并且需要开启:notify-keyspace-events gxE;同样在redis.conf中修改。
上述若修改了redis.conf文件,则必须要重启redis服务器。
参考:https://www.jianshu.com/p/be31ba7a43fe
Linux安装Redis:https://baijiahao.baidu.com/s?id=1722728002073366376&wfr=spider&for=pc
标签:resource,get,Redis,redis,springframework,Jedis,常用命令,org From: https://blog.51cto.com/u_15570188/6940350