org.redisson.client.codec.StringCodec Java Examples
The following examples show how to use
org.redisson.client.codec.StringCodec.
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: TasksRunnerService.java From redisson with Apache License 2.0 | 6 votes |
/** * Check shutdown state. If tasksCounter equals <code>0</code> * and executor in <code>shutdown</code> state, then set <code>terminated</code> state * and notify terminationTopicName * <p> * If <code>scheduledRequestId</code> is not null then * delete scheduled task * * @param requestId */ private void finish(String requestId, boolean removeTask) { String script = ""; if (removeTask) { script += "local scheduled = redis.call('zscore', KEYS[5], ARGV[3]);" + "if scheduled == false then " + "redis.call('hdel', KEYS[4], ARGV[3]); " + "end;"; } script += "redis.call('zrem', KEYS[5], 'ff' .. ARGV[3]);" + "if redis.call('decr', KEYS[1]) == 0 then " + "redis.call('del', KEYS[1]);" + "if redis.call('get', KEYS[2]) == ARGV[1] then " + "redis.call('del', KEYS[6]);" + "redis.call('set', KEYS[2], ARGV[2]);" + "redis.call('publish', KEYS[3], ARGV[2]);" + "end;" + "end;"; commandExecutor.evalWrite(name, StringCodec.INSTANCE, RedisCommands.EVAL_VOID, script, Arrays.<Object>asList(tasksCounterName, statusName, terminationTopicName, tasksName, schedulerQueueName, tasksRetryIntervalName), RedissonExecutorService.SHUTDOWN_STATE, RedissonExecutorService.TERMINATED_STATE, requestId); }
Example #2
Source File: RedissonScoredSortedSetReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testAddAndGet() throws InterruptedException { RScoredSortedSetReactive<Integer> set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE); sync(set.add(1, 100)); Double res = sync(set.addScore(100, 11)); Assert.assertEquals(12, (double)res, 0); Double score = sync(set.getScore(100)); Assert.assertEquals(12, (double)score, 0); RScoredSortedSetReactive<Integer> set2 = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE); sync(set2.add(100.2, 1)); Double res2 = sync(set2.addScore(1, new Double(12.1))); Assert.assertTrue(new Double(112.3).compareTo(res2) == 0); res2 = sync(set2.getScore(1)); Assert.assertTrue(new Double(112.3).compareTo(res2) == 0); }
Example #3
Source File: RedissonReactiveHyperLogLogCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<NumericResponse<PfAddCommand, Long>> pfAdd(Publisher<PfAddCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notEmpty(command.getValues(), "Values must not be empty!"); byte[] keyBuf = toByteArray(command.getKey()); List<Object> params = new ArrayList<Object>(command.getValues().size() + 1); params.add(keyBuf); params.addAll(command.getValues().stream().map(v -> toByteArray(v)).collect(Collectors.toList())); Mono<Long> m = write(keyBuf, StringCodec.INSTANCE, PFADD, params.toArray()); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #4
Source File: RedissonListTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testSortTo() { RList<String> list = redisson.getList("list", IntegerCodec.INSTANCE); list.add("1"); list.add("2"); list.add("3"); assertThat(list.sortTo("test3", SortOrder.DESC)).isEqualTo(3); RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE); assertThat(list2).containsExactly("3", "2", "1"); assertThat(list.sortTo("test4", SortOrder.ASC)).isEqualTo(3); RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE); assertThat(list3).containsExactly("1", "2", "3"); }
Example #5
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 #6
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { List<Object> args = new ArrayList<Object>(sets.length*2 + 5); args.add(destKey); args.add(sets.length); args.addAll(Arrays.asList(sets)); if (weights != null) { args.add("WEIGHTS"); for (int weight : weights) { args.add(weight); } } if (aggregate != null) { args.add("AGGREGATE"); args.add(aggregate.name()); } return write(destKey, StringCodec.INSTANCE, ZINTERSTORE, args.toArray()); }
Example #7
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public Long dbSize() { if (isQueueing()) { return read(null, StringCodec.INSTANCE, RedisCommands.DBSIZE); } RFuture<Long> f = executorService.readAllAsync(RedisCommands.DBSIZE, new SlotCallback<Long, Long>() { AtomicLong results = new AtomicLong(); @Override public void onSlotResult(Long result) { results.addAndGet(result); } @Override public Long onFinish() { return results.get(); } }); return sync(f); }
Example #8
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 6 votes |
@Override public Long dbSize() { if (isQueueing()) { return read(null, StringCodec.INSTANCE, RedisCommands.DBSIZE); } RFuture<Long> f = executorService.readAllAsync(RedisCommands.DBSIZE, new SlotCallback<Long, Long>() { AtomicLong results = new AtomicLong(); @Override public void onSlotResult(Long result) { results.addAndGet(result); } @Override public Long onFinish() { return results.get(); } }); return sync(f); }
Example #9
Source File: RedissonReactiveStringCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<NumericResponse<KeyCommand, Long>> strLen(Publisher<KeyCommand> keys) { return execute(keys, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); Mono<Long> m = read(keyBuf, StringCodec.INSTANCE, RedisCommands.STRLEN, keyBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #10
Source File: RedissonReactiveKeyCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<BooleanResponse<MoveCommand>> move(Publisher<MoveCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getDatabase(), "Database must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); Mono<Boolean> m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.MOVE, keyBuf, command.getDatabase()); return m.map(v -> new BooleanResponse<>(command, v)); }); }
Example #11
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long sDiffStore(byte[] destKey, byte[]... keys) { List<Object> args = new ArrayList<Object>(keys.length + 1); args.add(destKey); args.addAll(Arrays.asList(keys)); return write(keys[0], StringCodec.INSTANCE, RedisCommands.SDIFFSTORE, args.toArray()); }
Example #12
Source File: RedissonReactiveKeyCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<BooleanResponse<ExpireCommand>> pExpire(Publisher<ExpireCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); Mono<Boolean> m = read(keyBuf, StringCodec.INSTANCE, RedisCommands.PEXPIRE, keyBuf); return m.map(v -> new BooleanResponse<>(command, v)); }); }
Example #13
Source File: RedissonReactiveKeyCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<NumericResponse<KeyCommand, Long>> pTtl(Publisher<KeyCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); Mono<Long> m = write(keyBuf, StringCodec.INSTANCE, RedisCommands.PTTL, keyBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #14
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long pfAdd(byte[] key, byte[]... values) { List<Object> params = new ArrayList<Object>(values.length + 1); params.add(key); for (byte[] member : values) { params.add(member); } return write(key, StringCodec.INSTANCE, PFADD, params.toArray()); }
Example #15
Source File: RedissonReactiveKeyCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<NumericResponse<List<ByteBuffer>, Long>> mDel(Publisher<List<ByteBuffer>> keys) { return execute(keys, coll -> { Assert.notNull(coll, "List must not be null!"); Object[] params = coll.stream().map(buf -> toByteArray(buf)).toArray(Object[]::new); Mono<Long> m = read(null, StringCodec.INSTANCE, RedisCommands.DEL, params); return m.map(v -> new NumericResponse<>(coll, v)); }); }
Example #16
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) { List<Object> params = new ArrayList<Object>(memberCoordinateMap.size()*3 + 1); params.add(key); for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) { params.add(entry.getValue().getX()); params.add(entry.getValue().getY()); params.add(entry.getKey()); } return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray()); }
Example #17
Source File: RedissonReactiveKeyCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Mono<ValueEncoding> encodingOf(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); byte[] keyBuf = toByteArray(key); return read(keyBuf, StringCodec.INSTANCE, OBJECT_ENCODING, keyBuf); }
Example #18
Source File: RedissonPriorityQueue.java From redisson with Apache License 2.0 | 5 votes |
@Override public boolean trySetComparator(Comparator<? super V> comparator) { String className = comparator.getClass().getName(); String comparatorSign = className + ":" + calcClassSign(className); Boolean res = get(commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.SETNX, getComparatorKeyName(), comparatorSign)); if (res) { this.comparator = comparator; } return res; }
Example #19
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long sAdd(byte[] key, byte[]... values) { List<Object> args = new ArrayList<Object>(values.length + 1); args.add(key); args.addAll(Arrays.asList(values)); return write(key, StringCodec.INSTANCE, SADD, args.toArray()); }
Example #20
Source File: RedissonClusterConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public ClusterInfo clusterGetClusterInfo() { RFuture<Map<String, String>> f = executorService.readAsync((String)null, StringCodec.INSTANCE, RedisCommands.CLUSTER_INFO); syncFuture(f); Properties props = new Properties(); for (Entry<String, String> entry : f.getNow().entrySet()) { props.setProperty(entry.getKey(), entry.getValue()); } return new ClusterInfo(props); }
Example #21
Source File: RedissonClusterConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long clusterCountKeysInSlot(int slot) { RedisClusterNode node = clusterGetNodeForSlot(slot); MasterSlaveEntry entry = executorService.getConnectionManager().getEntry(new InetSocketAddress(node.getHost(), node.getPort())); RFuture<Long> f = executorService.readAsync(entry, StringCodec.INSTANCE, RedisCommands.CLUSTER_COUNTKEYSINSLOT, slot); return syncFuture(f); }
Example #22
Source File: RedissonReactiveZSetCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<NumericResponse<ZScoreCommand, Double>> zScore(Publisher<ZScoreCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getValue(), "Value must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); byte[] valueBuf = toByteArray(command.getValue()); Mono<Double> m = read(keyBuf, StringCodec.INSTANCE, RedisCommands.ZSCORE, keyBuf, valueBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #23
Source File: RedissonReactiveZSetCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Flux<NumericResponse<KeyCommand, Long>> zCard(Publisher<KeyCommand> commands) { return execute(commands, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); byte[] keyBuf = toByteArray(command.getKey()); Mono<Long> m = read(keyBuf, StringCodec.INSTANCE, RedisCommands.ZCARD, keyBuf); return m.map(v -> new NumericResponse<>(command, v)); }); }
Example #24
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long sUnionStore(byte[] destKey, byte[]... keys) { List<Object> args = new ArrayList<Object>(keys.length + 1); args.add(destKey); args.addAll(Arrays.asList(keys)); return write(keys[0], StringCodec.INSTANCE, RedisCommands.SUNIONSTORE, args.toArray()); }
Example #25
Source File: RedissonSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testSortOrderAlpha(){ RSet<String> set = redisson.getSet("list", StringCodec.INSTANCE); set.add("1"); set.add("3"); set.add("12"); assertThat(set.readSortAlpha(SortOrder.ASC)) .containsExactly("1", "12", "3"); assertThat(set.readSortAlpha(SortOrder.DESC)) .containsExactly("3", "12", "1"); }
Example #26
Source File: RedissonReactiveNumberCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public <T extends Number> Flux<NumericResponse<DecrByCommand<T>, T>> decrBy(Publisher<DecrByCommand<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 #27
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { List<Object> params = new ArrayList<Object>(tuples.size()*2+1); params.add(key); for (Tuple entry : tuples) { params.add(BigDecimal.valueOf(entry.getScore()).toPlainString()); params.add(entry.getValue()); } return write(key, StringCodec.INSTANCE, RedisCommands.ZADD, params.toArray()); }
Example #28
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long zRem(byte[] key, byte[]... values) { List<Object> params = new ArrayList<Object>(values.length+1); params.add(key); params.addAll(Arrays.asList(values)); return write(key, StringCodec.INSTANCE, RedisCommands.ZREM_LONG, params.toArray()); }
Example #29
Source File: RedissonStreamCommands.java From redisson with Apache License 2.0 | 5 votes |
@Override public Long xAck(byte[] key, String group, RecordId... recordIds) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(group, "Group must not be null!"); Assert.notNull(recordIds, "recordIds must not be null!"); List<Object> params = new ArrayList<>(); params.add(key); params.add(group); params.addAll(toStringList(recordIds)); return connection.write(key, StringCodec.INSTANCE, RedisCommands.XACK, params.toArray()); }
Example #30
Source File: RedissonClusterConnection.java From redisson with Apache License 2.0 | 5 votes |
@Override public void clusterDeleteSlots(RedisClusterNode node, int... slots) { MasterSlaveEntry entry = getEntry(node); List<Integer> params = convert(slots); RFuture<Long> f = executorService.writeAsync(entry, StringCodec.INSTANCE, RedisCommands.CLUSTER_DELSLOTS, params.toArray()); syncFuture(f); }