在springBoot中集成redis(window zip版)
解压redis64-3.0.501.zip 即可使用
启动redis redis-server.exe redis.windows.conf
启动客户端:redis-cli.exe -h 127.0.0.1(初始redis是无密码的)
启动客户端也可以通过redis64-3.0.501(redis解压包)下的redis-cli.exe启动
接下来在springBoot中集成redis
首先导入依赖
<!-- redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
然后在application中配置redis
spring.redis.database=0 spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.password=gzsendi1! spring.redis.pool.max-active=10 spring.redis.pool.max-wait=-1 spring.redis.pool.max-idle=8 spring.redis.pool.min-idle=0 spring.redis.timeout=0
注意:配置中不能出现空格,空格在window不会出现问题,但是在linux会识别空格导致配置不正确
接下来在controller中注入redisTemplate就可以使用redis了
@Autowired private RedisTemplate<String, String> redisTemplate;
使用
String value= redisTemplate.opsForValue().get("test");以上就是在springBoot中加入本地redis以及相关配置