import java.util.Iterator;
import java.util.List;
import org.redisson.api.RSortedSet;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.common.collect.Lists;
@Service
public class SpellGroupCacheHandleService {
@Autowired
private RedissonClient redissonClient;
private static final String SPELL_LIST = "_SPELL_LIST";
/**
* 初始化商品
*/
public void initSpellGroupCache(Map map) {
String listKey = map.get("INCORP_NO") + "_" + map.get("USER_ID") + "*";
redissonClient.getKeys().deleteByPattern(listKey);
}
/**
* 选中商品
*/
public void addSpellGroupCache(Map map) {
String listKey = map.get("INCORP_NO") + "_" + map.get("USER_ID") + SPELL_LIST;
String SUB_PRODUCT_ID = map.get("SUB_PRODUCT_ID").toString();
RSortedSet<String> list = redissonClient.getSortedSet(listKey);
list.add(SUB_PRODUCT_ID);
}
/**
* 删除商品
*/
public void deleteSpellGroupCache(Map map) {
String listKey = map.get("INCORP_NO") + "_" + map.get("USER_ID") + SPELL_LIST;
String SUB_PRODUCT_ID = map.get("SUB_PRODUCT_ID").toString();
if (StringUtil.isEmpty(SUB_PRODUCT_ID)) {
return;
}
RSortedSet<String> list = redissonClient.getSortedSet(listKey);
Iterator<String> it = list.iterator();
while (it.hasNext()) {
String WITH_SUB_PRODUCT_ID = it.next();
if (SUB_PRODUCT_ID.equals(WITH_SUB_PRODUCT_ID)) {
it.remove();
}
}
}
/**
* 查询商品
*/
public List<String> getSpellGroupCache(Map map) {
String listKey = map.get("INCORP_NO") + "_" + ctx.get("USER_ID") + SPELL_LIST;
RSortedSet<String> list = redissonClient.getSortedSet(listKey);
List<String> resultList = Lists.newArrayList();
resultList.addAll(list);
return resultList;
}
}
Redisson
最新推荐文章于 2024-03-31 00:49:12 发布