初始化hash缓存-get

master
DongZeLiang 2024-03-30 11:16:04 +08:00
parent 41d4175d23
commit e1d039804c
2 changed files with 11 additions and 2 deletions

View File

@ -26,7 +26,7 @@ public interface HashCache <K, HK, HV> extends DecorationKey<K> {
* @param redisHashKey * @param redisHashKey
* @return ID * @return ID
*/ */
public K decodeHashKey(String redisHashKey); public HK decodeHashKey(String redisHashKey);
/** /**
* Keymap * Keymap

View File

@ -1,7 +1,10 @@
package com.muyu.common.cache.abs; package com.muyu.common.cache.abs;
import com.muyu.common.cache.HashCache; import com.muyu.common.cache.HashCache;
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -13,6 +16,9 @@ import java.util.function.Function;
*/ */
public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> { public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
@Autowired
private RedisService redisService;
/** /**
* *
* *
@ -42,7 +48,10 @@ 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) {
return null; Map<String, HV> dataMap = redisService.getCacheMap(encode(key));
Map<HK, HV> resultMap = new HashMap<>();
dataMap.forEach((hashKey, hashValue) -> resultMap.put(decodeHashKey(hashKey), hashValue));
return resultMap;
} }
/** /**