Search in sources :

Example 1 with CacheConfigBean

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

the class CacheSetRemovesUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.get("key", String.class);
    Object member = msg.get("member", Object.class);
    Set members = (Set) msg.getArgMap().get("members");
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    long result = 0L;
    try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
        if (members != null && !members.isEmpty()) {
            String[] _members = new String[members.size()];
            Iterator<Object> iterator = members.iterator();
            int i = 0;
            while (iterator.hasNext()) {
                _members[i] = FormatUtil.formatValue(iterator.next());
                i++;
            }
            result = jedis.srem(key, _members);
        } else if (member != null && !"".equals(member)) {
            result = jedis.srem(key, FormatUtil.formatValue(member));
        }
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(result);
}
Also used : Jedis(redis.clients.jedis.Jedis) Set(java.util.Set) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 2 with CacheConfigBean

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

the class CacheSetSisMemberUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.get("key", String.class);
    Object member = msg.get("member", Object.class);
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    try {
        Boolean result = Redis.call(cacheConfigBean, jedis -> jedis.sismember(key, FormatUtil.formatValue(member)));
        return UnitResponse.success(result);
    } catch (Throwable e) {
        return UnitResponse.exception(e);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 3 with CacheConfigBean

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

the class CacheSortedSetAddUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.get("key", String.class);
    Long score = (Long) msg.getArgMap().get("score");
    Object member = msg.getArgMap().get("member");
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    try {
        Long result = Redis.call(cacheConfigBean, jedis -> jedis.zadd(key, score, FormatUtil.formatValue(member)));
        return UnitResponse.success(result);
    } catch (Throwable e) {
        return UnitResponse.exception(e);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 4 with CacheConfigBean

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

the class CacheSortedSetMembersUnit 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> members = Redis.call(cacheConfigBean, jedis -> jedis.zrange(key, 0, -1));
        return UnitResponse.success(members);
    } catch (Throwable e) {
        return UnitResponse.exception(e);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 5 with CacheConfigBean

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

the class JedisTestConnectUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    int number = msg.get("number", int.class, 1000);
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    final CountDownLatch startCountDownLatch = new CountDownLatch(1);
    final CountDownLatch finishCountDownLatch = new CountDownLatch(number);
    for (int i = 0; i < number; i++) {
        ThreadPoolManager.execute(() -> {
            try {
                startCountDownLatch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
                for (int j = 0; j < 90; j++) {
                    ObjectCacheOperate.incr(jedis, "CONNECT");
                    Thread.sleep(1 * 1000);
                }
            } catch (Exception e) {
                LOG.error(e);
            }
            finishCountDownLatch.countDown();
        });
    }
    try {
        startCountDownLatch.countDown();
        finishCountDownLatch.await();
        try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
            String connect = ObjectCacheOperate.get(jedis, "CONNECT");
            LOG.info(String.format("CONNECT: %s", connect));
        } catch (Exception e) {
            LOG.error(e);
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    SyncXian.call("diyMonitor", "jedisLockMonitor", new JSONObject());
    return UnitResponse.success();
}
Also used : Jedis(redis.clients.jedis.Jedis) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean) JSONObject(com.alibaba.fastjson.JSONObject) CountDownLatch(java.util.concurrent.CountDownLatch)

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