Redis遇到的坑

1.Redis连接不上的问题

1.1 首先查看applicaiton.yml文件中是否设置了密码password: 123456,然后看redis本身是否有密码(redis第一次安装默认没有密码),要是applicaiton.yml有密码,redis没设密码,会出现连接不上,直接注掉#password: 123456可以访问,相反同理。

1.2 (在1.1不成功后,查看配置文件redis.conf是否出错)

    修改redis.conf文件

      1.将bind 127.0.0.1加上注释,(#bind 127.0.0.1),允许出本机外的IP访问redis

      2.将protected-mode yes,修改为protected-mode no;不保护redis

      3.将daemonize no,修改为daemonize yes;允许redis服务后台运行

      4、重新启动redis,重启redis的时候一定要制定配置文件,不然修改后的配置文件是没有发挥作用的
        ./redis-server /usr/local/redis/etc/redis.conf

2.org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out

    错误原因:连接超时时间设置的过于短暂(我这边设置成了0),修改为60000左右即可
    
```java
spring:
  redis:
    #设置数据库索引
    database: 0
    #Redis服务器地址
    host: 10.1.1.1
    #Redis服务器连接端口
    port: 6379
    #Redis服务器连接密码(默认为空)
    #password: 123456
    #连接池最大连接数(使用负值表示没有限制)
    lettuce:
      pool:
        max-active: 10
    #连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: -1
    #连接池中的最大空闲连接
        max-idle: 10
    #连接池中的最小空闲连接
        min-idle: 0
    #连接超时时间(毫秒)
    timeout:  60000
```

3.io.lettuce.core.RedisCommandExecutionException: ERR Client sent AUTH, but no password is set
  意思就是redis服务器没有设置密码,但客户端向其发送了AUTH请求
  applicaiton.yml直接注掉密码#password: 123456就可以访问了。

4.io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required解决方法
  出现认证问题,应该是设置了认证密码,在配置文件application.yml中加入password: 123456即输入密码就可以啦

你可能感兴趣的:(Redis)