Search in sources :

Example 16 with CacheConfigBean

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);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 17 with CacheConfigBean

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);
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 18 with CacheConfigBean

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);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 19 with CacheConfigBean

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);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 20 with CacheConfigBean

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);
}
Also used : Jedis(redis.clients.jedis.Jedis) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Aggregations

CacheConfigBean (info.xiancloud.core.support.cache.CacheConfigBean)46 Jedis (redis.clients.jedis.Jedis)15 Redis (info.xiancloud.cache.redis.Redis)4 CacheGroup (info.xiancloud.cache.service.CacheGroup)4 Group (info.xiancloud.core.Group)4 Input (info.xiancloud.core.Input)4 Unit (info.xiancloud.core.Unit)4 UnitMeta (info.xiancloud.core.UnitMeta)4 UnitRequest (info.xiancloud.core.message.UnitRequest)4 UnitResponse (info.xiancloud.core.message.UnitResponse)4 Set (java.util.Set)3 JSONObject (com.alibaba.fastjson.JSONObject)2 List (java.util.List)2 Map (java.util.Map)2 FormatUtil (info.xiancloud.cache.redis.util.FormatUtil)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Pipeline (redis.clients.jedis.Pipeline)1 ScanParams (redis.clients.jedis.ScanParams)1