use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class DistributedLockUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Object valueObj = msg.get("value", Object.class, "Distributed Lock");
int expireTimeInSecond = msg.get("expireTimeInSecond", int.class, 3);
long timeOutInSecond = msg.get("timeOutInSecond", long.class, 3L);
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
boolean isLock = DistributedReentrantLockProcess.lock(cacheConfigBean, key, valueObj, expireTimeInSecond, timeOutInSecond);
if (isLock) {
DistributedReentrantLockProcess.lockSuccess();
return UnitResponse.success();
} else {
DistributedReentrantLockProcess.lockFailure();
return UnitResponse.error(CacheGroup.CODE_TIME_OUT, null, null);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class DistributedUnLockUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
Object valueObj = msg.get("value", Object.class, "Distributed Lock");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long result = 0;
try {
result = DistributedReentrantLockProcess.unLock(cacheConfigBean, key, valueObj);
} catch (Exception e) {
DistributedReentrantLockProcess.unLockFailure();
return UnitResponse.exception(e);
}
DistributedReentrantLockProcess.unLockSuccess();
return UnitResponse.success(result);
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListAddHeadUnit 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.lpush(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 CacheListClearUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Redis.call(cacheConfigBean, (jedis) -> jedis.ltrim(key, 1, 0));
return UnitResponse.success();
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.
the class CacheListGetAllUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
List<String> result = null;
try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
result = ListCacheOperate.range(jedis, key, 0, -1);
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(result);
}
Aggregations