use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheMapGetUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
String field = msg.getArgMap().get("field").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
String element = Redis.call(cacheConfigBean, (jedis) -> jedis.hget(key, field));
if (element != null && element.equals("nil"))
element = null;
return UnitResponse.success(element);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheKeysUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String pattern = msg.getArgMap().get("pattern").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Set<String> keys = Redis.call(cacheConfigBean, jedis -> jedis.keys(pattern));
return UnitResponse.success(keys);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheScanUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String pattern = msg.getArgMap().get("pattern").toString();
int count = msg.get("count", Integer.class, THRESHOLD_VALUE);
String cursor = msg.getArgMap().get("cursor").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
JSONObject jsonObject = Redis.call(cacheConfigBean, jedis -> {
JSONObject _jsonObject = new JSONObject();
ScanParams params = new ScanParams().match(pattern).count(count);
ScanResult<String> scans = jedis.scan(cursor, params);
// 如果服务器向客户端返回 0 的游标时则表示迭代结束
_jsonObject.put("cursor", scans.getStringCursor());
_jsonObject.put("result", scans.getResult());
return _jsonObject;
});
return UnitResponse.success(jsonObject);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheSetUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Object value = msg.getArgMap().get("value");
int ex = msg.get("ex", int.class, -1);
long px = msg.get("px", int.class, -2);
String nxXx = msg.get("nxXx", String.class, null);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
String result;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (px > -2)
result = ObjectCacheOperate.set(jedis, key, value, "PX", px, nxXx);
else
result = ObjectCacheOperate.set(jedis, key, value, "EX", ex, nxXx);
} catch (Exception e) {
return UnitResponse.exception(e);
}
if ("OK".equals(result))
return UnitResponse.success();
else
return UnitResponse.failure(result, result);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheTTLUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
long ttl = Redis.call(cacheConfigBean, jedis -> jedis.ttl(key));
return UnitResponse.success(ttl);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
Aggregations