提交 | 用户 | age
|
da6731
|
1 |
package com.hx.redisson.manager; |
C |
2 |
|
848054
|
3 |
import org.redisson.api.RedissonClient; |
da6731
|
4 |
import org.springframework.data.redis.core.RedisTemplate; |
C |
5 |
|
|
6 |
import java.util.Map; |
|
7 |
import java.util.concurrent.ConcurrentHashMap; |
|
8 |
|
|
9 |
/** |
|
10 |
* redis管理 |
|
11 |
* |
|
12 |
* @author CJH |
|
13 |
* @date 2022-06-27 |
|
14 |
*/ |
|
15 |
public class RedisManager { |
|
16 |
|
|
17 |
private Map<String, RedisTemplate> redisTemplateMap = new ConcurrentHashMap<>(); |
|
18 |
|
848054
|
19 |
public static Map<String, RedissonClient> redissonTemplateMap = new ConcurrentHashMap<>(); |
F |
20 |
|
da6731
|
21 |
/** |
C |
22 |
* 构造方法初始化 redisTemplateMap 的数据 |
|
23 |
* |
|
24 |
* @param redisTemplateMap |
|
25 |
*/ |
|
26 |
public RedisManager(Map<String, RedisTemplate> redisTemplateMap) { |
|
27 |
this.redisTemplateMap = redisTemplateMap; |
|
28 |
} |
848054
|
29 |
|
da6731
|
30 |
|
C |
31 |
/** |
|
32 |
* 根据数据库序号,返回对应的RedisTemplate |
|
33 |
* |
|
34 |
* @param dbIndex 序号 |
|
35 |
* @return {@link RedisTemplate} |
|
36 |
*/ |
|
37 |
public RedisTemplate getRedisTemplate(Integer dbIndex) { |
|
38 |
RedisTemplate redisTemplate = redisTemplateMap.get("redisTemplate" + dbIndex); |
|
39 |
if (redisTemplate == null) { |
|
40 |
throw new RuntimeException("Map不存在该redisTemplate"); |
|
41 |
} |
|
42 |
return redisTemplate; |
|
43 |
} |
|
44 |
|
848054
|
45 |
|
da6731
|
46 |
} |