use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListGetByIndexUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Long index = msg.getArgMap().get("index") != null ? Long.parseLong(msg.getArgMap().get("index").toString()) : 0;
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
String element = null;
try {
element = Redis.call(cacheConfigBean, (jedis) -> jedis.lindex(key, index));
if (element != null && element.toString().equals("nil"))
element = null;
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(element);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheMapPutAllUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Map maps = msg.get("maps", Map.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (maps != null && !maps.isEmpty()) {
Map<String, String> _maps = new HashMap<>();
maps.forEach((field, valueObj) -> {
String value = FormatUtil.formatValue(valueObj);
_maps.put(field.toString(), value);
});
jedis.hmset(key, _maps);
}
return UnitResponse.success();
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheExistsUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
boolean result = Redis.call(cacheConfigBean, jedis -> jedis.exists(key));
return UnitResponse.success(result);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheSortedSetLengthUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Long length = Redis.call(cacheConfigBean, jedis -> jedis.zcard(key));
return UnitResponse.success(length);
} catch (Throwable e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheSortedSetRemoveUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
Object member = msg.get("member", Object.class);
Set members = (Set) msg.getArgMap().get("members");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Long result = Redis.call(cacheConfigBean, jedis -> {
if (members != null && !members.isEmpty()) {
String[] _members = new String[members.size()];
Iterator<Object> iterator = members.iterator();
int i = 0;
while (iterator.hasNext()) {
_members[i] = FormatUtil.formatValue(iterator.next());
i++;
}
return jedis.srem(key, _members);
} else if (member != null && !"".equals(member)) {
return jedis.srem(key, FormatUtil.formatValue(member));
} else {
return -1L;
}
});
return UnitResponse.success(result);
} catch (Throwable e) {
return UnitResponse.exception(e);
}
}
Aggregations