use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheDecrementUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Long value = msg.get("value", Long.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long decrement = 0;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (value != null)
decrement = ObjectCacheOperate.decrBy(jedis, key, value);
else
decrement = ObjectCacheOperate.decr(jedis, key);
if (msg.getArgMap().containsKey("timeout")) {
int timeout = CacheOperateManager.correctionTimeout(msg.get("timeout", int.class));
if (timeout > -1)
ObjectCacheOperate.expire(jedis, key, timeout);
}
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(decrement);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheIncrementUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Long value = msg.get("value", Long.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long increment = 0;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (value != null)
increment = ObjectCacheOperate.incrBy(jedis, key, value);
else
increment = ObjectCacheOperate.incr(jedis, key);
if (msg.getArgMap().containsKey("timeout")) {
int timeout = CacheOperateManager.correctionTimeout(msg.get("timeout", int.class));
if (timeout > -1)
ObjectCacheOperate.expire(jedis, key, timeout);
}
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(increment);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListAddAllUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
List values = msg.get("values", List.class);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
if (values != null && !values.isEmpty()) {
String info = ServerOperate.info(jedis, "server");
String redis_mode = ServerOperate.getAttributeInInfo(info, "redis_mode");
if (redis_mode != null && "standalone".equals(redis_mode)) {
Pipeline pipeline = jedis.pipelined();
values.stream().forEach(valueObj -> {
String value = FormatUtil.formatValue(valueObj);
pipeline.rpush(key, value);
});
pipeline.sync();
} else {
values.stream().forEach(valueObj -> {
String value = FormatUtil.formatValue(valueObj);
jedis.rpush(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 CacheListAddUnit 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);
try {
long length = Redis.call(cacheConfigBean, (jedis) -> {
String value = FormatUtil.formatValue(valueObj);
return jedis.rpush(key, value);
});
return UnitResponse.success(length);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListExistsUnit 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);
}
}
Aggregations