org.springframework.data.redis.connection.stream.RecordId Java Examples
The following examples show how to use
org.springframework.data.redis.connection.stream.RecordId.
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: RedissonReactiveStreamCommands.java From redisson with Apache License 2.0 | 6 votes |
@Override public Flux<ReactiveRedisConnection.CommandResponse<AddStreamRecord, RecordId>> xAdd(Publisher<AddStreamRecord> publisher) { return execute(publisher, command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getBody(), "Body must not be null!"); byte[] k = toByteArray(command.getKey()); List<Object> params = new LinkedList<>(); params.add(k); if (!command.getRecord().getId().shouldBeAutoGenerated()) { params.add(command.getRecord().getId().getValue()); } else { params.add("*"); } for (Map.Entry<ByteBuffer, ByteBuffer> entry : command.getBody().entrySet()) { params.add(toByteArray(entry.getKey())); params.add(toByteArray(entry.getValue())); } Mono<StreamMessageId> m = write(k, StringCodec.INSTANCE, RedisCommands.XADD, params.toArray()); return m.map(v -> new ReactiveRedisConnection.CommandResponse<>(command, RecordId.of(v.toString()))); }); }
Example #2
Source File: SyncStreamApiTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Test public void basics() { // XADD with fixed id RecordId fixedId1 = streamOps.add(SensorData.RECORD_1234_0); assertThat(fixedId1).isEqualTo(SensorData.RECORD_1234_0.getId()); RecordId fixedId2 = streamOps.add(SensorData.RECORD_1234_1); assertThat(fixedId2).isEqualTo(SensorData.RECORD_1234_1.getId()); // XLEN assertThat(streamOps.size(SensorData.KEY)).isEqualTo(2L); // XADD errors when timestamp is less then last inserted assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { streamOps.add(SensorData.create("1234", "19.8", "invalid").withId(RecordId.of("0-0"))); }).withMessageContaining("ID specified"); // XADD with autogenerated id RecordId autogeneratedId = streamOps.add(SensorData.create("1234", "19.8", null)); assertThat(autogeneratedId.getValue()).endsWith("-0"); assertThat(streamOps.size(SensorData.KEY)).isEqualTo(3L); // XREAD from start List<MapRecord<String, String, String>> fromStart = streamOps.read(fromStart(SensorData.KEY)); assertThat(fromStart).hasSize(3).extracting(MapRecord::getId).containsExactly(fixedId1, fixedId2, autogeneratedId); // XREAD resume after List<MapRecord<String, String, String>> fromOffset = streamOps.read(StreamOffset.create(SensorData.KEY, ReadOffset.from(fixedId2))); assertThat(fromOffset).hasSize(1).extracting(MapRecord::getId).containsExactly(autogeneratedId); }
Example #3
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public Long xAck(byte[] key, String group, RecordId... recordIds) { return helper.doInScope(RedisCommand.XACK, () -> connection.xAck(key, group, recordIds)); }
Example #4
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public RecordId xAdd(MapRecord<byte[], byte[], byte[]> record) { return helper.doInScope(RedisCommand.XADD, () -> connection.xAdd(record)); }
Example #5
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public Long xDel(byte[] key, RecordId... recordIds) { return helper.doInScope(RedisCommand.XDEL, () -> connection.xDel(key, recordIds)); }
Example #6
Source File: ReactiveStreamApiTests.java From spring-data-examples with Apache License 2.0 | 4 votes |
@Test public void basics() { // XADD with fixed id streamOps.add(SensorData.RECORD_1234_0) .as(StepVerifier::create) .expectNext(SensorData.RECORD_1234_0.getId()).verifyComplete(); streamOps.add(SensorData.RECORD_1234_1) .as(StepVerifier::create) .expectNext(SensorData.RECORD_1234_1.getId()).verifyComplete(); // XLEN streamOps.size(SensorData.KEY) .as(StepVerifier::create) .expectNext(2L).verifyComplete(); // XADD errors when timestamp is less then last inserted streamOps.add(SensorData.create("1234", "19.8", "invalid").withId(RecordId.of("0-0"))) .as(StepVerifier::create) .verifyError(RedisSystemException.class); // XADD with autogenerated id streamOps.add(SensorData.create("1234", "19.8", null)) .as(StepVerifier::create) .consumeNextWith(autogeneratedId -> autogeneratedId.getValue().endsWith("-0")).verifyComplete(); streamOps.size(SensorData.KEY) .as(StepVerifier::create) .expectNext(3L).verifyComplete(); // XREAD from start streamOps.read(fromStart(SensorData.KEY)) .map(MapRecord::getId) .as(StepVerifier::create) .expectNext(SensorData.RECORD_1234_0.getId(), SensorData.RECORD_1234_1.getId()) .expectNextCount(1).verifyComplete(); // XREAD resume after streamOps.read(StreamOffset.create(SensorData.KEY, ReadOffset.from(SensorData.RECORD_1234_1.getId()))) .as(StepVerifier::create) .expectNextCount(1).verifyComplete(); }
Example #7
Source File: RedissonReactiveStreamCommands.java From redisson with Apache License 2.0 | 4 votes |
private static List<String> toStringList(List<RecordId> recordIds) { return recordIds.stream().map(RecordId::getValue).collect(Collectors.toList()); }