use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheObjectGetUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Object result = Redis.call(cacheConfigBean, jedis -> jedis.get(key));
if (result != null && result.toString().equals("nil"))
result = null;
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 CacheObjectRemoveUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
long size = Redis.call(cacheConfigBean, jedis -> jedis.del(key));
return UnitResponse.success(size);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheObjectUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
Object value = msg.getArgMap().get("value");
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (msg.getArgMap().containsKey("timeout")) {
int timeout = CacheOperateManager.correctionTimeout(msg.get("timeout", int.class));
ObjectCacheOperate.setex(jedis, key, value, timeout);
} else {
ObjectCacheOperate.set(jedis, key, value);
}
} 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 CacheTypeUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
String type = Redis.call(cacheConfigBean, jedis -> jedis.type(key));
return UnitResponse.success(type);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheSetAddUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
Set members = (Set) msg.getArgMap().get("members");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Long result = 0L;
if (members != null && !members.isEmpty()) {
result = Redis.call(cacheConfigBean, jedis -> {
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.sadd(key, _members);
});
}
return UnitResponse.success(result);
} catch (Throwable e) {
return UnitResponse.exception(e);
}
}
Aggregations