首页 > 编程语言 > 详细

[redis]springboot中快速使用redis

时间:2021-04-28 16:24:54      阅读:15      评论:0      收藏:0      [点我收藏+]

一、POM.xml (maven导入相应的包)

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

 

二、Application.properties配置集群(只要配置master)

#配置redis---start---
#只配置一台
#spring.redis.host=55.6.75.252
#只配置一台
#spring.redis.port=6380
#配置集群
spring.redis.cluster.nodes=55.6.75.252:6380,55.6.75.252:6382,55.6.75.252:6384
spring.redis.cluster.max-redirects=3
spring.redis.password=Cmb@2020
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=20
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000
#配置redis---end---

 

三、编写@Service

@Service
public class RedisService
{
    @Autowired RedisTemplate redisTemplate;

    public void setKV(String key,Object value)
    {
        redisTemplate.opsForValue().set ( key,value );
    }

    public Object getV(String key)
    {
        return redisTemplate.opsForValue ().get ( key );
    }


}

四、后续代码直接以下使用即可。

@Resource RedisService redisService;

 

[redis]springboot中快速使用redis

原文:https://www.cnblogs.com/SKeyC27/p/14714160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!