初始化hash缓存-put
parent
bee6f5678c
commit
acc59fd99b
|
@ -4,10 +4,7 @@ import com.muyu.common.cache.HashCache;
|
||||||
import com.muyu.common.redis.service.RedisService;
|
import com.muyu.common.redis.service.RedisService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,10 +46,7 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<HK, HV> get (K key) {
|
public Map<HK, HV> get (K key) {
|
||||||
Map<String, HV> dataMap = redisService.getCacheMap(encode(key));
|
return decodeMap(redisService.getCacheMap(encode(key)));
|
||||||
Map<HK, HV> resultMap = new HashMap<>();
|
|
||||||
dataMap.forEach((hashKey, hashValue) -> resultMap.put(decodeHashKey(hashKey), hashValue));
|
|
||||||
return resultMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +85,8 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<HV> getToList (K key) {
|
public List<HV> getToList (K key) {
|
||||||
return null;
|
Map<HK, HV> hkhvMap = get(key);
|
||||||
|
return hkhvMap.values().stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +97,7 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void put (K key, Map<HK, HV> map) {
|
public void put (K key, Map<HK, HV> map) {
|
||||||
|
redisService.setCacheMap(encode(key), encodeMap(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,4 +144,26 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
public void remove (K key, HK hashKey) {
|
public void remove (K key, HK hashKey) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原始数据转编码数据
|
||||||
|
* @param dataMap 原始数据
|
||||||
|
* @return 编码数据
|
||||||
|
*/
|
||||||
|
private Map<String, HV> encodeMap(Map<HK, HV> dataMap){
|
||||||
|
Map<String, HV> encodeDataMap = new HashMap<>();
|
||||||
|
dataMap.forEach((hashKey, HashValue) -> encodeDataMap.put(encodeHashKey(hashKey), HashValue));
|
||||||
|
return encodeDataMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码数据转原始数据
|
||||||
|
* @param encodeDataMap 编码数据
|
||||||
|
* @return 原始数据
|
||||||
|
*/
|
||||||
|
private Map<HK, HV> decodeMap(Map<String, HV> encodeDataMap){
|
||||||
|
Map<HK, HV> dataMap = new HashMap<>();
|
||||||
|
encodeDataMap.forEach((hashKey, hashValue) -> dataMap.put(decodeHashKey(hashKey), hashValue));
|
||||||
|
return dataMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue