redis整合springboot
redis参照processon图,包含redis知识库。
https://www.processon.com/mindmap/5fab94d77d9c0865e9bc7838
redis面试题,使用场景等
https://mp.weixin.qq.com/s?__biz=MzIwODI1OTk1Nw==&mid=2650321227&idx=1&sn=d60883728b0c7479e1e55381e7559ad8&scene=19#wechat_redirect
依赖中配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
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);
}