|
@@ -41,13 +41,13 @@ public class RedisGroupStore implements GroupStore {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取Redis用户分组标识
|
|
|
+ * 获取用户分组标识
|
|
|
*
|
|
|
+ * @param id 用户ID
|
|
|
* @return Redis标识
|
|
|
*/
|
|
|
- private String key() {
|
|
|
- Long id = SessionContextHolder.getId();
|
|
|
- return id == null ? null : ("group:" + id);
|
|
|
+ private String key(Long id) {
|
|
|
+ return "group:" + id;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -139,9 +139,8 @@ public class RedisGroupStore implements GroupStore {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Caps get(@NonNull String scene) {
|
|
|
- String key = this.key();
|
|
|
- if (StringUtils.isEmpty(key)) {
|
|
|
+ public Caps get(Long id, @NonNull String scene) {
|
|
|
+ if (id == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -152,6 +151,7 @@ public class RedisGroupStore implements GroupStore {
|
|
|
}
|
|
|
|
|
|
// 获取分组标识,如果缓存不存在则重新加载分组并更新缓存
|
|
|
+ String key = this.key(id);
|
|
|
RedisTemplate<String, Object> template = RedisContextHolder.getDefaultTemplate();
|
|
|
HashOperations<String, String, String> operations = template.opsForHash();
|
|
|
group = StringUtils.ifEmpty(operations.get(key, scene), Caps::valueOf);
|
|
@@ -162,9 +162,8 @@ public class RedisGroupStore implements GroupStore {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Caps> get(@NonNull Collection<String> scenes) {
|
|
|
- String key = this.key();
|
|
|
- if (StringUtils.isEmpty(key) || ObjectUtils.isEmpty(scenes)) {
|
|
|
+ public Map<String, Caps> get(Long id, @NonNull Collection<String> scenes) {
|
|
|
+ if (id == null || ObjectUtils.isEmpty(scenes)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
|
|
@@ -181,6 +180,7 @@ public class RedisGroupStore implements GroupStore {
|
|
|
}
|
|
|
|
|
|
// 批量获取缓存分组映射
|
|
|
+ String key = this.key(id);
|
|
|
RedisTemplate<String, Object> template = RedisContextHolder.getDefaultTemplate();
|
|
|
if (ObjectUtils.notEmpty(nones)) {
|
|
|
HashOperations<String, String, String> operations = template.opsForHash();
|
|
@@ -211,16 +211,19 @@ public class RedisGroupStore implements GroupStore {
|
|
|
|
|
|
@Override
|
|
|
public Caps set(@NonNull String scene, @NonNull Caps group) {
|
|
|
- String key = this.key();
|
|
|
- return StringUtils.isEmpty(key) ? group : this.setnx(key, scene, group);
|
|
|
+ Long id = SessionContextHolder.getId();
|
|
|
+ return id == null ? group : this.setnx(this.key(id), scene, group);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Caps> set(@NonNull Map<String, Caps> groups) {
|
|
|
- String key = this.key();
|
|
|
- if (StringUtils.isEmpty(key) || ObjectUtils.isEmpty(groups)) {
|
|
|
+ Long id = SessionContextHolder.getId();
|
|
|
+ if (id == null || ObjectUtils.isEmpty(groups)) {
|
|
|
return groups;
|
|
|
- } else if (groups.size() == 1) {
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = this.key(id);
|
|
|
+ if (groups.size() == 1) {
|
|
|
Map.Entry<String, Caps> entry = groups.entrySet().iterator().next();
|
|
|
String scene = entry.getKey();
|
|
|
Caps group = this.setnx(key, scene, entry.getValue());
|