当前位置:   article > 正文

Redis的安装启动和redisManager的连接和Spring Boot集成

redismanager

redis下载地址: 

​​​​​​https://github.com/microsoftarchive/redis/releases

 redis启动

进入到安装的Redis的目录中,通过DOS命令 redis-server --service-install redis.windows-service.conf --loglevel verbose

打开服务

 (**启动报错1067的话,在刚才redis的目录下新建文件夹Logs然后再次启动即可。**

Redis Desktop Manager

下载:https://pan.baidu.com/s/1zmHQBaaVFqht6VDKpLCONQ    提取码:n301 

连接 

集成SpringBoot

  1. <!-- redis-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-data-redis</artifactId>
  5. </dependency>

application配置增加

  1. #redis config
  2. spring.redis.host=127.0.0.1
  3. #Redis服务器连接端口
  4. spring.redis.port=6379
  5. #Redis服务器连接密码(默认为空)
  6. #spring.redis.password=123456
  7. #连接池最大连接数(使用负值表示没有限制)
  8. spring.redis.pool.max-active=8
  9. #连接池最大阻塞等待时间(使用负值表示没有限制)
  10. spring.redis.pool.max-wait=-1
  11. #连接池中的最大空闲连接
  12. spring.redis.pool.max-idle=8
  13. #连接池中的最小空闲连接
  14. spring.redis.pool.min-idle=0
  15. #连接超时时间(毫秒)
  16. spring.redis.timeout=30000

redis配置,解决key,value 乱码

  1. package com.goldnet.common.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.data.redis.connection.RedisConnectionFactory;
  5. import org.springframework.data.redis.core.RedisTemplate;
  6. import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
  7. import org.springframework.data.redis.serializer.StringRedisSerializer;
  8. //自定义RedisConfig
  9. @Configuration
  10. public class RedisConfig {
  11. @Bean
  12. public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
  13. RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
  14. redisTemplate.setConnectionFactory(factory);
  15. //采用String的序列化方式
  16. redisTemplate.setKeySerializer(new StringRedisSerializer());
  17. // value序列化方式采用jackson
  18. redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
  19. redisTemplate.setHashKeySerializer(new StringRedisSerializer());
  20. redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
  21. return redisTemplate;
  22. }
  23. }

代码使用

  1. @Autowired
  2. private RedisTemplate redisTemplate;
  3. {
  4. redisTemplate.opsForValue().set("redis",purchaseContracts);
  5. List<PurchaseContract> redis = (List<PurchaseContract>)
  6. redisTemplate.opsForValue().get("redis");
  7. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/845956
推荐阅读
相关标签
  

闽ICP备14008679号