public RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) { List<Object> args = new ArrayList<Object>(keys.size() + 1); args.add(getName()); encodeMapKeys(args, keys); RFuture<Map<K, V>> future = commandExecutor.readAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("HMGET", new MapGetAllDecoder(new ArrayList<Object>(keys), 0), ValueType.MAP_VALUE), args.toArray()); return future; }
@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 RFuture<Map<V, String>> hashAsync(V... members) { List<Object> params = new ArrayList<Object>(members.length + 1); params.add(getName()); for (Object member : members) { params.add(encode(member)); } RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder((List<Object>)Arrays.asList(members), 0)); return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, command, params.toArray()); }
@Override public RFuture<Map<V, String>> hashAsync(V... members) { List<Object> params = new ArrayList<Object>(members.length + 1); params.add(getName()); for (Object member : members) { params.add(encode(member)); } RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder((List<Object>)Arrays.asList(members), 0)); return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, command, params.toArray()); }
public <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) { return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor), "local items = redis.call('lrange', KEYS[1], tonumber(ARGV[2]), tonumber(ARGV[3])) " + "for i=1,#items do " + "if items[i] == ARGV[1] then " + "return tonumber(ARGV[2]) + i - 1; " + "end; " + "end; " + "return -1; ", Collections.<Object>singletonList(getName()), encode(o), fromIndex, toIndex.get()-1); }
public <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) { return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor), "local items = redis.call('lrange', KEYS[1], tonumber(ARGV[2]), tonumber(ARGV[3])) " + "for i=1,#items do " + "if items[i] == ARGV[1] then " + "return tonumber(ARGV[2]) + i - 1; " + "end; " + "end; " + "return -1; ", Collections.<Object>singletonList(getName()), encode(o), fromIndex, toIndex.get()-1); }
protected RFuture<V> addAndGetOperationAsync(K key, Number value) { ByteBuf keyState = encodeMapKey(key); RFuture<V> future = commandExecutor.writeAsync(getName(key), StringCodec.INSTANCE, new RedisCommand<Object>("HINCRBYFLOAT", new NumberConvertor(value.getClass())), getName(key), keyState, new BigDecimal(value.toString()).toPlainString()); return future; }
protected RFuture<V> addAndGetOperationAsync(K key, Number value) { ByteBuf keyState = encodeMapKey(key); RFuture<V> future = commandExecutor.writeAsync(getName(key), StringCodec.INSTANCE, new RedisCommand<Object>("HINCRBYFLOAT", new NumberConvertor(value.getClass())), getName(key), keyState, new BigDecimal(value.toString()).toPlainString()); return future; }
@Override public <V> RFuture<Map<String, V>> getAsync(String... keys) { if (keys.length == 0) { Map<String, V> emptyMap = Collections.emptyMap(); return RedissonPromise.<Map<String, V>>newSucceededFuture(emptyMap); } RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0)); return commandExecutor.readAsync(keys[0], new CompositeCodec(StringCodec.INSTANCE, codec, codec), command, keys); }
@Override public RFuture<Integer> drainToAsync(Collection<? super V> c) { if (c == null) { throw new NullPointerException(); } return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder(c)), "local vals = redis.call('lrange', KEYS[1], 0, -1); " + "redis.call('del', KEYS[1]); " + "return vals", Collections.<Object>singletonList(getName())); }
public RFuture<Integer> drainToAsync(Collection<? super V> c, int maxElements) { if (c == null) { throw new NullPointerException(); } return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder(c)), "local elemNum = math.min(ARGV[1], redis.call('llen', KEYS[1])) - 1;" + "local vals = redis.call('lrange', KEYS[1], 0, elemNum); " + "redis.call('ltrim', KEYS[1], elemNum + 1, -1); " + "return vals", Collections.<Object>singletonList(getName()), maxElements); }
@Override public RFuture<Integer> drainToAsync(Collection<? super V> c) { if (c == null) { throw new NullPointerException(); } return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder(c)), "local vals = redis.call('lrange', KEYS[1], 0, -1); " + "redis.call('del', KEYS[1]); " + "return vals", Collections.<Object>singletonList(getName())); }
@Override public <V> RFuture<Map<String, V>> getAsync(String... keys) { if (keys.length == 0) { Map<String, V> emptyMap = Collections.emptyMap(); return RedissonPromise.<Map<String, V>>newSucceededFuture(emptyMap); } RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0)); return commandExecutor.readAsync(keys[0], new CompositeCodec(StringCodec.INSTANCE, codec, codec), command, keys); }
public RFuture<Integer> drainToAsync(Collection<? super V> c, int maxElements) { if (c == null) { throw new NullPointerException(); } return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder(c)), "local elemNum = math.min(ARGV[1], redis.call('llen', KEYS[1])) - 1;" + "local vals = redis.call('lrange', KEYS[1], 0, elemNum); " + "redis.call('ltrim', KEYS[1], elemNum + 1, -1); " + "return vals", Collections.<Object>singletonList(getName()), maxElements); }
private void readConfig() { RFuture<Map<String, String>> future = commandExecutor.readAsync(configName, StringCodec.INSTANCE, new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), configName); Map<String, String> config = commandExecutor.get(future); readConfig(config); }
private void readConfig() { RFuture<Map<String, String>> future = commandExecutor.readAsync(configName, StringCodec.INSTANCE, new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), configName); Map<String, String> config = commandExecutor.get(future); readConfig(config); }
@Override public long count() { CommandBatchService executorService = new CommandBatchService(commandExecutor.getConnectionManager()); RFuture<Map<String, String>> configFuture = executorService.readAsync(configName, StringCodec.INSTANCE, new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), configName); RBitSetAsync bs = createBitSet(executorService); RFuture<Long> cardinalityFuture = bs.cardinalityAsync(); executorService.execute(); readConfig(configFuture.getNow()); return Math.round(-size / ((double) hashIterations) * Math.log(1 - cardinalityFuture.getNow() / ((double) size))); }
@Override public long count() { CommandBatchService executorService = new CommandBatchService(commandExecutor.getConnectionManager()); RFuture<Map<String, String>> configFuture = executorService.readAsync(configName, StringCodec.INSTANCE, new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder()), configName); RBitSetAsync bs = createBitSet(executorService); RFuture<Long> cardinalityFuture = bs.cardinalityAsync(); executorService.execute(); readConfig(configFuture.getNow()); return Math.round(-size / ((double) hashIterations) * Math.log(1 - cardinalityFuture.getNow() / ((double) size))); }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }