org.redisson.client.protocol.RedisCommand Java Examples
The following examples show how to use
org.redisson.client.protocol.RedisCommand.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonReactiveListCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); RedisCommand<List<Object>> redisCommand = RedisCommands.BLPOP; if (command.getDirection() == Direction.RIGHT) { redisCommand = RedisCommands.BRPOP; } List<Object> params = new ArrayList<Object>(command.getKeys().size() + 1); params.addAll(command.getKeys().stream().map(v -> toByteArray(v)).collect(Collectors.toList())); params.add(command.getTimeout().getSeconds()); Mono<List<byte[]>> m = write((byte[])params.get(0), ByteArrayCodec.INSTANCE, redisCommand, params.toArray()); return m.map(v -> new PopResponse(command, new PopResult(v.stream().map(e -> ByteBuffer.wrap(e)).collect(Collectors.toList())))); }); }
Example #2
Source File: RedissonBoundedBlockingQueue.java From redisson with Apache License 2.0 | 6 votes |
@Override public RFuture<Integer> drainToAsync(Collection<? super V> c, int maxElements) { if (c == null) { throw new NullPointerException(); } String channelName = RedissonSemaphore.getChannelName(getSemaphoreName()); return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder((Collection<Object>) 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); " + "if #vals > 0 then " + "local value = redis.call('incrby', KEYS[2], #vals); " + "redis.call('publish', KEYS[3], value); " + "end; " + "return vals", Arrays.<Object>asList(getName(), getSemaphoreName(), channelName), maxElements); }
Example #3
Source File: RedissonListMultimapValues.java From redisson with Apache License 2.0 | 6 votes |
private <R> RFuture<R> indexOfAsync(Object o, Convertor<R> convertor) { return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<R>("EVAL", convertor), "local expireDate = 92233720368547758; " + "local expireDateScore = redis.call('zscore', KEYS[1], ARGV[2]); " + "if expireDateScore ~= false then " + "expireDate = tonumber(expireDateScore); " + "end; " + "if expireDate <= tonumber(ARGV[1]) then " + "return -1;" + "end; " + "local items = redis.call('lrange', KEYS[2], 0, -1); " + "for i=1,#items do " + "if items[i] == ARGV[3] then " + "return i - 1; " + "end; " + "end; " + "return -1;", Arrays.<Object>asList(timeoutSetName, getName()), System.currentTimeMillis(), encodeMapKey(key), encodeMapValue(o)); }
Example #4
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
protected RedisCommand<?> toCommand(ReturnType returnType, String name) { RedisCommand<?> c = null; if (returnType == ReturnType.BOOLEAN) { c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand(); } else if (returnType == ReturnType.INTEGER) { c = org.redisson.api.RScript.ReturnType.INTEGER.getCommand(); } else if (returnType == ReturnType.MULTI) { c = org.redisson.api.RScript.ReturnType.MULTI.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } else if (returnType == ReturnType.STATUS) { c = org.redisson.api.RScript.ReturnType.STATUS.getCommand(); } else if (returnType == ReturnType.VALUE) { c = org.redisson.api.RScript.ReturnType.VALUE.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } return new RedisCommand(c, name); }
Example #5
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
protected RedisCommand<?> toCommand(ReturnType returnType, String name) { RedisCommand<?> c = null; if (returnType == ReturnType.BOOLEAN) { c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand(); } else if (returnType == ReturnType.INTEGER) { c = org.redisson.api.RScript.ReturnType.INTEGER.getCommand(); } else if (returnType == ReturnType.MULTI) { c = org.redisson.api.RScript.ReturnType.MULTI.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } else if (returnType == ReturnType.STATUS) { c = org.redisson.api.RScript.ReturnType.STATUS.getCommand(); } else if (returnType == ReturnType.VALUE) { c = org.redisson.api.RScript.ReturnType.VALUE.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } return new RedisCommand(c, name); }
Example #6
Source File: CommandAsyncServiceMethodInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private boolean validate(final Object target, final Object[] args) { if (args == null || args.length < 4) { if (isDebug) { logger.debug("Invalid arguments. Null or not found args({}).", args); } return false; } // args[1] is org.redisson.connection.NodeSource if (!(args[1] instanceof NodeSource)) { if (isDebug) { logger.debug("Invalid arguments. Expect NodeSourceGetter but args[0]({}).", args[0]); } return false; } // args[3] is org.redisson.client.protocol.RedisCommand if (!(args[3] instanceof RedisCommand)) { if (isDebug) { logger.debug("Invalid arguments. Expect RedisCommand but args[3]({}).", args[0]); } return false; } return true; }
Example #7
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { if (isQueueing()) { throw new UnsupportedOperationException(); } if (isPipelined()) { throw new UnsupportedOperationException(); } RedisCommand<?> c = toCommand(returnType, "EVALSHA"); List<Object> params = new ArrayList<Object>(); params.add(scriptSha); params.add(numKeys); params.addAll(Arrays.asList(keysAndArgs)); return write(null, ByteArrayCodec.INSTANCE, c, params.toArray()); }
Example #8
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { if (isQueueing()) { throw new UnsupportedOperationException(); } if (isPipelined()) { throw new UnsupportedOperationException(); } RedisCommand<?> c = toCommand(returnType, "EVAL"); List<Object> params = new ArrayList<Object>(); params.add(script); params.add(numKeys); params.addAll(Arrays.asList(keysAndArgs)); return write(null, StringCodec.INSTANCE, c, params.toArray()); }
Example #9
Source File: RedissonReactiveNumberCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T extends Number> Flux<NumericResponse<HIncrByCommand<T>, T>> hIncrBy( Publisher<HIncrByCommand<T>> commands) { return execute(commands, key -> { Assert.notNull(key.getKey(), "Key must not be null!"); Assert.notNull(key.getValue(), "Value must not be null!"); byte[] keyBuf = toByteArray(key.getKey()); byte[] fieldBuf = toByteArray(key.getField()); Mono<T> m = write(keyBuf, StringCodec.INSTANCE, new RedisCommand<Object>("HINCRBYFLOAT", new NumberConvertor(key.getValue().getClass())), keyBuf, fieldBuf, new BigDecimal(key.getValue().toString()).toPlainString()); return m.map(v -> new NumericResponse<>(key, v)); }); }
Example #10
Source File: RedissonReactiveZSetCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<NumericResponse<ZRankCommand, Long>> zRank(Publisher<ZRankCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getValue(), "Member must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); byte[] valueBuf = toByteArray(command.getValue()); RedisCommand<Long> cmd = RedisCommands.ZRANK; if (command.getDirection() == Direction.DESC) { cmd = RedisCommands.ZREVRANK; } Mono<Long> m = read(keyBuf, DoubleCodec.INSTANCE, cmd, keyBuf, valueBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #11
Source File: RedissonReactiveZSetCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<NumericResponse<ZRankCommand, Long>> zRank(Publisher<ZRankCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getValue(), "Member must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); byte[] valueBuf = toByteArray(command.getValue()); RedisCommand<Long> cmd = RedisCommands.ZRANK; if (command.getDirection() == Direction.DESC) { cmd = RedisCommands.ZREVRANK; } Mono<Long> m = read(keyBuf, DoubleCodec.INSTANCE, cmd, keyBuf, valueBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #12
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { if (isQueueing()) { throw new UnsupportedOperationException(); } if (isPipelined()) { throw new UnsupportedOperationException(); } RedisCommand<?> c = toCommand(returnType, "EVAL"); List<Object> params = new ArrayList<Object>(); params.add(script); params.add(numKeys); params.addAll(Arrays.asList(keysAndArgs)); return write(null, StringCodec.INSTANCE, c, params.toArray()); }
Example #13
Source File: RedissonReactiveGeoCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<MultiValueResponse<GeoPosCommand, Point>> geoPos(Publisher<GeoPosCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getMembers(), "Members must not be null!"); RedisCommand<Map<Object, Object>> cmd = new RedisCommand<Map<Object, Object>>("GEOPOS", geoDecoder); byte[] keyBuf = toByteArray(command.getKey()); List<Object> args = new ArrayList<Object>(command.getMembers().size() + 1); args.add(keyBuf); args.addAll(command.getMembers().stream().map(buf -> toByteArray(buf)).collect(Collectors.toList())); Mono<List<Point>> m = read(keyBuf, StringCodec.INSTANCE, cmd, args.toArray()); return m.map(v -> new MultiValueResponse<>(command, v)); }); }
Example #14
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { if (isQueueing()) { throw new UnsupportedOperationException(); } if (isPipelined()) { throw new UnsupportedOperationException(); } RedisCommand<?> c = toCommand(returnType, "EVALSHA"); List<Object> params = new ArrayList<Object>(); params.add(scriptSha); params.add(numKeys); params.addAll(Arrays.asList(keysAndArgs)); return write(null, ByteArrayCodec.INSTANCE, c, params.toArray()); }
Example #15
Source File: RedissonReactiveListCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); RedisCommand<List<Object>> redisCommand = RedisCommands.BLPOP; if (command.getDirection() == Direction.RIGHT) { redisCommand = RedisCommands.BRPOP; } List<Object> params = new ArrayList<Object>(command.getKeys().size() + 1); params.addAll(command.getKeys().stream().map(v -> toByteArray(v)).collect(Collectors.toList())); params.add(command.getTimeout().getSeconds()); Mono<List<byte[]>> m = write((byte[])params.get(0), ByteArrayCodec.INSTANCE, redisCommand, params.toArray()); return m.map(v -> new PopResponse(command, new PopResult(v.stream().map(e -> ByteBuffer.wrap(e)).collect(Collectors.toList())))); }); }
Example #16
Source File: CommandAsyncService.java From redisson with Apache License 2.0 | 6 votes |
private <R, T> void retryReadRandomAsync(Codec codec, RedisCommand<T> command, RPromise<R> mainPromise, List<MasterSlaveEntry> nodes, Object... params) { RPromise<R> attemptPromise = new RedissonPromise<R>(); attemptPromise.onComplete((res, e) -> { if (e == null) { if (res == null) { if (nodes.isEmpty()) { mainPromise.trySuccess(null); } else { retryReadRandomAsync(codec, command, mainPromise, nodes, params); } } else { mainPromise.trySuccess(res); } } else { mainPromise.tryFailure(e); } }); MasterSlaveEntry entry = nodes.remove(0); async(true, new NodeSource(entry), codec, command, params, attemptPromise, false); }
Example #17
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
protected RedisCommand<?> toCommand(ReturnType returnType, String name) { RedisCommand<?> c = null; if (returnType == ReturnType.BOOLEAN) { c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand(); } else if (returnType == ReturnType.INTEGER) { c = org.redisson.api.RScript.ReturnType.INTEGER.getCommand(); } else if (returnType == ReturnType.MULTI) { c = org.redisson.api.RScript.ReturnType.MULTI.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } else if (returnType == ReturnType.STATUS) { c = org.redisson.api.RScript.ReturnType.STATUS.getCommand(); } else if (returnType == ReturnType.VALUE) { c = org.redisson.api.RScript.ReturnType.VALUE.getCommand(); return new RedisCommand(c, name, new BinaryConvertor()); } return new RedisCommand(c, name); }
Example #18
Source File: RedissonReactiveNumberCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public <T extends Number> Flux<NumericResponse<HIncrByCommand<T>, T>> hIncrBy( Publisher<HIncrByCommand<T>> commands) { return execute(commands, key -> { Assert.notNull(key.getKey(), "Key must not be null!"); Assert.notNull(key.getValue(), "Value must not be null!"); byte[] keyBuf = toByteArray(key.getKey()); byte[] fieldBuf = toByteArray(key.getField()); Mono<T> m = write(keyBuf, StringCodec.INSTANCE, new RedisCommand<Object>("HINCRBYFLOAT", new NumberConvertor(key.getValue().getClass())), keyBuf, fieldBuf, new BigDecimal(key.getValue().toString()).toPlainString()); return m.map(v -> new NumericResponse<>(key, v)); }); }
Example #19
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder2(new GeoResultsDecoder(within.getRadius().getMetric()), new GeoDistanceDecoder()); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
Example #20
Source File: RedissonBloomFilter.java From redisson with Apache License 2.0 | 5 votes |
@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))); }
Example #21
Source File: SentinelRedisNode.java From redisson with Apache License 2.0 | 5 votes |
private <T> RFuture<T> executeAsync(T defaultValue, Codec codec, long timeout, RedisCommand<T> command, Object... params) { RPromise<T> result = new RedissonPromise<>(); RFuture<RedisConnection> connectionFuture = client.connectAsync(); connectionFuture.onComplete((connection, ex) -> { if (ex != null) { if (defaultValue != null) { result.trySuccess(defaultValue); } else { result.tryFailure(ex); } return; } RFuture<T> future = connection.async(timeout, codec, command, params); future.onComplete((r, e) -> { connection.closeAsync(); if (e != null) { if (defaultValue != null) { result.trySuccess(defaultValue); } else { result.tryFailure(e); } return; } result.trySuccess(r); }); }); return result; }
Example #22
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@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()); }
Example #23
Source File: RedissonReactiveNumberCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public <T extends Number> Flux<NumericResponse<IncrByCommand<T>, T>> incrBy(Publisher<IncrByCommand<T>> commands) { return execute(commands, key -> { Assert.notNull(key.getKey(), "Key must not be null!"); Assert.notNull(key.getValue(), "Value must not be null!"); byte[] keyBuf = toByteArray(key.getKey()); Mono<T> m = write(keyBuf, StringCodec.INSTANCE, new RedisCommand<Object>("INCRBYFLOAT", new NumberConvertor(key.getValue().getClass())), keyBuf, new BigDecimal(key.getValue().toString()).toPlainString()); return m.map(v -> new NumericResponse<>(key, v)); }); }
Example #24
Source File: RedissonScript.java From redisson with Apache License 2.0 | 5 votes |
@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()); }
Example #25
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public List<Point> geoPos(byte[] key, byte[]... members) { List<Object> params = new ArrayList<Object>(members.length + 1); params.add(key); params.addAll(Arrays.asList(members)); RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOPOS", geoDecoder); return read(key, StringCodec.INSTANCE, command, params.toArray()); }
Example #26
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
protected void indexCommand(RedisCommand<?> command) { if (isQueueing() || isPipelined()) { index++; if (commandsToRemove.contains(command.getName())) { indexToRemove.add(index); } } }
Example #27
Source File: RedissonReactiveNumberCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public <T extends Number> Flux<NumericResponse<IncrByCommand<T>, T>> incrBy(Publisher<IncrByCommand<T>> commands) { return execute(commands, key -> { Assert.notNull(key.getKey(), "Key must not be null!"); Assert.notNull(key.getValue(), "Value must not be null!"); byte[] keyBuf = toByteArray(key.getKey()); Mono<T> m = write(keyBuf, StringCodec.INSTANCE, new RedisCommand<Object>("INCRBYFLOAT", new NumberConvertor(key.getValue().getClass())), keyBuf, new BigDecimal(key.getValue().toString()).toPlainString()); return m.map(v -> new NumericResponse<>(key, v)); }); }
Example #28
Source File: CommandAsyncService.java From redisson with Apache License 2.0 | 5 votes |
@Override public <T, R> RFuture<Collection<R>> readAllAsync(Collection<R> results, Codec codec, RedisCommand<T> command, Object... params) { RPromise<Collection<R>> mainPromise = createPromise(); Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet(); AtomicInteger counter = new AtomicInteger(nodes.size()); BiConsumer<Object, Throwable> listener = new BiConsumer<Object, Throwable>() { @Override public void accept(Object result, Throwable u) { if (u != null && !(u instanceof RedisRedirectException)) { mainPromise.tryFailure(u); return; } if (result instanceof Collection) { synchronized (results) { results.addAll((Collection) result); } } else { synchronized (results) { results.add((R) result); } } if (counter.decrementAndGet() == 0 && !mainPromise.isDone()) { mainPromise.trySuccess(results); } } }; for (MasterSlaveEntry entry : nodes) { RPromise<R> promise = new RedissonPromise<R>(); promise.onComplete(listener); async(true, new NodeSource(entry), codec, command, params, promise, true); } return mainPromise; }
Example #29
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public List<Point> geoPos(byte[] key, byte[]... members) { List<Object> params = new ArrayList<Object>(members.length + 1); params.add(key); params.addAll(Arrays.asList(members)); MultiDecoder<Map<Object, Object>> decoder = new ListMultiDecoder2(new ObjectListReplayDecoder2(), new PointDecoder()); RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOPOS", decoder); return read(key, StringCodec.INSTANCE, command, params.toArray()); }
Example #30
Source File: RedissonBlockingQueue.java From redisson with Apache License 2.0 | 5 votes |
@Override 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); }