com.yomahub.liteflow.parser.redis.mode.RClient Maven / Gradle / Ivy
package com.yomahub.liteflow.parser.redis.mode;
import cn.hutool.core.collection.CollectionUtil;
import org.redisson.api.RMap;
import org.redisson.api.RMapCache;
import org.redisson.api.RScript;
import org.redisson.api.RedissonClient;
import org.redisson.api.map.event.MapEntryListener;
import org.redisson.client.codec.StringCodec;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Redisson 客户端封装类.
*
* @author hxinyu
* @since 2.11.0
*/
public class RClient {
private final RedissonClient redissonClient;
private Map map = new HashMap<>();
public RClient(RedissonClient redissonClient) {
this.redissonClient = redissonClient;
}
/**
* get hashmap of the key
*
* @param key hash name
* @return hashmap
*/
public Map getMap(String key) {
RMapCache mapCache = redissonClient.getMapCache(key);
Set mapFieldSet = mapCache.keySet();
if (CollectionUtil.isEmpty(mapFieldSet)) {
return map;
}
for (String field : mapFieldSet) {
String value = mapCache.get(field);
map.put(field, value);
}
return map;
}
/**
* add listener of the key
*
* @param key hash name
* @param listener listener
* @return listener id
*/
public int addListener(String key, MapEntryListener listener) {
RMapCache