use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheSetMembersUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Set<String> values = Redis.call(cacheConfigBean, jedis -> jedis.smembers(key));
return UnitResponse.success(values);
} catch (Throwable e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListSetUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
int index = msg.get("index", int.class, 0);
Object valueObj = msg.get("valueObj");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
String replyCode = Redis.call(cacheConfigBean, (jedis) -> {
String value = FormatUtil.formatValue(valueObj);
return jedis.lset(key, index, value);
});
if ("OK".equals(replyCode))
return UnitResponse.success();
else
return UnitResponse.failure(replyCode, replyCode);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheLuaUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String scripts = msg.get("scripts", String.class);
Integer keyCount = msg.get("keyCount", Integer.class);
List<String> keys = msg.getArgMap().containsKey("keys") ? (List<String>) msg.getArgMap().get("keys") : null;
List<String> params = msg.getArgMap().containsKey("params") ? (List<String>) msg.getArgMap().get("params") : null;
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
Object response = null;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (keyCount != null && params != null) {
response = jedis.eval(scripts, keyCount, params.toArray(new String[params.size()]));
} else if (keys != null && params != null) {
response = jedis.eval(scripts, keys, params);
} else {
response = jedis.eval(scripts);
}
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(response);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheMapClearUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long result = 0L;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
result = MapCacheOperate.removeAll(jedis, key);
} 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 CacheMapGetAllUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Map<String, String> result = Redis.call(cacheConfigBean, jedis -> jedis.hgetAll(key));
return UnitResponse.success(result);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
Aggregations