码迷,mamicode.com
首页 > 编程语言 > 详细

redis整合springboot

时间:2020-12-05 10:54:05      阅读:9      评论:0      收藏:0      [点我收藏+]

标签:default   tco   def   spring   utils   pen   tor   disco   etc   

redis参照processon图,包含redis知识库。
https://www.processon.com/mindmap/5fab94d77d9c0865e9bc7838

依赖中配置

org.springframework.boot
spring-boot-starter-data-redis

public String getDBStr(int db, String key) {
RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
RedisConnection redisConnection = RedisConnectionUtils.bindConnection(connectionFactory);
DefaultStringRedisConnection stringRedisConnection = new DefaultStringRedisConnection(redisConnection);
stringRedisConnection.select(db);
return stringRedisConnection.get(key);
}

public void setDBStr(int db, String key, String value) {
RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
RedisConnection redisConnection = RedisConnectionUtils.bindConnection(connectionFactory);
DefaultStringRedisConnection stringRedisConnection = new DefaultStringRedisConnection(redisConnection);
stringRedisConnection.select(db);
stringRedisConnection.set(key, value);
}

redis整合springboot

标签:default   tco   def   spring   utils   pen   tor   disco   etc   

原文地址:https://www.cnblogs.com/stubborn-dude/p/13959849.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!