org.springframework.data.redis.connection.RedisListCommands Maven / Gradle / Ivy
/*
* Copyright 2011-2018 the original author or authors.
*
* 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.springframework.data.redis.connection;
import java.util.List;
import org.springframework.lang.Nullable;
/**
* List-specific commands supported by Redis.
*
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
*/
public interface RedisListCommands {
/**
* List insertion position.
*/
enum Position {
BEFORE, AFTER
}
/**
* Append {@code values} to {@code key}.
*
* @param key must not be {@literal null}.
* @param values must not be empty.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: RPUSH
*/
@Nullable
Long rPush(byte[] key, byte[]... values);
/**
* Prepend {@code values} to {@code key}.
*
* @param key must not be {@literal null}.
* @param values must not be empty.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LPUSH
*/
@Nullable
Long lPush(byte[] key, byte[]... values);
/**
* Append {@code values} to {@code key} only if the list exists.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: RPUSHX
*/
@Nullable
Long rPushX(byte[] key, byte[] value);
/**
* Prepend {@code values} to {@code key} only if the list exists.
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LPUSHX
*/
@Nullable
Long lPushX(byte[] key, byte[] value);
/**
* Get the size of list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LLEN
*/
@Nullable
Long lLen(byte[] key);
/**
* Get elements between {@code start} and {@code end} from list at {@code key}.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return empty {@link List} if key does not exists or range does not contain values. {@literal null} when used in
* pipeline / transaction.
* @see Redis Documentation: LRANGE
*/
@Nullable
List lRange(byte[] key, long start, long end);
/**
* Trim list at {@code key} to elements between {@code start} and {@code end}.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @see Redis Documentation: LTRIM
*/
void lTrim(byte[] key, long start, long end);
/**
* Get element at {@code index} form list at {@code key}.
*
* @param key must not be {@literal null}.
* @param index zero based index value. Use negative number to designate elements starting at the tail.
* @return {@literal null} when index is out of range or when used in pipeline / transaction.
* @see Redis Documentation: LINDEX
*/
@Nullable
byte[] lIndex(byte[] key, long index);
/**
* Insert {@code value} {@link Position#BEFORE} or {@link Position#AFTER} existing {@code pivot} for {@code key}.
*
* @param key must not be {@literal null}.
* @param where must not be {@literal null}.
* @param pivot must not be {@literal null}.
* @param value must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LINSERT
*/
@Nullable
Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value);
/**
* Set the {@code value} list element at {@code index}.
*
* @param key must not be {@literal null}.
* @param index
* @param value
* @see Redis Documentation: LSET
*/
void lSet(byte[] key, long index, byte[] value);
/**
* Removes the first {@code count} occurrences of {@code value} from the list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @param count
* @param value
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LREM
*/
@Nullable
Long lRem(byte[] key, long count, byte[] value);
/**
* Removes and returns first element in list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return {@literal null} when key does not exist or used in pipeline / transaction.
* @see Redis Documentation: LPOP
*/
@Nullable
byte[] lPop(byte[] key);
/**
* Removes and returns last element in list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return {@literal null} when key does not exist or used in pipeline / transaction.
* @see Redis Documentation: RPOP
*/
@Nullable
byte[] rPop(byte[] key);
/**
* Removes and returns first element from lists stored at {@code keys}.
* Blocks connection until element available or {@code timeout} reached.
*
* @param timeout seconds to block.
* @param keys must not be {@literal null}.
* @return empty {@link List} when no element could be popped and the timeout was reached. {@literal null} when used
* in pipeline / transaction.
* @see Redis Documentation: BLPOP
* @see #lPop(byte[])
*/
@Nullable
List bLPop(int timeout, byte[]... keys);
/**
* Removes and returns last element from lists stored at {@code keys}.
* Blocks connection until element available or {@code timeout} reached.
*
* @param timeout seconds to block.
* @param keys must not be {@literal null}.
* @return empty {@link List} when no element could be popped and the timeout was reached. {@literal null} when used
* in pipeline / transaction.
* @see Redis Documentation: BRPOP
* @see #rPop(byte[])
*/
@Nullable
List bRPop(int timeout, byte[]... keys);
/**
* Remove the last element from list at {@code srcKey}, append it to {@code dstKey} and return its value.
*
* @param srcKey must not be {@literal null}.
* @param dstKey must not be {@literal null}.
* @return can be {@literal null}.
* @see Redis Documentation: RPOPLPUSH
*/
@Nullable
byte[] rPopLPush(byte[] srcKey, byte[] dstKey);
/**
* Remove the last element from list at {@code srcKey}, append it to {@code dstKey} and return its value.
* Blocks connection until element available or {@code timeout} reached.
*
* @param timeout seconds to block.
* @param srcKey must not be {@literal null}.
* @param dstKey must not be {@literal null}.
* @return can be {@literal null}.
* @see Redis Documentation: BRPOPLPUSH
* @see #rPopLPush(byte[], byte[])
*/
@Nullable
byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey);
}