环境
Windows 10
Redis 下载
https://github.com/microsoftarchive/redis/releases
下载Redis-x64-3.0.504.zip,并解压
配置Redis
- 如果你直接双击redis-server.exe则会看到如下一段文字,意思是没有指定配置文件,则采用默认的配置文件。如果你一开始在redis.windows.conf或者redis.windows-service.conf文件中进行了配置,却没有得到正确的结果,可能就是这个原因。
Warning: no config file specified, using the default config. In order to specify a config file use D:\develop\redis\hospital\redis\redis-server.exe /path/to/redis.conf
- 在文件夹下新建redis.conf文件,并输入如下配置
include .\redis.windows.conf
requirepass hospital
- Spring Boot 整合Redis application.properties中相应的配置
#-----------------------------------------redis-----------------------
#Redis库的编号,Redis中提供了16个database,编号0~15
spring.redis.database=0
#Redis示例实例的地址
spring.redis.host=localhost
#Redis端口号,默认是6379
spring.redis.port=6379
#Redis登录密码
spring.redis.password=hospital
#Redis连接池的最大连接数
spring.redis.jedis.pool.max-active=8
#连接池中的最大空闲连接数
spring.redis.jedis.pool.max-idle=8
#连接池的最大阻塞等待时间,默认为-1,表示没有限制
spring.redis.jedis.pool.max-wait=-1ms
#连接池最小空闲连接数
spring.redis.jedis.pool.min-idle=0
运行
- 在文件夹下Shift + 鼠标右键 打开PowerShell 输入命令
./redis-server.exe redis.conf
异常
- 如果在Spring Boot application.properties配置文件中配置了spring.redis.password,而在运行redis时没有指定配置文件,那么相当于在配置文件中没有配置密码,所以就会报出如下异常。
redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set