Search in sources :

Example 31 with CacheConfigBean

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

Example 32 with CacheConfigBean

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

Example 33 with CacheConfigBean

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

Example 34 with CacheConfigBean

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

Example 35 with CacheConfigBean

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);
    }
}
Also used : 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