初始化hash缓存

master
DongZeLiang 2024-03-29 19:41:55 +08:00
parent 39b92736fa
commit c76dfb1228
9 changed files with 180 additions and 25 deletions

View File

@ -1,32 +1,13 @@
package com.muyu.common.cache;
import com.muyu.common.cache.decoration.DecorationKey;
/**
* @author DongZl
* @description:
* @Date 2024-3-26 03:25
*/
public interface Cache <K, V> {
/**
* key
* @return key
*/
public String keyPre();
/**
*
* @param key ID
* @return
*/
public String encode(K key);
/**
*
* @param redisKey
* @return ID
*/
public K decode(String redisKey);
public interface Cache <K, V> extends DecorationKey<K> {
/**
* Keyvalue

View File

@ -0,0 +1,97 @@
package com.muyu.common.cache;
import com.muyu.common.cache.decoration.DecorationKey;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* @author DongZl
* @description: Hash
* @Date 2024-3-29 03:16
*/
public interface HashCache <K, HK, HV> extends DecorationKey<K> {
/**
*
* @param hashKey ID
* @return
*/
public String encodeHashKey(HK hashKey);
/**
*
* @param redisHashKey
* @return ID
*/
public K decodeHashKey(String redisHashKey);
/**
* Keymap
* @param key
* @return Map
*/
public Map<HK, HV> get(K key);
/**
* hashKeyhashValue
* @param key
* @param hashKey hash
* @return hash
*/
public HV get(K key, HK hashKey);
/**
* hashKeyhashValue
* @param key
* @param hashKeyList hash
* @return hash
*/
public HV get(K key, HK... hashKeyList);
/**
* hash
* @param key
* @return hash
*/
public List<HV> getToList(K key);
/**
*
* @param key redis
* @param map hashMap
*/
public void put(K key, Map<HK, HV> map);
/**
*
* @param key redis
* @param dataList
* @param hashKey hash
*/
public void put(K key, List<HV> dataList, Function<HV, HK> hashKey);
/**
*
* @param key redis
* @param hashKey hash
* @param hashValue hash
*/
public void put(K key, HK hashKey, HV hashValue);
/**
* redis
* @param key hash
*/
public void remove(K key);
/**
* redishash
* @param key redis
* @param hashKey hash
*/
public void remove(K key, HK hashKey);
}

View File

@ -0,0 +1,11 @@
package com.muyu.common.cache.abs;
import com.muyu.common.cache.HashCache;
/**
* @author DongZl
* @description: hash
* @Date 2024-3-29 07:40
*/
public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
}

View File

@ -0,0 +1,30 @@
package com.muyu.common.cache.decoration;
/**
* @author DongZl
* @description: Key
* @Date 2024-3-29 03:19
*/
public interface DecorationKey <K>{
/**
* key
* @return key
*/
public String keyPre();
/**
*
* @param key ID
* @return
*/
public String encode(K key);
/**
*
* @param redisKey
* @return ID
*/
public K decode(String redisKey);
}

View File

@ -1,11 +1,17 @@
package com.muyu.product.cache;
import com.muyu.common.cache.HashCache;
import com.muyu.common.cache.abs.CacheAbs;
import com.muyu.common.core.text.Convert;
import com.muyu.product.cache.datasource.ProjectInfoData;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.ProjectSkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* @author DongZl
@ -15,6 +21,18 @@ import org.springframework.stereotype.Service;
@Component
public class ProjectInfoCache extends CacheAbs<Long, ProjectInfo> {
public static void main (String[] args) {
Long projectId = 10L;
HashCache<Long, Long, ProjectSkuInfo> hashCache = null;
List<ProjectSkuInfo> projectSkuInfoList = new ArrayList<>(){{
add(new ProjectSkuInfo());
add(new ProjectSkuInfo());
}};
hashCache.put(projectId, projectSkuInfoList, ProjectSkuInfo::getProjectId);
Long[] longArr = new Long[]{10L,11L,12L,13L,14L,15L};
hashCache.get(projectId, longArr);
}
@Autowired
private ProjectInfoData projectInfoData;
/**

View File

@ -0,0 +1,9 @@
package com.muyu.product.cache;
/**
* @author DongZl
* @description: sku
* @Date 2024-3-29 03:06
*/
public class ProjectSkuCache {
}

View File

@ -0,0 +1,9 @@
package com.muyu.product.cache;
/**
* @author DongZl
* @description: SKU
* @Date 2024-3-29 03:06
*/
public class ProjectSkuStockCache {
}

View File

@ -1,4 +1,4 @@
package com.muyu.product.cache;
package com.muyu.product.cache.datasource;
import com.muyu.product.domain.ProjectInfo;

View File

@ -1,6 +1,6 @@
package com.muyu.product.cache.impl;
import com.muyu.product.cache.ProjectInfoData;
import com.muyu.product.cache.datasource.ProjectInfoData;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;