protected boolean await(RFuture<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException { return commandExecutor.await(future, timeout, timeoutUnit); }
@Override public <R> RFuture<R> evalShaAsync(String key, Mode mode, String shaDigest, ReturnType returnType, List<Object> keys, Object... values) { RedisCommand command = new RedisCommand(returnType.getCommand(), "EVALSHA"); if (mode == Mode.READ_ONLY) { return commandExecutor.evalReadAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray()); } return commandExecutor.evalWriteAsync(key, codec, command, shaDigest, keys, encode(Arrays.asList(values), codec).toArray()); }
@Override public <R> R eval(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys, Object... values) { return commandExecutor.get((RFuture<R>)evalAsync(key, mode, luaScript, returnType, keys, values)); }
protected ByteBuf encode(Object value) { if (commandExecutor.isRedissonReferenceSupportEnabled()) { RedissonReference reference = commandExecutor.getObjectBuilder().toReference(value); if (reference != null) { value = reference; } } try { return codec.getValueEncoder().encode(value); } catch (IOException e) { throw new IllegalArgumentException(e); } }
public RedissonLock(CommandAsyncExecutor commandExecutor, String name) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.id = commandExecutor.getConnectionManager().getId(); this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(); this.entryName = id + ":" + name; }
public RFuture<MapScanResult<Object, Object>> scanIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count) { if (pattern == null) { RFuture<MapScanResult<Object, Object>> f = commandExecutor.readAsync(client, name, codec, RedisCommands.HSCAN, name, startPos, "COUNT", count); return f; } RFuture<MapScanResult<Object, Object>> f = commandExecutor.readAsync(client, name, codec, RedisCommands.HSCAN, name, startPos, "MATCH", pattern, "COUNT", count); return f; }
@Override public RFuture<V> pollLastFromAnyAsync(long timeout, TimeUnit unit, String ... queueNames) { return commandExecutor.pollFromAnyAsync(getName(), codec, RedisCommands.BRPOP_VALUE, toSeconds(timeout, unit), queueNames); }
protected <T> RFuture<T> fastRemoveAsync(List<Object> mapKeys, List<Object> listKeys, RedisCommand<T> evalCommandType) { return commandExecutor.evalWriteAsync(getName(), codec, evalCommandType, "local res = redis.call('hdel', KEYS[1], unpack(ARGV)); " + "if res > 0 then " + "redis.call('del', unpack(KEYS, 2, #KEYS)); " + "end; " + "return res; ", listKeys, mapKeys.toArray()); }
@Override public RFuture<V> peekAsync() { return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_OBJECT, "local v = redis.call('lindex', KEYS[1], 0); " + "if v ~= false then " + "local randomId, value = struct.unpack('dLc0', v);" + "return value; " + "end " + "return nil;", Arrays.<Object>asList(queueName)); }
@Override public RFuture<Collection<String>> findKeysByPatternAsync(String pattern) { return commandExecutor.readAllAsync(RedisCommands.KEYS, pattern); }
@Override public <T> Collection<T> find(Class<T> entityClass, Condition condition) { NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass); Set<Object> ids = Collections.emptySet(); if (condition instanceof EQCondition) { EQCondition c = (EQCondition) condition; String indexName = namingScheme.getIndexName(entityClass, c.getName()); RSetMultimap<Object, Object> map = redisson.getSetMultimap(indexName, namingScheme.getCodec()); ids = map.getAll(c.getValue()); } else if (condition instanceof ORCondition) { ids = traverseOr((ORCondition) condition, namingScheme, entityClass); } else if (condition instanceof ANDCondition) { ids = traverseAnd((ANDCondition) condition, namingScheme, entityClass); } if (ids.isEmpty()) { return Collections.emptyList(); } List<T> result = new ArrayList<T>(ids.size()); for (Object id : ids) { T proxied = createLiveObject(entityClass, id); result.add(proxied); } return result; }
public ByteBuf encode(Object value) { if (commandExecutor.isRedissonReferenceSupportEnabled()) { RedissonReference reference = commandExecutor.getObjectBuilder().toReference(value); if (reference != null) { value = reference; } } try { return codec.getValueEncoder().encode(value); } catch (IOException e) { throw new IllegalArgumentException(e); } }
public RedissonLock(CommandAsyncExecutor commandExecutor, String name) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.id = commandExecutor.getConnectionManager().getId(); this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(); this.entryName = id + ":" + name; }
@Override public RFuture<Collection<String>> rangeHeadAsync(String toElement, boolean toInclusive) { String toValue = value(toElement, toInclusive); return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue); }
@Override public RFuture<V> pollFromAnyAsync(long timeout, TimeUnit unit, String ... queueNames) { return commandExecutor.pollFromAnyAsync(getName(), codec, RedisCommands.BLPOP_VALUE, toSeconds(timeout, unit), queueNames); }
@Override protected RFuture<Boolean> removeAsync(String requestQueueName, RequestId taskId) { return commandExecutor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, "redis.call('lrem', KEYS[1], 1, ARGV[1]); " + "redis.call('hdel', KEYS[2], ARGV[1]);" + "return 1;", Arrays.<Object>asList(requestQueueName, requestQueueName + ":tasks"), taskId.toString()); }
@Override public RFuture<List<V>> readAllAsync() { return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_LIST, "local result = {}; " + "local items = redis.call('lrange', KEYS[1], 0, -1); " + "for i, v in ipairs(items) do " + "local randomId, value = struct.unpack('dLc0', v); " + "table.insert(result, value);" + "end; " + "return result; ", Collections.<Object>singletonList(queueName)); }
@Override public RFuture<Collection<String>> findKeysByPatternAsync(String pattern) { return commandExecutor.readAllAsync(RedisCommands.KEYS, pattern); }
@Override public <T> Collection<T> find(Class<T> entityClass, Condition condition) { NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass); Set<Object> ids = Collections.emptySet(); if (condition instanceof EQCondition) { EQCondition c = (EQCondition) condition; String indexName = namingScheme.getIndexName(entityClass, c.getName()); RSetMultimap<Object, Object> map = redisson.getSetMultimap(indexName, namingScheme.getCodec()); ids = map.getAll(c.getValue()); } else if (condition instanceof ORCondition) { ids = traverseOr((ORCondition) condition, namingScheme, entityClass); } else if (condition instanceof ANDCondition) { ids = traverseAnd((ANDCondition) condition, namingScheme, entityClass); } if (ids.isEmpty()) { return Collections.emptyList(); } List<T> result = new ArrayList<T>(ids.size()); for (Object id : ids) { T proxied = createLiveObject(entityClass, id); result.add(proxied); } return result; }
protected ByteBuf encode(Object value) { if (commandExecutor.isRedissonReferenceSupportEnabled()) { RedissonReference reference = commandExecutor.getObjectBuilder().toReference(value); if (reference != null) { value = reference; } } try { return codec.getValueEncoder().encode(value); } catch (IOException e) { throw new IllegalArgumentException(e); } }