File tree Expand file tree Collapse file tree
simple-framework/src/main/java/top/cadecode/framework/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import org .springframework .cache .caffeine .CaffeineCacheManager ;
88import org .springframework .context .annotation .Bean ;
99import org .springframework .context .annotation .Configuration ;
10+ import org .springframework .data .redis .connection .RedisConnectionFactory ;
11+ import org .springframework .data .redis .core .RedisTemplate ;
12+ import org .springframework .data .redis .serializer .RedisSerializer ;
1013import top .cadecode .common .util .TokenUtil ;
1114
1215import java .util .concurrent .TimeUnit ;
2225public class CacheConfig {
2326
2427 private final TokenUtil tokenUtil ;
28+ private final RedisConnectionFactory factory ;
2529
2630 @ Bean ("securityCacheManager" )
2731 public CacheManager securityCacheManager () {
@@ -32,4 +36,16 @@ public CacheManager securityCacheManager() {
3236 caffeineCacheManager .setAllowNullValues (true );
3337 return caffeineCacheManager ;
3438 }
39+
40+ @ Bean ("redisTemplate" )
41+ public RedisTemplate <String , Object > redisTemplate () {
42+ RedisTemplate <String , Object > template = new RedisTemplate <>();
43+ template .setConnectionFactory (factory );
44+ // 设置 k v 的序列化方式
45+ template .setKeySerializer (RedisSerializer .string ());
46+ template .setValueSerializer (RedisSerializer .json ());
47+ template .setHashKeySerializer (RedisSerializer .string ());
48+ template .setHashValueSerializer (RedisSerializer .json ());
49+ return template ;
50+ }
3551}
You can’t perform that action at this time.
0 commit comments