Redis教程

Redis

本文主要是介绍Redis,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

第一步:加依赖

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

第二步:配置

# Redis相关配置
#Redis数据库索引(默认为0)
spring.redis.database=0
#Redis服务地址
spring.redis.host=192.168.0.24
#redis服务器连接端口
spring.redis.port=6379
#redis服务器连接密码(默认为空)
spring.redis.password=
#连接池最大连接数(负值表示没有限制)
spring.redis.pool.max-active=200


#连接池最大阻塞等待时间(使用负值标识没有限制)
spring.redis.jedis.pool.max-wait = 5000ms
#连接池最大的空闲连接
spring.redis.jedis.pool.max-Idle = 100
#连接池最小空闲连接
spring.redis.jedis.pool.min-Idle = 10
#连接超时时间(毫秒)
spring.redis.timeout = 10s


#下面两个是集群配置
#spring.redis.cluster.nodes = 192.168.31.81:6379,192.168.31.81:6380,192.168.31.81:6381
#spring.redis.cluster.max-redirects=5
# Redis相关配置   
spring.redis.jedis.pool.max-wait = 5000ms
spring.redis.jedis.pool.max-Idle = 100
spring.redis.jedis.pool.min-Idle = 10
spring.redis.timeout = 10s

#Redis服务地址
spring.redis.host=192.168.0.24
spring.redis.port=6379
 

第三步就是在代码中注入 RedisTemplate<String,String> redisTemplate;

 注入
 @Autowired
    private RedisTemplate<String,String> redisTemplate;
    //后面为有效期5分钟  存
redisTemplate.opsForValue().set(redisKey, code, Duration.ofMinutes(5)); 
//取
 redisTemplate.opsForValue().get(redisKey);
    

还需接着完善

这篇关于Redis的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!