Search in sources :

Example 6 with CacheConfigBean

use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.

the class CacheListLengthUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.getArgMap().get("key").toString();
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    long length = 0L;
    try {
        length = Redis.call(cacheConfigBean, (jedis) -> jedis.llen(key));
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(length);
}
Also used : Group(info.xiancloud.core.Group) Unit(info.xiancloud.core.Unit) Input(info.xiancloud.core.Input) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean) Redis(info.xiancloud.cache.redis.Redis) UnitRequest(info.xiancloud.core.message.UnitRequest) CacheGroup(info.xiancloud.cache.service.CacheGroup) UnitResponse(info.xiancloud.core.message.UnitResponse) UnitMeta(info.xiancloud.core.UnitMeta) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 7 with CacheConfigBean

use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.

the class CacheListRangeUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.getArgMap().get("key").toString();
    long startIndex = Long.parseLong(msg.getArgMap().get("startIndex").toString());
    Long endIndex = msg.getArgMap().get("endIndex") != null ? Long.parseLong(msg.getArgMap().get("endIndex").toString()) : (startIndex + 100);
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    List<String> result = null;
    try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
        result = ListCacheOperate.range(jedis, key, startIndex, endIndex);
    } 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 8 with CacheConfigBean

use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.

the class CacheListRemoveUnit 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);
    long length = 0;
    try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
        length = ListCacheOperate.remove(jedis, key, valueObj);
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(length);
}
Also used : Jedis(redis.clients.jedis.Jedis) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 9 with CacheConfigBean

use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.

the class CacheMapBatchRemovesUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    Map<String, List<String>> batchRemoves = (Map<String, List<String>>) msg.getArgMap().get("batchRemoves");
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    if (batchRemoves != null && !batchRemoves.isEmpty()) {
        try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
            for (Map.Entry<String, List<String>> entry : batchRemoves.entrySet()) {
                if (entry.getValue() != null && !entry.getValue().isEmpty()) {
                    String[] fields = entry.getValue().toArray(new String[] {});
                    MapCacheOperate.remove(jedis, entry.getKey(), fields);
                }
            }
        } catch (Exception e) {
            return UnitResponse.exception(e);
        }
    }
    return UnitResponse.success();
}
Also used : Jedis(redis.clients.jedis.Jedis) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean) List(java.util.List) Map(java.util.Map)

Example 10 with CacheConfigBean

use of info.xiancloud.core.support.cache.CacheConfigBean in project xian by happyyangyuan.

the class CacheMapExistsUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.getArgMap().get("key").toString();
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    boolean exists = false;
    try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
        if (msg.getArgMap().containsKey("field")) {
            String field = msg.getArgMap().get("field").toString();
            exists = MapCacheOperate.exists(jedis, key, field);
        } else {
            exists = ObjectCacheOperate.exists(jedis, key);
        }
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(exists);
}
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