use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListLengthUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long length = 0L;
try {
length = Redis.call(cacheConfigBean, (jedis) -> jedis.llen(key));
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(length);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListRangeUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
long startIndex = Long.parseLong(msg.getArgMap().get("startIndex").toString());
Long endIndex = msg.getArgMap().get("endIndex") != null ? Long.parseLong(msg.getArgMap().get("endIndex").toString()) : (startIndex + 100);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
List<String> result = null;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
result = ListCacheOperate.range(jedis, key, startIndex, endIndex);
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(result);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListRemoveUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Object valueObj = msg.getArgMap().get("valueObj");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long length = 0;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
length = ListCacheOperate.remove(jedis, key, valueObj);
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(length);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheMapBatchRemovesUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
Map<String, List<String>> batchRemoves = (Map<String, List<String>>) msg.getArgMap().get("batchRemoves");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
if (batchRemoves != null && !batchRemoves.isEmpty()) {
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
for (Map.Entry<String, List<String>> entry : batchRemoves.entrySet()) {
if (entry.getValue() != null && !entry.getValue().isEmpty()) {
String[] fields = entry.getValue().toArray(new String[] {});
MapCacheOperate.remove(jedis, entry.getKey(), fields);
}
}
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
return UnitResponse.success();
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheMapExistsUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
boolean exists = false;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (msg.getArgMap().containsKey("field")) {
String field = msg.getArgMap().get("field").toString();
exists = MapCacheOperate.exists(jedis, key, field);
} else {
exists = ObjectCacheOperate.exists(jedis, key);
}
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(exists);
}
Aggregations