Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.redisson.RedissonStream Maven / Gradle / Ivy
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.redisson.api.PendingEntry;
import org.redisson.api.PendingResult;
import org.redisson.api.RFuture;
import org.redisson.api.RStream;
import org.redisson.api.StreamMessageId;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
/**
*
* @author Nikita Koksharov
*
* @param key type
* @param value type
*/
public class RedissonStream extends RedissonExpirable implements RStream {
public RedissonStream(Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(codec, connectionManager, name);
}
public RedissonStream(CommandAsyncExecutor connectionManager, String name) {
super(connectionManager, name);
}
protected void checkKey(Object key) {
if (key == null) {
throw new NullPointerException("key can't be null");
}
}
protected void checkValue(Object value) {
if (value == null) {
throw new NullPointerException("value can't be null");
}
}
@Override
public void createGroup(String groupName) {
get(createGroupAsync(groupName));
}
@Override
public RFuture createGroupAsync(String groupName) {
return createGroupAsync(groupName, StreamMessageId.NEWEST);
}
@Override
public void createGroup(String groupName, StreamMessageId id) {
get(createGroupAsync(groupName, id));
}
@Override
public RFuture createGroupAsync(String groupName, StreamMessageId id) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XGROUP, "CREATE", getName(), groupName, id);
}
@Override
public RFuture ackAsync(String groupName, StreamMessageId... ids) {
List params = new ArrayList();
params.add(getName());
params.add(groupName);
for (StreamMessageId id : ids) {
params.add(id);
}
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XACK, params.toArray());
}
@Override
public long ack(String groupName, StreamMessageId... id) {
return get(ackAsync(groupName, id));
}
@Override
public RFuture listPendingAsync(String groupName) {
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.XPENDING, getName(), groupName);
}
@Override
public PendingResult listPending(String groupName) {
return get(listPendingAsync(groupName));
}
@Override
public RFuture> listPendingAsync(String groupName, String consumerName, StreamMessageId startId, StreamMessageId endId, int count) {
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.XPENDING_ENTRIES, getName(), groupName, startId, endId, count, consumerName);
}
@Override
public RFuture> listPendingAsync(String groupName, StreamMessageId startId, StreamMessageId endId, int count) {
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.XPENDING_ENTRIES, getName(), groupName, startId, endId, count);
}
@Override
public List listPending(String groupName, StreamMessageId startId, StreamMessageId endId, int count) {
return get(listPendingAsync(groupName, startId, endId, count));
}
@Override
public List listPending(String groupName, String consumerName, StreamMessageId startId, StreamMessageId endId, int count) {
return get(listPendingAsync(groupName, consumerName, startId, endId, count));
}
@Override
public List fastClaim(String groupName, String consumerName, long idleTime, TimeUnit idleTimeUnit,
StreamMessageId... ids) {
return get(fastClaimAsync(groupName, consumerName, idleTime, idleTimeUnit, ids));
}
@Override
public RFuture> fastClaimAsync(String groupName, String consumerName, long idleTime,
TimeUnit idleTimeUnit, StreamMessageId... ids) {
List params = new ArrayList();
params.add(getName());
params.add(groupName);
params.add(consumerName);
params.add(idleTimeUnit.toMillis(idleTime));
for (StreamMessageId id : ids) {
params.add(id.toString());
}
params.add("JUSTID");
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.XCLAIM_IDS, params.toArray());
}
@Override
public RFuture>> claimAsync(String groupName, String consumerName, long idleTime,
TimeUnit idleTimeUnit, StreamMessageId... ids) {
List params = new ArrayList();
params.add(getName());
params.add(groupName);
params.add(consumerName);
params.add(idleTimeUnit.toMillis(idleTime));
for (StreamMessageId id : ids) {
params.add(id.toString());
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XCLAIM, params.toArray());
}
@Override
public Map> claim(String groupName, String consumerName, long idleTime, TimeUnit idleTimeUnit,
StreamMessageId... ids) {
return get(claimAsync(groupName, consumerName, idleTime, idleTimeUnit, ids));
}
@Override
public RFuture>> readGroupAsync(String groupName, String consumerName, StreamMessageId... ids) {
return readGroupAsync(groupName, consumerName, 0, ids);
}
@Override
public RFuture>> readGroupAsync(String groupName, String consumerName, int count, StreamMessageId... ids) {
return readGroupAsync(groupName, consumerName, count, 0, null, ids);
}
@Override
public RFuture>> readGroupAsync(String groupName, String consumerName, long timeout, TimeUnit unit,
StreamMessageId... ids) {
return readGroupAsync(groupName, consumerName, 0, timeout, unit, ids);
}
@Override
public RFuture>> readGroupAsync(String groupName, String consumerName, int count, long timeout, TimeUnit unit,
StreamMessageId... ids) {
List params = new ArrayList();
params.add("GROUP");
params.add(groupName);
params.add(consumerName);
if (count > 0) {
params.add("COUNT");
params.add(count);
}
if (timeout > 0) {
params.add("BLOCK");
params.add(toSeconds(timeout, unit)*1000);
}
params.add("STREAMS");
params.add(getName());
if (ids.length == 0) {
params.add(">");
}
for (StreamMessageId id : ids) {
params.add(id.toString());
}
if (timeout > 0) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREADGROUP_BLOCKING_SINGLE, params.toArray());
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREADGROUP_SINGLE, params.toArray());
}
@Override
public Map>> readGroup(String groupName, String consumerName, StreamMessageId id, Map keyToId) {
return readGroup(groupName, consumerName, 0, id, keyToId);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName,StreamMessageId id, Map keyToId) {
return readGroupAsync(groupName, consumerName, 0, id, keyToId);
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, StreamMessageId id, Map keyToId) {
return get(readGroupAsync(groupName, consumerName, count, id, keyToId));
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, StreamMessageId id, Map keyToId) {
return readGroupAsync(groupName, consumerName, count, -1, null, id, keyToId);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2) {
return readGroupAsync(groupName, consumerName, count, timeout, unit, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2, String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readGroupAsync(groupName, consumerName, count, timeout, unit, id, params);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return readGroupAsync(groupName, consumerName, 0, timeout, unit, id, keyToId);
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return get(readGroupAsync(groupName, consumerName, count, timeout, unit, id, keyToId));
}
@Override
public Map>> readGroup(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return readGroup(groupName, consumerName, 0, timeout, unit, id, keyToId);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, StreamMessageId id, String key2, StreamMessageId id2) {
return readGroupAsync(groupName, consumerName, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readGroupAsync(groupName, consumerName, id, params);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, StreamMessageId id, String key2, StreamMessageId id2) {
return readGroupAsync(groupName, consumerName, count, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, StreamMessageId id, String key2, StreamMessageId id2,
String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readGroupAsync(groupName, consumerName, count, id, params);
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2) {
return readGroupAsync(groupName, consumerName, timeout, unit, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readGroupAsync(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2, String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readGroupAsync(groupName, consumerName, timeout, unit, id, params);
}
@Override
public Map>> readGroup(String groupName, String consumerName, StreamMessageId id, String key2, StreamMessageId id2) {
return get(readGroupAsync(groupName, consumerName, id, key2, id2));
}
@Override
public Map>> readGroup(String groupName, String consumerName, StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
return get(readGroupAsync(groupName, consumerName, id, key2, id2, key3, id3));
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, StreamMessageId id, String key2, StreamMessageId id2) {
return get(readGroupAsync(groupName, consumerName, count, id, key2, id2));
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
return get(readGroupAsync(groupName, consumerName, count, id, key2, id2, key3, id3));
}
@Override
public Map>> readGroup(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2) {
return get(readGroupAsync(groupName, consumerName, timeout, unit, id, key2, id2));
}
@Override
public Map>> readGroup(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2, String key3, StreamMessageId id3) {
return get(readGroupAsync(groupName, consumerName, timeout, unit, id, key2, id2, key3, id3));
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2) {
return get(readGroupAsync(groupName, consumerName, count, timeout, unit, id, key2, id2));
}
@Override
public Map>> readGroup(String groupName, String consumerName, int count, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2, String key3, StreamMessageId id3) {
return get(readGroupAsync(groupName, consumerName, count, timeout, unit, id, key2, id2, key3, id3));
}
public RFuture>>> readGroupAsync(String groupName, String consumerName, int count, long timeout, TimeUnit unit,
StreamMessageId id, Map keyToId) {
List params = new ArrayList();
params.add("GROUP");
params.add(groupName);
params.add(consumerName);
if (count > 0) {
params.add("COUNT");
params.add(count);
}
if (timeout > 0) {
params.add("BLOCK");
params.add(toSeconds(timeout, unit)*1000);
}
params.add("STREAMS");
params.add(getName());
for (String key : keyToId.keySet()) {
params.add(key);
}
if (id == null) {
params.add(">");
} else {
params.add(id);
}
for (StreamMessageId nextId : keyToId.values()) {
params.add(nextId.toString());
}
if (timeout > 0) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREADGROUP_BLOCKING, params.toArray());
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREADGROUP, params.toArray());
}
@Override
public Map> readGroup(String groupName, String consumerName, StreamMessageId... ids) {
return get(readGroupAsync(groupName, consumerName, ids));
}
@Override
public Map> readGroup(String groupName, String consumerName, int count, StreamMessageId... ids) {
return get(readGroupAsync(groupName, consumerName, count, ids));
}
@Override
public Map> readGroup(String groupName, String consumerName, long timeout, TimeUnit unit, StreamMessageId... ids) {
return get(readGroupAsync(groupName, consumerName, timeout, unit, ids));
}
@Override
public Map> readGroup(String groupName, String consumerName, int count, long timeout, TimeUnit unit,
StreamMessageId... ids) {
return get(readGroupAsync(groupName, consumerName, count, timeout, unit, ids));
}
@Override
public StreamMessageId addAll(Map entries) {
return addAll(entries, 0, false);
}
@Override
public RFuture addAllAsync(Map entries) {
return addAllAsync(entries, 0, false);
}
@Override
public void addAll(StreamMessageId id, Map entries) {
addAll(id, entries, 0, false);
}
@Override
public RFuture addAllAsync(StreamMessageId id, Map entries) {
return addAllAsync(id, entries, 0, false);
}
@Override
public StreamMessageId addAll(Map entries, int trimLen, boolean trimStrict) {
return get(addAllAsync(entries, trimLen, trimStrict));
}
@Override
public RFuture addAllAsync(Map entries, int trimLen, boolean trimStrict) {
return addAllCustomAsync(null, entries, trimLen, trimStrict);
}
@Override
public void addAll(StreamMessageId id, Map entries, int trimLen, boolean trimStrict) {
get(addAllAsync(id, entries, trimLen, trimStrict));
}
private RFuture addAllCustomAsync(StreamMessageId id, Map entries, int trimLen, boolean trimStrict) {
List params = new ArrayList(entries.size()*2 + 1);
params.add(getName());
if (trimLen > 0) {
params.add("MAXLEN");
if (!trimStrict) {
params.add("~");
}
params.add(trimLen);
}
if (id == null) {
params.add("*");
} else {
params.add(id.toString());
}
for (java.util.Map.Entry extends K, ? extends V> t : entries.entrySet()) {
checkKey(t.getKey());
checkValue(t.getValue());
params.add(encodeMapKey(t.getKey()));
params.add(encodeMapValue(t.getValue()));
}
if (id == null) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XADD, params.toArray());
}
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XADD_VOID, params.toArray());
}
@Override
public RFuture addAllAsync(StreamMessageId id, Map entries, int trimLen, boolean trimStrict) {
return addAllCustomAsync(id, entries, trimLen, trimStrict);
}
@Override
public long size() {
return get(sizeAsync());
}
@Override
public RFuture sizeAsync() {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XLEN, getName());
}
@Override
public Map>> read(StreamMessageId id, Map keyToId) {
return read(0, id, keyToId);
}
@Override
public RFuture>>> readAsync(StreamMessageId id, Map keyToId) {
return readAsync(0, id, keyToId);
}
@Override
public Map>> read(int count, StreamMessageId id, Map keyToId) {
return get(readAsync(count, id, keyToId));
}
@Override
public RFuture>>> readAsync(int count, StreamMessageId id, Map keyToId) {
return readAsync(count, -1, null, id, keyToId);
}
@Override
public RFuture>>> readAsync(int count, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2) {
return readAsync(count, timeout, unit, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readAsync(int count, long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2, String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readAsync(count, timeout, unit, id, params);
}
@Override
public RFuture>>> readAsync(long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return readAsync(0, timeout, unit, id, keyToId);
}
@Override
public Map>> read(int count, long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return get(readAsync(count, timeout, unit, id, keyToId));
}
@Override
public Map>> read(long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
return read(0, timeout, unit, id, keyToId);
}
@Override
public RFuture>>> readAsync(StreamMessageId id, String key2, StreamMessageId id2) {
return readAsync(id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readAsync(StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readAsync(id, params);
}
@Override
public RFuture>>> readAsync(int count, StreamMessageId id, String key2, StreamMessageId id2) {
return readAsync(count, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readAsync(int count, StreamMessageId id, String key2, StreamMessageId id2,
String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readAsync(count, id, params);
}
@Override
public RFuture>>> readAsync(long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2) {
return readAsync(timeout, unit, id, Collections.singletonMap(key2, id2));
}
@Override
public RFuture>>> readAsync(long timeout, TimeUnit unit, StreamMessageId id,
String key2, StreamMessageId id2, String key3, StreamMessageId id3) {
Map params = new HashMap(2);
params.put(key2, id2);
params.put(key3, id3);
return readAsync(timeout, unit, id, params);
}
@Override
public Map>> read(StreamMessageId id, String key2, StreamMessageId id2) {
return get(readAsync(id, key2, id2));
}
@Override
public Map>> read(StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
return get(readAsync(id, key2, id2, key3, id3));
}
@Override
public Map>> read(int count, StreamMessageId id, String key2, StreamMessageId id2) {
return get(readAsync(count, id, key2, id2));
}
@Override
public Map>> read(int count, StreamMessageId id, String key2, StreamMessageId id2, String key3,
StreamMessageId id3) {
return get(readAsync(count, id, key2, id2, key3, id3));
}
@Override
public Map>> read(long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2) {
return get(readAsync(timeout, unit, id, key2, id2));
}
@Override
public Map>> read(long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2, String key3, StreamMessageId id3) {
return get(readAsync(timeout, unit, id, key2, id2, key3, id3));
}
@Override
public Map>> read(int count, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2) {
return get(readAsync(count, timeout, unit, id, key2, id2));
}
@Override
public Map>> read(int count, long timeout, TimeUnit unit, StreamMessageId id, String key2,
StreamMessageId id2, String key3, StreamMessageId id3) {
return get(readAsync(count, timeout, unit, id, key2, id2, key3, id3));
}
@Override
public RFuture>>> readAsync(int count, long timeout, TimeUnit unit, StreamMessageId id, Map keyToId) {
List params = new ArrayList();
if (count > 0) {
params.add("COUNT");
params.add(count);
}
if (timeout > 0) {
params.add("BLOCK");
params.add(toSeconds(timeout, unit)*1000);
}
params.add("STREAMS");
params.add(getName());
for (String key : keyToId.keySet()) {
params.add(key);
}
params.add(id);
for (StreamMessageId nextId : keyToId.values()) {
params.add(nextId.toString());
}
if (timeout > 0) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREAD_BLOCKING, params.toArray());
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREAD, params.toArray());
}
@Override
public RFuture addAsync(K key, V value) {
return addAsync(key, value, 0, false);
}
@Override
public RFuture addAsync(StreamMessageId id, K key, V value) {
return addAsync(id, key, value, 0, false);
}
@Override
public RFuture addAsync(K key, V value, int trimLen, boolean trimStrict) {
return addCustomAsync(null, key, value, trimLen, trimStrict);
}
private RFuture addCustomAsync(StreamMessageId id, K key, V value, int trimLen, boolean trimStrict) {
List params = new LinkedList();
params.add(getName());
if (trimLen > 0) {
params.add("MAXLEN");
if (!trimStrict) {
params.add("~");
}
params.add(trimLen);
}
if (id == null) {
params.add("*");
} else {
params.add(id.toString());
}
checkKey(key);
checkValue(value);
params.add(encodeMapKey(key));
params.add(encodeMapValue(value));
if (id == null) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XADD, params.toArray());
}
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XADD_VOID, params.toArray());
}
@Override
public RFuture addAsync(StreamMessageId id, K key, V value, int trimLen, boolean trimStrict) {
return addCustomAsync(id, key, value, trimLen, trimStrict);
}
@Override
public StreamMessageId add(K key, V value) {
return get(addAsync(key, value));
}
@Override
public void add(StreamMessageId id, K key, V value) {
get(addAsync(id, key, value));
}
@Override
public StreamMessageId add(K key, V value, int trimLen, boolean trimStrict) {
return get(addAsync(key, value, trimLen, trimStrict));
}
@Override
public void add(StreamMessageId id, K key, V value, int trimLen, boolean trimStrict) {
get(addAsync(id, key, value, trimLen, trimStrict));
}
@Override
public RFuture>> readAsync(int count, StreamMessageId... ids) {
return readAsync(count, 0, null, ids);
}
@Override
public Map> read(int count, long timeout, TimeUnit unit, StreamMessageId... ids) {
return get(readAsync(count, timeout, unit, ids));
}
@Override
public Map> read(int count, StreamMessageId ... ids) {
return get(readAsync(count, ids));
}
@Override
public RFuture>> readAsync(int count, long timeout, TimeUnit unit,
StreamMessageId... ids) {
List params = new ArrayList();
if (count > 0) {
params.add("COUNT");
params.add(count);
}
if (timeout > 0) {
params.add("BLOCK");
params.add(toSeconds(timeout, unit)*1000);
}
params.add("STREAMS");
params.add(getName());
for (StreamMessageId id : ids) {
params.add(id.toString());
}
if (timeout > 0) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREAD_BLOCKING_SINGLE, params.toArray());
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREAD_SINGLE, params.toArray());
}
@Override
public RFuture>> rangeAsync(int count, StreamMessageId startId, StreamMessageId endId) {
List params = new LinkedList();
params.add(getName());
params.add(startId);
params.add(endId);
if (count > 0) {
params.add("COUNT");
params.add(count);
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XRANGE, params.toArray());
}
@Override
public Map> range(int count, StreamMessageId startId, StreamMessageId endId) {
return get(rangeAsync(count, startId, endId));
}
@Override
public RFuture>> rangeReversedAsync(int count, StreamMessageId startId, StreamMessageId endId) {
List params = new LinkedList();
params.add(getName());
params.add(startId);
params.add(endId);
if (count > 0) {
params.add("COUNT");
params.add(count);
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.XREVRANGE, params.toArray());
}
@Override
public Map> rangeReversed(int count, StreamMessageId startId, StreamMessageId endId) {
return get(rangeReversedAsync(count, startId, endId));
}
@Override
public RFuture>> readAsync(StreamMessageId... ids) {
return readAsync(0, ids);
}
@Override
public RFuture>> readAsync(long timeout, TimeUnit unit, StreamMessageId... ids) {
return readAsync(0, timeout, unit, ids);
}
@Override
public RFuture>> rangeAsync(StreamMessageId startId, StreamMessageId endId) {
return rangeAsync(0, startId, endId);
}
@Override
public RFuture>> rangeReversedAsync(StreamMessageId startId, StreamMessageId endId) {
return rangeReversedAsync(0, startId, endId);
}
@Override
public Map> read(StreamMessageId... ids) {
return read(0, ids);
}
@Override
public Map> read(long timeout, TimeUnit unit, StreamMessageId... ids) {
return read(0, timeout, unit, ids);
}
@Override
public Map> range(StreamMessageId startId, StreamMessageId endId) {
return range(0, startId, endId);
}
@Override
public Map> rangeReversed(StreamMessageId startId, StreamMessageId endId) {
return rangeReversed(0, startId, endId);
}
@Override
public RFuture removeAsync(StreamMessageId... ids) {
List params = new ArrayList();
params.add(getName());
for (StreamMessageId id : ids) {
params.add(id);
}
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XDEL, params.toArray());
}
@Override
public long remove(StreamMessageId... ids) {
return get(removeAsync(ids));
}
@Override
public RFuture trimAsync(int count) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XTRIM, "MAXLEN", count);
}
@Override
public RFuture trimNonStrictAsync(int count) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XTRIM, "MAXLEN", "~", count);
}
@Override
public long trim(int count) {
return get(trimAsync(count));
}
@Override
public long trimNonStrict(int count) {
return get(trimNonStrictAsync(count));
}
@Override
public RFuture removeGroupAsync(String groupName) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XGROUP, "DESTROY", getName(), groupName);
}
@Override
public void removeGroup(String groupName) {
get(removeGroupAsync(groupName));
}
@Override
public RFuture removeConsumerAsync(String groupName, String consumerName) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XGROUP_LONG, "DELCONSUMER", getName(), groupName, consumerName);
}
@Override
public long removeConsumer(String groupName, String consumerName) {
return get(removeConsumerAsync(groupName, consumerName));
}
@Override
public RFuture updateGroupMessageIdAsync(String groupName, StreamMessageId id) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.XGROUP, "SETID", getName(), groupName, id);
}
@Override
public void updateGroupMessageId(String groupName, StreamMessageId id) {
get(updateGroupMessageIdAsync(groupName, id));
}
}