/* * Copyright 2011-2017 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; /** * List-specific commands supported by Redis. * * @author Costin Leau * @author Christoph Strobl * @author Mark Paluch */ public interface RedisListCommands { /** * List insertion position. */ public enum Position { BEFORE, AFTER } /** * Append {@code values} to {@code key}. * * @param key must not be {@literal null}. * @param values * @return * @see <a href="http://redis.io/commands/rpush">Redis Documentation: RPUSH</a> */ Long rPush(byte[] key, byte[]... values); /** * Prepend {@code values} to {@code key}. * * @param key must not be {@literal null}. * @param values * @return * @see <a href="http://redis.io/commands/lpush">Redis Documentation: LPUSH</a> */ 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 * @return * @see <a href="http://redis.io/commands/rpushx">Redis Documentation: RPUSHX</a> */ 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 * @return * @see <a href="http://redis.io/commands/lpushx">Redis Documentation: LPUSHX</a> */ Long lPushX(byte[] key, byte[] value); /** * Get the size of list stored at {@code key}. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/llen">Redis Documentation: LLEN</a> */ 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 * @see <a href="http://redis.io/commands/lrange">Redis Documentation: LRANGE</a> */ List<byte[]> 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 <a href="http://redis.io/commands/ltrim">Redis Documentation: LTRIM</a> */ 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 * @return * @see <a href="http://redis.io/commands/lindex">Redis Documentation: LINDEX</a> */ 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 * @param value * @return * @see <a href="http://redis.io/commands/linsert">Redis Documentation: LINSERT</a> */ 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 <a href="http://redis.io/commands/lset">Redis Documentation: LSET</a> */ 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 * @see <a href="http://redis.io/commands/lrem">Redis Documentation: LREM</a> */ 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 * @see <a href="http://redis.io/commands/lpop">Redis Documentation: LPOP</a> */ byte[] lPop(byte[] key); /** * Removes and returns last element in list stored at {@code key}. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/rpop">Redis Documentation: RPOP</a> */ byte[] rPop(byte[] key); /** * Removes and returns first element from lists stored at {@code keys}. <br> * <b>Blocks connection</b> until element available or {@code timeout} reached. * * @param timeout * @param keys must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/blpop">Redis Documentation: BLPOP</a> * @see #lPop(byte[]) */ List<byte[]> bLPop(int timeout, byte[]... keys); /** * Removes and returns last element from lists stored at {@code keys}. <br> * <b>Blocks connection</b> until element available or {@code timeout} reached. * * @param timeout * @param keys must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/brpop">Redis Documentation: BRPOP</a> * @see #rPop(byte[]) */ List<byte[]> 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 * @see <a href="http://redis.io/commands/rpoplpush">Redis Documentation: RPOPLPUSH</a> */ byte[] rPopLPush(byte[] srcKey, byte[] dstKey); /** * Remove the last element from list at {@code srcKey}, append it to {@code dstKey} and return its value. * <br> * <b>Blocks connection</b> until element available or {@code timeout} reached. * * @param timeout * @param srcKey must not be {@literal null}. * @param dstKey must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/brpoplpush">Redis Documentation: BRPOPLPUSH</a> * @see #rPopLPush(byte[], byte[]) */ byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey); }