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);
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations