Class RedisConnection
- java.lang.Object
-
- com.blackrook.redis.RedisConnectionAbstract
-
- com.blackrook.redis.RedisConnection
-
- All Implemented Interfaces:
RedisConnectionCommands
,RedisHyperlogCommands
,RedisScanCommands
,AutoCloseable
public class RedisConnection extends RedisConnectionAbstract implements RedisConnectionCommands, RedisHyperlogCommands, RedisScanCommands
A single connection to a Redis server.- Author:
- Matthew Tropiano
-
-
Field Summary
-
Fields inherited from class com.blackrook.redis.RedisConnectionAbstract
reader, writer
-
Fields inherited from interface com.blackrook.redis.commands.RedisConnectionCommands
TTL_NO_EXPIRE, TTL_NOT_EXIST
-
-
Constructor Summary
Constructors Constructor Description RedisConnection()
Creates an open connection to localhost, port 6379, the default Redis port.RedisConnection(RedisInfo info)
Creates an open connection.RedisConnection(String host, int port)
Creates an open connection.RedisConnection(String host, int port, String password)
Creates an open connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
append(String key, String value)
long
bitcount(String key)
long
bitcount(String key, long start, long end)
long
bitop(BitwiseOperation operation, String destkey, String key, String... keys)
long
bitpos(String key, long bit)
long
bitpos(String key, long bit, Long start, Long end)
KeyValue<String,String>
blpop(long timeout, String key, String... keys)
KeyValue<String,Long>
blpopLong(long timeout, String key, String... keys)
Likeblpop(long, String, String...)
, except it casts the value to a long integer.KeyValue<String,String>
brpop(long timeout, String key, String... keys)
KeyValue<String,Long>
brpopLong(long timeout, String key, String... keys)
Likebrpop(long, String, String...)
, except it casts the value to a long integer.String
brpoplpush(long timeout, String source, String destination)
Long
brpoplpushLong(long timeout, String source, String destination)
Likebrpoplpush(long, String, String)
, except it casts the value to a long integer.String
clientGetName()
boolean
clientSetName(String name)
long
decr(String key)
long
decrby(String key, long decrement)
long
del(String key, String... keys)
String
dump(String key)
String
echo(String message)
RedisObject
eval(String scriptContent, String[] keys, Object... args)
RedisObject
evalsha(String hash, String[] keys, Object... args)
boolean
exists(String key)
boolean
expire(String key, long seconds)
boolean
expireat(String key, long timestamp)
String
get(String key)
long
getbit(String key, long offset)
Long
getLong(String key)
Just likeget(String)
, but it casts the result to a long integer.String
getrange(String key, long start, long end)
String
getset(String key, Number value)
String
getset(String key, String value)
Long
getsetLong(String key, Number value)
Just likegetset(String, String)
, but it casts the result to a long integer.Long
getsetLong(String key, String value)
Just likegetset(String, String)
, but it casts the result to a long integer.long
hdel(String key, String field, String... fields)
boolean
hexists(String key, String field)
String
hget(String key, String field)
String[]
hgetall(String key)
HashMap<String,String>
hgetallMap(String key)
Just likehgetall(String)
, except the keys and values are returned in a map of key to value.<T> T
hgetallObject(String key, Class<T> type)
Just likehgetall(String)
, except the keys and values are set on a new instance of a Java object via reflection.<T> void
hgetallObject(String key, T object)
Just likehgetall(String)
, except the keys and values are set on an existing instance of a Java object via reflection.Long
hgetLong(String key, String field)
Just likehget(String, String)
, but it casts the result to a long integer.long
hincrby(String key, String field, long increment)
double
hincrbyfloat(String key, String field, double increment)
String[]
hkeys(String key)
long
hlen(String key)
String[]
hmget(String key, String field, String... fields)
boolean
hmset(String key, KeyValue<String,Object>... pairs)
Likehmset(String, String, String, String...)
, except abstracted asKeyValue
s of key-value pairs.boolean
hmset(String key, Object field, Object value, Object... fieldvalues)
boolean
hmset(String key, String field, String value, String... fieldvalues)
boolean
hmsetMap(String key, Map<String,Object> map)
Likehmset(String, String, String, String...)
, except abstracted as a map of key-value pairs.<T> boolean
hmsetObject(String key, T object)
Likehmset(String, String, String, String...)
, except each field or getter sets the fields and values.RedisCursor
hscan(String key, long cursor)
RedisCursor
hscan(String key, long cursor, long count)
RedisCursor
hscan(String key, long cursor, String pattern)
RedisCursor
hscan(String key, long cursor, String pattern, Long count)
boolean
hset(String key, String field, Number value)
boolean
hset(String key, String field, String value)
boolean
hsetnx(String key, String field, Number value)
boolean
hsetnx(String key, String field, String value)
String[]
hvals(String key)
long
incr(String key)
long
incrby(String key, long increment)
double
incrbyfloat(String key, double increment)
String[]
keys(String pattern)
String
lindex(String key, long index)
Long
lindexLong(String key, long index)
Likelindex(String, long)
, except it casts the value to a long integer.long
linsert(String key, boolean before, String pivot, Number value)
long
linsert(String key, boolean before, String pivot, String value)
long
llen(String key)
String
lpop(String key)
Long
lpopLong(String key)
Likelpop(String)
, except it casts the value to a long integer.long
lpush(String key, String value, String... values)
long
lpushx(String key, String value)
String[]
lrange(String key, long start, long stop)
long
lrem(String key, long count, String value)
boolean
lset(String key, long index, String value)
boolean
ltrim(String key, long start, long stop)
String[]
mget(String key, String... keys)
boolean
move(String key, long db)
boolean
mset(KeyValue<String,Object>... pairs)
LikeRedisConnectionCommands.mset(String, String, String...)
, but takes key-value pairs.boolean
mset(String key, String value, String... keyValues)
boolean
msetnx(KeyValue<String,Object>... pairs)
LikeRedisConnectionCommands.msetnx(String, String, String...)
, but takes key-value pairs.boolean
msetnx(String key, String value, String... keyValues)
boolean
persist(String key)
boolean
pexpire(String key, long milliseconds)
boolean
pexpireat(String key, long timestamp)
boolean
pfadd(String key, String element, String... elements)
long
pfcount(String key, String... keys)
boolean
pfmerge(String destkey, String sourcekey, String... sourcekeys)
long
ping()
boolean
psetex(String key, long milliseconds, String value)
long
pttl(String key)
long
publish(String channel, String message)
boolean
quit()
String
randomkey()
boolean
rename(String key, String newkey)
boolean
renamenx(String key, String newkey)
boolean
restore(String key, long ttl, String serializedvalue)
String
rpop(String key)
Long
rpopLong(String key)
Likerpop(String)
, except it casts the value to a long integer.String
rpoplpush(String source, String destination)
Long
rpoplpushLong(String source, String destination)
Likerpoplpush(String, String)
, except it casts the value to a long integer.long
rpush(String key, String value, String... values)
long
rpushx(String key, String value)
long
sadd(String key, Object member, Object... members)
long
sadd(String key, String member, String... members)
RedisCursor
scan(long cursor)
RedisCursor
scan(long cursor, long count)
RedisCursor
scan(long cursor, String pattern)
RedisCursor
scan(long cursor, String pattern, Long count)
long
scard(String key)
boolean[]
scriptExists(String scriptHash, String... scriptHashes)
boolean
scriptFlush()
boolean
scriptKill(String hash)
String
scriptLoad(File content)
String
scriptLoad(InputStream content)
String
scriptLoad(String content)
String[]
sdiff(String key, String... keys)
long
sdiffstore(String destination, String key, String... keys)
boolean
set(String key, Number value)
boolean
set(String key, String value)
long
setbit(String key, long offset, long value)
boolean
setex(String key, long seconds, String value)
boolean
setnx(String key, String value)
long
setrange(String key, long offset, String value)
String[]
sinter(String key, String... keys)
long
sinterstore(String destination, String key, String... keys)
boolean
sismember(String key, Number member)
boolean
sismember(String key, String member)
String[]
smembers(String key)
boolean
smove(String source, String destination, String member)
String[]
sort(String key, String pattern, SortOrder sortOrder, boolean alpha, Long limitOffset, Long limitCount, String storeKey, String... getPatterns)
protected String
specialDouble(double d)
Converts some of Java's primitive doubles to Redis interval values.String
spop(String key)
Long
spopLong(String key)
Likespop(String)
, except it casts the value to a long integer.String
srandmember(String key)
String[]
srandmember(String key, long count)
long
srem(String key, Object member, Object... members)
long
srem(String key, String member, String... members)
RedisCursor
sscan(String key, long cursor)
RedisCursor
sscan(String key, long cursor, long count)
RedisCursor
sscan(String key, long cursor, String pattern)
RedisCursor
sscan(String key, String cursor, String pattern, Long count)
RedisPipeline
startPipeline()
Creates a pipelined set of commands.long
strlen(String key)
String[]
sunion(String key, String... keys)
long
sunionstore(String destination, String key, String... keys)
long
ttl(String key)
DataType
type(String key)
long
zadd(String key, double score, Number member)
long
zadd(String key, double score, String member)
long
zadd(String key, KeyValue<Double,String>... pairs)
long
zcard(String key)
long
zcount(String key, double min, double max)
Likezcount(String, String, String)
, except it accepts doubles for min and max, not strings.long
zcount(String key, String min, String max)
double
zincrby(String key, double increment, String member)
long
zinterstore(String destination, double[] weights, Aggregation aggregation, String key, String... keys)
long
zinterstore(String destination, double[] weights, String key, String... keys)
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except it does no aggregation of scores.long
zinterstore(String destination, Aggregation aggregation, String key, String... keys)
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores.long
zinterstore(String destination, String key, String... keys)
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores, and does no aggregation of scores.long
zlexcount(String key, double min, double max)
LikeRedisConnectionCommands.zlexcount(String, String, String)
, except it accepts doubles for min and max, not strings.long
zlexcount(String key, String min, String max)
String[]
zrange(String key, long start, long stop, boolean withScores)
long
zrangebylex(String key, double min, double max)
Likezrangebylex(String, String, String)
, except it accepts doubles for min and max, not strings, with no limit.long
zrangebylex(String key, double min, double max, Long limitOffset, Long limitCount)
Likezrangebylex(String, String, String, Long, Long)
, except it accepts doubles for min and max, not strings.long
zrangebylex(String key, String min, String max)
Likezrangebylex(String, String, String, Long, Long)
, with no limit.long
zrangebylex(String key, String min, String max, Long limitOffset, Long limitCount)
String[]
zrangebyscore(String key, double min, double max, boolean withScores)
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean)
, except it accepts doubles for min and max, not strings.String[]
zrangebyscore(String key, double min, double max, boolean withScores, Long limitOffset, Long limitCount)
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean, Long, Long)
, except it accepts doubles for min and max, not strings.String[]
zrangebyscore(String key, String min, String max, boolean withScores)
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean, Long, Long)
, except specifies no limit.String[]
zrangebyscore(String key, String min, String max, boolean withScores, Long limitOffset, Long limitCount)
Long
zrank(String key, Number member)
Long
zrank(String key, String member)
long
zrem(String key, Number member, Number... members)
long
zrem(String key, String member, String... members)
long
zremrangebylex(String key, double min, double max)
LikeRedisConnectionCommands.zrangebylex(String, String, String)
, except it accepts doubles for min and max.long
zremrangebylex(String key, String min, String max)
long
zremrangebyrank(String key, long start, long stop)
long
zremrangebyscore(String key, double min, double max)
Likezremrangebyscore(String, String, String)
, except it accepts doubles for min and max, not strings.long
zremrangebyscore(String key, String min, String max)
String[]
zrevrange(String key, long start, long stop, boolean withScores)
String[]
zrevrangebyscore(String key, double min, double max, boolean withScores)
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean)
, except it accepts doubles for min and max, not strings.String[]
zrevrangebyscore(String key, double min, double max, boolean withScores, Long limitOffset, Long limitCount)
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean, Long, Long)
, except it accepts doubles for min and max, not strings.String[]
zrevrangebyscore(String key, String min, String max, boolean withScores)
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean, Long, Long)
, except specifies no limit.String[]
zrevrangebyscore(String key, String min, String max, boolean withScores, Long limitOffset, Long limitCount)
Long
zrevrank(String key, String member)
RedisCursor
zscan(String key, long cursor)
RedisCursor
zscan(String key, long cursor, long count)
RedisCursor
zscan(String key, long cursor, String pattern)
RedisCursor
zscan(String key, long cursor, String pattern, Long count)
Double
zscore(String key, String member)
long
zunionstore(String destination, double[] weights, Aggregation aggregation, String key, String... keys)
long
zunionstore(String destination, double[] weights, String key, String... keys)
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except it does no aggregation of scores.long
zunionstore(String destination, Aggregation aggregation, String key, String... keys)
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores.long
zunionstore(String destination, String key, String... keys)
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores, and does no aggregation of scores.-
Methods inherited from class com.blackrook.redis.RedisConnectionAbstract
close, disconnect, isBound, isClosed, isConnected, reconnect
-
-
-
-
Constructor Detail
-
RedisConnection
public RedisConnection() throws IOException
Creates an open connection to localhost, port 6379, the default Redis port.- Throws:
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- if the IP address of the host could not be determined.SecurityException
- if a security manager exists and doesn't allow the connection to be made.
-
RedisConnection
public RedisConnection(String host, int port) throws IOException
Creates an open connection.- Parameters:
host
- the server hostname or address.port
- the server connection port.- Throws:
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- if the IP address of the host could not be determined.SecurityException
- if a security manager exists and doesn't allow the connection to be made.
-
RedisConnection
public RedisConnection(String host, int port, String password) throws IOException
Creates an open connection.- Parameters:
host
- the server hostname or address.port
- the server connection port.password
- the server database password.- Throws:
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- if the IP address of the host could not be determined.SecurityException
- if a security manager exists and doesn't allow the connection to be made.RedisException
- if the password in the server information is incorrect.
-
RedisConnection
public RedisConnection(RedisInfo info) throws IOException
Creates an open connection.- Parameters:
info
- theRedisInfo
class detailing a connection.- Throws:
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- if the IP address of the host could not be determined.SecurityException
- if a security manager exists and doesn't allow the connection to be made.RedisException
- if the password in the server information is incorrect.
-
-
Method Detail
-
startPipeline
public RedisPipeline startPipeline()
Creates a pipelined set of commands.- Returns:
- a new pipeline.
-
echo
public String echo(String message)
Description copied from interface:RedisConnectionCommands
- Specified by:
echo
in interfaceRedisConnectionCommands
- Returns:
- the string sent to the server.
-
ping
public long ping()
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/ping:
Available since 1.0.0.
This command is often used to test if a connection is still alive, or to measure latency.
- Specified by:
ping
in interfaceRedisConnectionCommands
- Returns:
- milliseconds between the call and the response. Ordinarily, Redis just returns "PONG", which is not very useful API-wise.
-
quit
public boolean quit()
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/quit:
Available since 1.0.0.
Ask the server to close the connection. The connection is closed as soon as all pending replies have been written to the client.
- Specified by:
quit
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
clientGetName
public String clientGetName()
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/client-getname:
Available since 2.6.9.
Time complexity: O(1)
The
CLIENT GETNAME
returns the name of the current connection as set byCLIENT SETNAME
. Since every new connection starts without an associated name, if no name was assigned a null bulk reply is returned.- Specified by:
clientGetName
in interfaceRedisConnectionCommands
- Returns:
- the connection name, or null if no name is set.
-
clientSetName
public boolean clientSetName(String name)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/client-setname:
Available since 2.6.9.
Time complexity: O(1)
The
CLIENT SETNAME
command assigns a name to the current connection.- Specified by:
clientSetName
in interfaceRedisConnectionCommands
- Returns:
- true if successful, false otherwise.
-
del
public long del(String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/del:
Available since 1.0.0.
Time complexity: O(N) where N is the number of keys that will be removed. When a key to remove holds a value other than a string, the individual complexity for this key is O(M) where M is the number of elements in the list, set, sorted set or hash. Removing a single key that holds a string value is O(1).
Removes the specified keys. A key is ignored if it does not exist.
- Specified by:
del
in interfaceRedisConnectionCommands
- Parameters:
key
- the first key to delete.keys
- the additional keys to delete.- Returns:
- The number of keys that were removed.
-
dump
public String dump(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/dump:
Available since 2.6.0.
Time complexity: O(1) to access the key and additional O(N*M) to serialized it, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1).
Serialize the value stored at key in a Redis-specific format and return it to the user. The returned value can be synthesized back into a Redis key using the
RedisConnectionCommands.restore(java.lang.String, long, java.lang.String)
command.- Specified by:
dump
in interfaceRedisConnectionCommands
- Returns:
- the serialized value.
-
exists
public boolean exists(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/exists:
Available since 1.0.0.
Time complexity: O(1)
Returns if
key
exists.- Specified by:
exists
in interfaceRedisConnectionCommands
- Returns:
- true if the key exists, false if not.
-
expire
public boolean expire(String key, long seconds)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/expire:
Available since 1.0.0.
Time complexity: O(1)
Set a timeout on
key
. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.- Specified by:
expire
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to expire.seconds
- the time-to-live in seconds.- Returns:
- true if set, false if not set.
-
expireat
public boolean expireat(String key, long timestamp)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/expireat:
Available since 1.2.0.
Time complexity: O(1)
expireat has the same effect and semantic as
RedisConnectionCommands.expire(java.lang.String, long)
, but instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp (seconds since January 1, 1970).- Specified by:
expireat
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to expire.timestamp
- the timestamp in from-Epoch milliseconds.- Returns:
- true if set, false if not set.
-
keys
public String[] keys(String pattern)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/keys:
Available since 1.0.0.
Time complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.
Returns all keys matching
pattern
.- Specified by:
keys
in interfaceRedisConnectionCommands
- Parameters:
pattern
- a wildcard pattern for matching key names.- Returns:
- a list of keys matching
pattern
.
-
move
public boolean move(String key, long db)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/move:
Available since 1.0.0.
Time complexity: O(1)
Move
key
from the currently selected database to the specified destination database. Whenkey
already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.- Specified by:
move
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to move.db
- the target database.- Returns:
- true if the key was moved, false if not.
-
persist
public boolean persist(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/persist:
Available since 2.2.0.
Time complexity: O(1)
Remove the existing timeout on
key
, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).- Specified by:
persist
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to persist (remove TTL).- Returns:
- true if successful, false if not.
-
pexpire
public boolean pexpire(String key, long milliseconds)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/pexpire:
Available since 2.6.0.
Time complexity: O(1)
This command works exactly like
RedisConnectionCommands.expire(java.lang.String, long)
but the time to live of the key is specified in milliseconds instead of seconds.- Specified by:
pexpire
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to expire.milliseconds
- the time-to-live in milliseconds.- Returns:
- true if successful, false if not.
-
pexpireat
public boolean pexpireat(String key, long timestamp)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/pexpireat:
Available since 2.6.0.
Time complexity: O(1)
PEXPIREAT has the same effect and semantic as
RedisConnectionCommands.expireat(java.lang.String, long)
, but the Unix time at which the key will expire is specified in milliseconds instead of seconds.- Specified by:
pexpireat
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to expire.timestamp
- the timestamp in from-Epoch milliseconds.- Returns:
- true if successful, false if not.
-
pttl
public long pttl(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/pttl:
Available since 2.6.0.
Time complexity: O(1)
Like
RedisConnectionCommands.ttl(java.lang.String)
, this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.- Specified by:
pttl
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to inspect.- Returns:
- TTL in milliseconds, or a negative value in order to signal an error (see the description above).
-
publish
public long publish(String channel, String message)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/publish:
Available since 2.0.0.
Time complexity: O(N+M) where N is the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).
Posts a message to the given channel.
- Specified by:
publish
in interfaceRedisConnectionCommands
- Returns:
- the number of clients that received the message.
-
randomkey
public String randomkey()
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/randomkey:
Available since 1.0.0.
Time complexity: O(1)
Return a random key from the currently selected database.
- Specified by:
randomkey
in interfaceRedisConnectionCommands
- Returns:
- the random key, or
null
when the database is empty.
-
rename
public boolean rename(String key, String newkey)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/rename:
Available since 1.0.0.
Time complexity: O(1)
Renames
key
tonewkey
. It returns an error when the source and destination names are the same, or whenkey
does not exist. Ifnewkey
already exists it is overwritten, when this happensRedisConnectionCommands.rename(java.lang.String, java.lang.String)
executes an implicitRedisConnectionCommands.del(java.lang.String, java.lang.String...)
operation, so if the deleted key contains a very big value it may cause high latency even ifRedisConnectionCommands.rename(java.lang.String, java.lang.String)
itself is usually a constant-time operation.- Specified by:
rename
in interfaceRedisConnectionCommands
- Parameters:
key
- the old name.newkey
- the new name.- Returns:
- always true.
-
renamenx
public boolean renamenx(String key, String newkey)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/renamenx:
Available since 1.0.0.
Time complexity: O(1)
Renames
key
tonewkey
ifnewkey
does not yet exist. It returns an error under the same conditions asRedisConnectionCommands.rename(java.lang.String, java.lang.String)
.- Specified by:
renamenx
in interfaceRedisConnectionCommands
- Parameters:
key
- the old name.newkey
- the new name.- Returns:
- true if successful, false if not.
-
restore
public boolean restore(String key, long ttl, String serializedvalue)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/restore:
Available since 2.6.0.
Time complexity: O(1) to create the new key and additional O(N*M) to reconstruct the serialized value, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1). However for sorted set values the complexity is O(N*M*log(N)) because inserting values into sorted sets is O(log(N)).
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via
RedisConnectionCommands.dump(java.lang.String)
).- Specified by:
restore
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to restore.ttl
- the time-to-live in milliseconds.serializedvalue
- the serialized value (from aRedisConnectionCommands.dump(java.lang.String)
call).- Returns:
- always true.
-
scan
public RedisCursor scan(long cursor)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/scan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
Incrementally iterates over a collection of elements.
- Specified by:
scan
in interfaceRedisScanCommands
- Parameters:
cursor
- the cursor value.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
scan
public RedisCursor scan(long cursor, String pattern)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/scan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
Incrementally iterates over a collection of elements.
- Specified by:
scan
in interfaceRedisScanCommands
- Parameters:
cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
scan
public RedisCursor scan(long cursor, long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/scan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
Incrementally iterates over a collection of elements.
- Specified by:
scan
in interfaceRedisScanCommands
- Parameters:
cursor
- the cursor value.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
scan
public RedisCursor scan(long cursor, String pattern, Long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/scan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
Incrementally iterates over a collection of elements.
- Specified by:
scan
in interfaceRedisScanCommands
- Parameters:
cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
sort
public String[] sort(String key, String pattern, SortOrder sortOrder, boolean alpha, Long limitOffset, Long limitCount, String storeKey, String... getPatterns)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sort:
Available since 1.0.0.
Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is currently O(N) as there is a copy step that will be avoided in next releases.
Returns or stores the elements contained in the list, set, or sorted set at
key
. By default, sorting is numeric and elements are compared by their value interpreted as double precision floating point number.- Specified by:
sort
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to sort the contents of.pattern
- if not null,sortOrder
- if true, sort descending. if false or null, sort ascending.alpha
- if true, sort lexicographically, not by a score.limitOffset
- if not null, the starting offset into the list (0-based).limitCount
- if not null, the amount of objects from the offset to sort. else, return all the way to the end.storeKey
- if not null, this is the key to store the result in.getPatterns
- the patterns for finding the sort score.- Returns:
- the list of sorted elements.
-
ttl
public long ttl(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/ttl:
Available since 1.0.0.
Time complexity: O(1)
Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset.
- Specified by:
ttl
in interfaceRedisConnectionCommands
- Parameters:
key
- the key to inspect.- Returns:
- TTL in seconds, or a negative value in order to signal an error (see description).
-
type
public DataType type(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/type:
Available since 1.0.0.
Time complexity: O(1)
Returns the string representation of the type of the value stored at
key
.- Specified by:
type
in interfaceRedisConnectionCommands
- Returns:
- the type of
key
, orDataType.NONE
whenkey
does not exist.
-
append
public long append(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/append:
Available since 2.0.0.
Time complexity: O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation.
If
key
already exists and is a string, this command appends thevalue
at the end of the string. Ifkey
does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.- Specified by:
append
in interfaceRedisConnectionCommands
- Returns:
- the length of the string after the append operation.
-
bitcount
public long bitcount(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/bitcount:
Available since 2.6.0.
Time complexity: O(N)
Count the number of set bits (population counting) in a string.
- Specified by:
bitcount
in interfaceRedisConnectionCommands
- Returns:
- the count.
-
bitcount
public long bitcount(String key, long start, long end)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/bitcount:
Available since 2.6.0.
Time complexity: O(N)
Count the number of set bits (population counting) in a string between a start and end bit.
- Specified by:
bitcount
in interfaceRedisConnectionCommands
- Returns:
- the count.
-
bitop
public long bitop(BitwiseOperation operation, String destkey, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/bitop:
Available since 2.6.0.
Time complexity: O(N)
Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.
- Specified by:
bitop
in interfaceRedisConnectionCommands
- Returns:
- the size of the string stored in the destination key, equal to the size of the longest input string.
-
bitpos
public long bitpos(String key, long bit)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/bitpos:
Available since 2.8.7.
Time complexity: O(N)
Return the position of the first bit set to 1 or 0 in a string.
- Specified by:
bitpos
in interfaceRedisConnectionCommands
- Returns:
- the command returns the position of the first bit set to 1 or 0 according to the request.
-
bitpos
public long bitpos(String key, long bit, Long start, Long end)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/bitpos:
Available since 2.8.7.
Time complexity: O(N)
Return the position of the first bit set to 1 or 0 in a string.
- Specified by:
bitpos
in interfaceRedisConnectionCommands
- Returns:
- the command returns the position of the first bit set to 1 or 0 according to the request.
-
decr
public long decr(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/decr:
Available since 1.0.0.
Time complexity: O(1)
Decrements the number stored at
key
by one. If the key does not exist, it is set to0
before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.- Specified by:
decr
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
after the decrement.
-
decrby
public long decrby(String key, long decrement)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/decrby:
Available since 1.0.0.
Time complexity: O(1)
Decrements the number stored at
key
bydecrement
. If the key does not exist, it is set to0
before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.- Specified by:
decrby
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
after the decrement.
-
get
public String get(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/get:
Available since 1.0.0.
Time complexity: O(1)
Get the value of
key
. If the key does not exist the special valuenull
is returned. An error is returned if the value stored atkey
is not a string, because GET only handles string values.- Specified by:
get
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
, ornull
whenkey
does not exist.
-
getLong
public Long getLong(String key)
Just likeget(String)
, but it casts the result to a long integer.- Parameters:
key
- the data key.- Returns:
-
getbit
public long getbit(String key, long offset)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/getbit:
Available since 2.2.0.
Time complexity: O(1)
Returns the bit value at offset in the string value stored at key.
- Specified by:
getbit
in interfaceRedisConnectionCommands
- Returns:
- the bit value stored at offset.
-
getrange
public String getrange(String key, long start, long end)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/getrange:
Available since 2.4.0.
Time complexity: O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings. it is called
SUBSTR
in Redis versions<= 2.0
.- Specified by:
getrange
in interfaceRedisConnectionCommands
- Returns:
- the resultant substring.
-
getset
public String getset(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/getset:
Available since 1.0.0.
Time complexity: O(1)
Atomically sets
key
tovalue
and returns the old value stored atkey
. Returns an error whenkey
exists but does not hold a string value.- Specified by:
getset
in interfaceRedisConnectionCommands
- Returns:
- the old value stored at
key
, ornull
whenkey
did not exist.
-
getset
public String getset(String key, Number value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/getset:
Available since 1.0.0.
Time complexity: O(1)
Atomically sets
key
tovalue
and returns the old value stored atkey
. Returns an error whenkey
exists but does not hold a string value.- Specified by:
getset
in interfaceRedisConnectionCommands
- Returns:
- the old value stored at
key
, ornull
whenkey
did not exist.
-
getsetLong
public Long getsetLong(String key, String value)
Just likegetset(String, String)
, but it casts the result to a long integer.- Parameters:
key
- th@param key the data key.value
-- Returns:
- the previous value.
-
getsetLong
public Long getsetLong(String key, Number value)
Just likegetset(String, String)
, but it casts the result to a long integer.- Parameters:
key
- the data key.value
-- Returns:
- the previous value.
-
incr
public long incr(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/incr:
Available since 1.0.0.
Time complexity: O(1)
Increments the number stored at
key
by one. If the key does not exist, it is set to0
before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.- Specified by:
incr
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
after the increment,
-
incrby
public long incrby(String key, long increment)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/incrby:
Available since 1.0.0.
Time complexity: O(1)
Increments the number stored at
key
byincrement
. If the key does not exist, it is set to0
before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.- Specified by:
incrby
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
after the increment.
-
incrbyfloat
public double incrbyfloat(String key, double increment)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/incrbyfloat:
Available since 2.6.0.
Time complexity: O(1)
Increment the string representing a floating point number stored at
key
by the specifiedincrement
. If the key does not exist, it is set to0
before performing the operation. An error is returned if one of the following conditions occur:- Specified by:
incrbyfloat
in interfaceRedisConnectionCommands
- Returns:
- the value of
key
after the increment.
-
mget
public String[] mget(String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/mget:
Available since 1.0.0.
Time complexity: O(N) where N is the number of keys to retrieve.
Returns the values of all specified keys. For every key that does not hold a string value or does not exist, the special value
nil
is returned. Because of this, the operation never fails.- Specified by:
mget
in interfaceRedisConnectionCommands
- Returns:
- list of values at the specified keys.
-
mset
public boolean mset(String key, String value, String... keyValues)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/mset:
Available since 1.0.1.
Time complexity: O(N) where N is the number of keys to set.
Sets the given keys to their respective values.
MSET
replaces existing values with new values, just as regular SET. SeeRedisConnectionCommands.msetnx(java.lang.String, java.lang.String, java.lang.String...)
if you don't want to overwrite existing values.- Specified by:
mset
in interfaceRedisConnectionCommands
- Returns:
- true, always.
-
mset
public boolean mset(KeyValue<String,Object>... pairs)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.mset(String, String, String...)
, but takes key-value pairs.- Specified by:
mset
in interfaceRedisConnectionCommands
-
msetnx
public boolean msetnx(String key, String value, String... keyValues)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/msetnx:
Available since 1.0.1.
Time complexity: O(N) where N is the number of keys to set.
Sets the given keys to their respective values.
MSETNX
will not perform any operation at all even if just a single key already exists.- Specified by:
msetnx
in interfaceRedisConnectionCommands
- Returns:
- true if all of the keys were set, false if no key was set.
-
msetnx
public boolean msetnx(KeyValue<String,Object>... pairs)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.msetnx(String, String, String...)
, but takes key-value pairs.- Specified by:
msetnx
in interfaceRedisConnectionCommands
-
psetex
public boolean psetex(String key, long milliseconds, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/psetex:
Available since 2.6.0.
Time complexity: O(1)
PSETEX
works exactly likeRedisConnectionCommands.setex(String, long, String)
with the sole difference that the expire time is specified in milliseconds instead of seconds.- Specified by:
psetex
in interfaceRedisConnectionCommands
- Returns:
- true, always.
-
set
public boolean set(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/set:
Available since 1.0.0.
Time complexity: O(1)
Set
key
to hold the stringvalue
. Ifkey
already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successfulSET
operation.- Specified by:
set
in interfaceRedisConnectionCommands
- Returns:
- true, always.
-
set
public boolean set(String key, Number value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/set:
Available since 1.0.0.
Time complexity: O(1)
Set
key
to hold the stringvalue
. Ifkey
already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successfulSET
operation.- Specified by:
set
in interfaceRedisConnectionCommands
- Returns:
- true, always.
-
setbit
public long setbit(String key, long offset, long value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/setbit:
Available since 2.2.0.
Time complexity: O(1)
Sets or clears the bit at offset in the string value stored at key.
- Specified by:
setbit
in interfaceRedisConnectionCommands
- Returns:
- the original bit value stored at offset.
-
setex
public boolean setex(String key, long seconds, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/setex:
Available since 2.0.0.
Time complexity: O(1)
Set
key
to hold the stringvalue
and setkey
to timeout after a given number of seconds. This command is equivalent to executing the following commands:- Specified by:
setex
in interfaceRedisConnectionCommands
- Returns:
- true, always.
-
setnx
public boolean setnx(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/setnx:
Available since 1.0.0.
Time complexity: O(1)
Set
key
to hold stringvalue
ifkey
does not exist. In that case, it is equal toRedisConnectionCommands.set(String, String)
. Whenkey
already holds a value, no operation is performed.SETNX
is short for "SET if N ot e X ists".- Specified by:
setnx
in interfaceRedisConnectionCommands
- Returns:
- true if the key was set, false if not.
-
setrange
public long setrange(String key, long offset, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/setrange:
Available since 2.2.0.
Time complexity: O(1), not counting the time taken to copy the new string in place. Usually, this string is very small so the amortized complexity is O(1). Otherwise, complexity is O(M) with M being the length of the value argument.
Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. Non-existing keys are considered as empty strings, so this command will make sure it holds a string large enough to be able to set value at offset.
- Specified by:
setrange
in interfaceRedisConnectionCommands
- Returns:
- the length of the string after it was modified by the command.
-
strlen
public long strlen(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/strlen:
Available since 2.2.0.
Time complexity: O(1)
Returns the length of the string value stored at
key
. An error is returned whenkey
holds a non-string value.- Specified by:
strlen
in interfaceRedisConnectionCommands
- Returns:
- the length of the string at
key
, or0
whenkey
does not exist.
-
hdel
public long hdel(String key, String field, String... fields)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hdel:
Available since 2.0.0.
Time complexity: O(N) where N is the number of fields to be removed.
Removes the specified fields from the hash stored at
key
. Specified fields that do not exist within this hash are ignored. Ifkey
does not exist, it is treated as an empty hash and this command returns0
.- Specified by:
hdel
in interfaceRedisConnectionCommands
- Returns:
- the number of fields that were removed from the hash, not including specified but non existing fields.
-
hexists
public boolean hexists(String key, String field)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hexists:
Available since 2.0.0.
Time complexity: O(1)
Returns if
field
is an existing field in the hash stored atkey
.- Specified by:
hexists
in interfaceRedisConnectionCommands
- Returns:
- true if successful, false if not.
-
hget
public String hget(String key, String field)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hget:
Available since 2.0.0.
Time complexity: O(1)
Returns the value associated with
field
in the hash stored atkey
.- Specified by:
hget
in interfaceRedisConnectionCommands
- Returns:
- the value associated with
field
, ornull
whenfield
is not present in the hash orkey
does not exist.
-
hgetLong
public Long hgetLong(String key, String field)
Just likehget(String, String)
, but it casts the result to a long integer.- Parameters:
key
- the data key.field
-- Returns:
- the previous value.
-
hgetall
public String[] hgetall(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hgetall:
Available since 2.0.0.
Time complexity: O(N) where N is the size of the hash.
Returns all fields and values of the hash stored at
key
. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.- Specified by:
hgetall
in interfaceRedisConnectionCommands
- Returns:
- a list of fields and their values stored in the hash, or an empty
list when
key
does not exist.
-
hgetallMap
public HashMap<String,String> hgetallMap(String key)
Just likehgetall(String)
, except the keys and values are returned in a map of key to value.- Parameters:
key
- the data key.- Returns:
- the returned map.
-
hgetallObject
public <T> T hgetallObject(String key, Class<T> type)
Just likehgetall(String)
, except the keys and values are set on a new instance of a Java object via reflection. Fields/Setter Methods annotated withRedisIgnore
are ignored.- Type Parameters:
T
- the return type.- Parameters:
key
- the data key.type
- the class type to crate and return.- Returns:
- the returned object.
- Throws:
RuntimeException
- if instantiation cannot happen, either due to a non-existent constructor or a non-visible constructor.ClassCastException
- if a incoming type cannot be converted to a field value.
-
hgetallObject
public <T> void hgetallObject(String key, T object)
Just likehgetall(String)
, except the keys and values are set on an existing instance of a Java object via reflection. Fields/Setter Methods annotated withRedisIgnore
are ignored.- Type Parameters:
T
- the object type.- Parameters:
key
- the data key.object
- the object to store.- Throws:
RuntimeException
- if instantiation cannot happen, either due to a non-existent constructor or a non-visible constructor.ClassCastException
- if a incoming type cannot be converted to a field value.
-
hincrby
public long hincrby(String key, String field, long increment)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hincrby:
Available since 2.0.0.
Time complexity: O(1)
Increments the number stored at
field
in the hash stored atkey
byincrement
. Ifkey
does not exist, a new key holding a hash is created. Iffield
does not exist the value is set to0
before the operation is performed.- Specified by:
hincrby
in interfaceRedisConnectionCommands
- Returns:
- the value at
field
after the increment operation.
-
hincrbyfloat
public double hincrbyfloat(String key, String field, double increment)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hincrbyfloat:
Available since 2.6.0.
Time complexity: O(1)
Increment the specified
field
of an hash stored atkey
, and representing a floating point number, by the specifiedincrement
. If the field does not exist, it is set to0
before performing the operation.- Specified by:
hincrbyfloat
in interfaceRedisConnectionCommands
- Returns:
- the value of
field
after the increment.
-
hkeys
public String[] hkeys(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hkeys:
Available since 2.0.0.
Time complexity: O(N) where N is the size of the hash.
Returns all field names in the hash stored at
key
.- Specified by:
hkeys
in interfaceRedisConnectionCommands
- Returns:
- the list of fields in the hash, or an empty list when
key
does not exist.
-
hlen
public long hlen(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hlen:
Available since 2.0.0.
Time complexity: O(1)
Returns the number of fields contained in the hash stored at
key
.- Specified by:
hlen
in interfaceRedisConnectionCommands
- Returns:
- the number of fields in the hash, or
0
whenkey
does not exist.
-
hmget
public String[] hmget(String key, String field, String... fields)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hmget:
Available since 2.0.0.
Time complexity: O(N) where N is the number of fields being requested.
Returns the values associated with the specified
fields
in the hash stored atkey
.- Specified by:
hmget
in interfaceRedisConnectionCommands
- Returns:
- a list of values associated with the given fields, in the same order as they are requested.
-
hmset
public boolean hmset(String key, String field, String value, String... fieldvalues)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hmset:
Available since 2.0.0.
Time complexity: O(N) where N is the number of fields being set.
Sets the specified fields to their respective values in the hash stored at
key
. This command overwrites any existing fields in the hash. Ifkey
does not exist, a new key holding a hash is created.Parameters should alternate between field, value, field, value ...
- Specified by:
hmset
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
hmset
public boolean hmset(String key, Object field, Object value, Object... fieldvalues)
From http://redis.io/commands/hmset:
Available since 2.0.0.
Time complexity: O(N) where N is the number of fields being set.
Sets the specified fields to their respective values in the hash stored at
key
. This command overwrites any existing fields in the hash. Ifkey
does not exist, a new key holding a hash is created.Parameters should alternate between field, value, field, value ...
- Parameters:
key
- the key.field
- the first field.value
- the first value.fieldvalues
- the subsequent field-values for the hash.- Returns:
- always true.
-
hmset
public boolean hmset(String key, KeyValue<String,Object>... pairs)
Likehmset(String, String, String, String...)
, except abstracted asKeyValue
s of key-value pairs.- Specified by:
hmset
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
hmsetMap
public boolean hmsetMap(String key, Map<String,Object> map)
Likehmset(String, String, String, String...)
, except abstracted as a map of key-value pairs.- Parameters:
key
- the key.map
- the map of field-value pairs for the hash.- Returns:
- true.
-
hmsetObject
public <T> boolean hmsetObject(String key, T object)
Likehmset(String, String, String, String...)
, except each field or getter sets the fields and values. Fields/Getter Methods annotated withRedisIgnore
are ignored.- Type Parameters:
T
- the object type.- Parameters:
key
- the key.object
- the object to convert to a hash.- Returns:
- true.
-
hset
public boolean hset(String key, String field, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hset:
Available since 2.0.0.
Time complexity: O(1)
Sets
field
in the hash stored atkey
tovalue
. Ifkey
does not exist, a new key holding a hash is created. Iffield
already exists in the hash, it is overwritten.- Specified by:
hset
in interfaceRedisConnectionCommands
- Returns:
- true if a new field, false if set, but not a new field.
-
hset
public boolean hset(String key, String field, Number value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hset:
Available since 2.0.0.
Time complexity: O(1)
Sets
field
in the hash stored atkey
tovalue
. Ifkey
does not exist, a new key holding a hash is created. Iffield
already exists in the hash, it is overwritten.- Specified by:
hset
in interfaceRedisConnectionCommands
- Returns:
- true if a new field, false if set, but not a new field.
-
hsetnx
public boolean hsetnx(String key, String field, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hsetnx:
Available since 2.0.0.
Time complexity: O(1)
Sets
field
in the hash stored atkey
tovalue
, only iffield
does not yet exist. Ifkey
does not exist, a new key holding a hash is created. Iffield
already exists, this operation has no effect.- Specified by:
hsetnx
in interfaceRedisConnectionCommands
- Returns:
- true if a new field, false if set, but not a new field.
-
hsetnx
public boolean hsetnx(String key, String field, Number value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hsetnx:
Available since 2.0.0.
Time complexity: O(1)
Sets
field
in the hash stored atkey
tovalue
, only iffield
does not yet exist. Ifkey
does not exist, a new key holding a hash is created. Iffield
already exists, this operation has no effect.- Specified by:
hsetnx
in interfaceRedisConnectionCommands
- Returns:
- true if a new field, false if set, but not a new field.
-
hvals
public String[] hvals(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/hvals:
Available since 2.0.0.
Time complexity: O(N) where N is the size of the hash.
Returns all values in the hash stored at
key
.- Specified by:
hvals
in interfaceRedisConnectionCommands
- Returns:
- a list of values in the hash, or an empty list when
key
does not exist.
-
hscan
public RedisCursor hscan(String key, long cursor)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/sscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
hscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the hash to scan.cursor
- the cursor value.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
hscan
public RedisCursor hscan(String key, long cursor, String pattern)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/sscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
hscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the hash to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
hscan
public RedisCursor hscan(String key, long cursor, long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/sscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
hscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the hash to scan.cursor
- the cursor value.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
hscan
public RedisCursor hscan(String key, long cursor, String pattern, Long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/hscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
hscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the hash to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
pfadd
public boolean pfadd(String key, String element, String... elements)
Description copied from interface:RedisHyperlogCommands
From http://redis.io/commands/pfadd:
Available since 2.8.9.
Time complexity: O(1) to add every element.
Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.
- Specified by:
pfadd
in interfaceRedisHyperlogCommands
- Parameters:
key
- the hyperlog key.element
- the first element.elements
- the rest of the elements.- Returns:
- true if at least one internal register was altered, false otherwise.
-
pfcount
public long pfcount(String key, String... keys)
Description copied from interface:RedisHyperlogCommands
From http://redis.io/commands/pfcount:
Available since 2.8.9.
Time complexity: O(1).
Returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist.
- Specified by:
pfcount
in interfaceRedisHyperlogCommands
- Parameters:
key
- the first key.keys
- the rest of the keys.- Returns:
- the number of unique elements observed via
RedisHyperlogCommands.pfadd(String, String, String...)
.
-
pfmerge
public boolean pfmerge(String destkey, String sourcekey, String... sourcekeys)
Description copied from interface:RedisHyperlogCommands
From http://redis.io/commands/pfmerge:
Available since 2.8.9.
Time complexity: O(N) to merge N HyperLogLogs, but with high constant times.
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
- Specified by:
pfmerge
in interfaceRedisHyperlogCommands
- Parameters:
destkey
- the destination key.sourcekey
- the first key.sourcekeys
- the rest of the keys.- Returns:
- always true.
-
blpop
public KeyValue<String,String> blpop(long timeout, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/blpop:
Available since 2.0.0.
Time complexity: O(1)
BLPOP
is a blocking list pop primitive. It is the blocking version ofRedisConnectionCommands.lpop(String)
because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given. Atimeout
of zero can be used to block indefinitely. Timeout is in seconds.- Specified by:
blpop
in interfaceRedisConnectionCommands
- Returns:
- an object pair consisting of popped list key and the value popped, or null on timeout.
-
blpopLong
public KeyValue<String,Long> blpopLong(long timeout, String key, String... keys)
Likeblpop(long, String, String...)
, except it casts the value to a long integer.- Parameters:
timeout
- the timeout in seconds.key
- the first key.keys
- the subsequent keys.- Returns:
- an object pair consisting of popped list key and the numeric value popped, or null on timeout.
-
brpop
public KeyValue<String,String> brpop(long timeout, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/brpop:
Available since 2.0.0.
Time complexity: O(1)
BRPOP
is a blocking list pop primitive. It is the blocking version ofRedisConnectionCommands.rpop(java.lang.String)
because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given. Atimeout
of zero can be used to block indefinitely. Timeout is in seconds.- Specified by:
brpop
in interfaceRedisConnectionCommands
- Returns:
- an object pair consisting of popped list key and the value popped, or null on timeout.
-
brpopLong
public KeyValue<String,Long> brpopLong(long timeout, String key, String... keys)
Likebrpop(long, String, String...)
, except it casts the value to a long integer.- Parameters:
timeout
- the timeout in seconds.key
- the first key.keys
- the subsequent keys.- Returns:
- an object pair consisting of popped list key and the numeric value popped, or null on timeout.
-
brpoplpush
public String brpoplpush(long timeout, String source, String destination)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/brpoplpush:
Available since 2.2.0.
Time complexity: O(1)
BRPOPLPUSH
is the blocking variant ofRedisConnectionCommands.rpoplpush(String, String)
. Whensource
contains elements, this command behaves exactly likeRedisConnectionCommands.rpoplpush(String, String)
. Whensource
is empty, Redis will block the connection until another client pushes to it or untiltimeout
is reached. Atimeout
of zero can be used to block indefinitely. Timeout is in seconds.- Specified by:
brpoplpush
in interfaceRedisConnectionCommands
- Returns:
- the value popped-then-pushed to destination from source, or null on timeout.
-
brpoplpushLong
public Long brpoplpushLong(long timeout, String source, String destination)
Likebrpoplpush(long, String, String)
, except it casts the value to a long integer.- Parameters:
timeout
- the timeout in seconds.source
- the source key.destination
- the destination key.- Returns:
- the value returned as a long.
-
lindex
public String lindex(String key, long index)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lindex:
Available since 1.0.0.
Time complexity: O(N) where N is the number of elements to traverse to get to the element at index. This makes asking for the first or the last element of the list O(1).
Returns the element at index
index
in the list stored atkey
. The index is zero-based, so0
means the first element,1
the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here,-1
means the last element,-2
means the penultimate and so forth.- Specified by:
lindex
in interfaceRedisConnectionCommands
- Returns:
- the requested element, or
null
whenindex
is out of range.
-
lindexLong
public Long lindexLong(String key, long index)
Likelindex(String, long)
, except it casts the value to a long integer.- Parameters:
key
- the key.index
- the list index.- Returns:
- the value returned as a long.
-
linsert
public long linsert(String key, boolean before, String pivot, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/linsert:
Available since 2.2.0.
Time complexity: O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).
Inserts
value
in the list stored atkey
either before or after the reference valuepivot
.- Specified by:
linsert
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the insert operation, or
-1
when the valuepivot
was not found.
-
linsert
public long linsert(String key, boolean before, String pivot, Number value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/linsert:
Available since 2.2.0.
Time complexity: O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).
Inserts
value
in the list stored atkey
either before or after the reference valuepivot
.- Specified by:
linsert
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the insert operation, or
-1
when the valuepivot
was not found.
-
llen
public long llen(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/llen:
Available since 1.0.0.
Time complexity: O(1)
Returns the length of the list stored at
key
. Ifkey
does not exist, it is interpreted as an empty list and0
is returned. An error is returned when the value stored atkey
is not a list.- Specified by:
llen
in interfaceRedisConnectionCommands
- Returns:
- the length of the list at
key
.
-
lpop
public String lpop(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lpop:
Available since 1.0.0.
Time complexity: O(1)
Removes and returns the first element of the list stored at
key
.- Specified by:
lpop
in interfaceRedisConnectionCommands
- Returns:
- the value of the first element, or
null
whenkey
does not exist.
-
lpopLong
public Long lpopLong(String key)
Likelpop(String)
, except it casts the value to a long integer.- Parameters:
key
- the key.- Returns:
- the value returned as a long.
-
lpush
public long lpush(String key, String value, String... values)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lpush:
Available since 1.0.0.
Time complexity: O(1)
Insert all the specified values at the head of the list stored at
key
. Ifkey
does not exist, it is created as empty list before performing the push operations. Whenkey
holds a value that is not a list, an error is returned.- Specified by:
lpush
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the push operations.
-
lpushx
public long lpushx(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lpushx:
Available since 2.2.0.
Time complexity: O(1)
Inserts
value
at the head of the list stored atkey
, only ifkey
already exists and holds a list. In contrary toRedisConnectionCommands.lpush(java.lang.String, java.lang.String, java.lang.String...)
, no operation will be performed whenkey
does not yet exist.- Specified by:
lpushx
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the push operation.
-
lrange
public String[] lrange(String key, long start, long stop)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lrange:
Available since 1.0.0.
Time complexity: O(S+N) where S is the start offset and N is the number of elements in the specified range.
Returns the specified elements of the list stored at
key
. The offsetsstart
andstop
are zero-based indexes, with0
being the first element of the list (the head of the list),1
being the next element and so on.- Specified by:
lrange
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified range.
-
lrem
public long lrem(String key, long count, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lrem:
Available since 1.0.0.
Time complexity: O(N) where N is the length of the list.
Removes the first
count
occurrences of elements equal tovalue
from the list stored atkey
. Thecount
argument influences the operation in the following ways:count > 0
: Remove elements equal tovalue
moving from head to tail.count < 0
: Remove elements equal tovalue
moving from tail to head.count = 0
: Remove all elements equal tovalue
.
- Specified by:
lrem
in interfaceRedisConnectionCommands
- Returns:
- the number of removed elements.
-
lset
public boolean lset(String key, long index, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/lset:
Available since 1.0.0.
Time complexity: O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1).
Sets the list element at
index
tovalue
. For more information on theindex
argument, seeRedisConnectionCommands.lindex(String, long)
.- Specified by:
lset
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
ltrim
public boolean ltrim(String key, long start, long stop)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/ltrim:
Available since 1.0.0.
Time complexity: O(N) where N is the number of elements to be removed by the operation.
Trim an existing list so that it will contain only the specified range of elements specified. Both
start
andstop
are zero-based indexes, where0
is the first element of the list (the head),1
the next element and so on.- Specified by:
ltrim
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
rpop
public String rpop(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/rpop:
Available since 1.0.0.
Time complexity: O(1)
Removes and returns the last element of the list stored at
key
.- Specified by:
rpop
in interfaceRedisConnectionCommands
- Returns:
- the value of the last element, or
null
whenkey
does not exist.
-
rpopLong
public Long rpopLong(String key)
Likerpop(String)
, except it casts the value to a long integer.- Parameters:
key
- the key.- Returns:
- the value returned as a long.
-
rpoplpush
public String rpoplpush(String source, String destination)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/rpoplpush:
Available since 1.2.0.
Time complexity: O(1)
Atomically returns and removes the last element (tail) of the list stored at
source
, and pushes the element at the first element (head) of the list stored atdestination
.- Specified by:
rpoplpush
in interfaceRedisConnectionCommands
- Returns:
- the element being popped and pushed.
-
rpoplpushLong
public Long rpoplpushLong(String source, String destination)
Likerpoplpush(String, String)
, except it casts the value to a long integer.- Parameters:
source
- the source key.destination
- the destination key.- Returns:
- the value returned as a long.
-
rpush
public long rpush(String key, String value, String... values)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/rpush:
Available since 1.0.0.
Time complexity: O(1)
Insert all the specified values at the tail of the list stored at
key
. Ifkey
does not exist, it is created as empty list before performing the push operation. Whenkey
holds a value that is not a list, an error is returned.- Specified by:
rpush
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the push operation.
-
rpushx
public long rpushx(String key, String value)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/rpushx:
Available since 2.2.0.
Time complexity: O(1)
Inserts
value
at the tail of the list stored atkey
, only ifkey
already exists and holds a list. In contrary toRedisConnectionCommands.rpush(java.lang.String, java.lang.String, java.lang.String...)
, no operation will be performed whenkey
does not yet exist.- Specified by:
rpushx
in interfaceRedisConnectionCommands
- Returns:
- the length of the list after the push operation.
-
eval
public RedisObject eval(String scriptContent, String[] keys, Object... args)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/eval:
Available since 2.6.0.
Time complexity: Depends on the script that is executed.
Evaluates a Lua script. The keys specified in
keys
should be used as a hint for Redis as to what keys are touched during the script call.- Specified by:
eval
in interfaceRedisConnectionCommands
- Returns:
- the content returned by the script. Can be null.
-
evalsha
public RedisObject evalsha(String hash, String[] keys, Object... args)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/evalsha:
Available since 2.6.0.
Time complexity: Depends on the script that is executed.
Evaluates a script cached on the server side by its SHA1 digest. Scripts are cached on the server side using the
RedisConnectionCommands.scriptLoad(java.lang.String)
command. The command is otherwise identical toRedisConnectionCommands.eval(String, String[], Object...)
.- Specified by:
evalsha
in interfaceRedisConnectionCommands
- Returns:
- the content returned by the script. Can be null.
-
scriptExists
public boolean[] scriptExists(String scriptHash, String... scriptHashes)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/script-exists:
Available since 2.6.0.
Time complexity: O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).
Returns information about the existence of the scripts in the script cache.
- Specified by:
scriptExists
in interfaceRedisConnectionCommands
- Returns:
- The command returns an array of booleans that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, true is returned, otherwise false is returned.
-
scriptFlush
public boolean scriptFlush()
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/script-flush:
Available since 2.6.0.
Time complexity: O(N) with N being the number of scripts in cache
Flush the Lua scripts cache.
- Specified by:
scriptFlush
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
scriptKill
public boolean scriptKill(String hash)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/script-kill:
Available since 2.6.0.
Time complexity: O(1)
Kills the currently executing Lua script, assuming no write operation was yet performed by the script.
- Specified by:
scriptKill
in interfaceRedisConnectionCommands
- Returns:
- always true.
-
scriptLoad
public String scriptLoad(String content)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/script-load:
Available since 2.6.0.
Time complexity: O(N) with N being the length in bytes of the script body.
Load a script into the scripts cache, without executing it. After the specified command is loaded into the script cache it will be callable using
RedisConnectionCommands.evalsha(String, String[], Object...)
with the correct SHA1 digest of the script, exactly like after the first successful invocation ofRedisConnectionCommands.eval(String, String[], Object...)
.- Specified by:
scriptLoad
in interfaceRedisConnectionCommands
- Returns:
- the SHA1 digest of the script added into the script cache.
-
scriptLoad
public String scriptLoad(File content) throws IOException
From http://redis.io/commands/script-load:
Available since 2.6.0.
Time complexity: O(N) with N being the length in bytes of the script body.
Load a script into the scripts cache from the specified file without executing it. After the specified command is loaded into the script cache it will be callable using
evalsha(String, String[], Object...)
with the correct SHA1 digest of the script, exactly like after the first successful invocation ofeval(String, String[], Object...)
.- Specified by:
scriptLoad
in interfaceRedisConnectionCommands
- Returns:
- the SHA1 digest of the script added into the script cache.
- Throws:
IOException
-
scriptLoad
public String scriptLoad(InputStream content) throws IOException
From http://redis.io/commands/script-load:
Available since 2.6.0.
Time complexity: O(N) with N being the length in bytes of the script body.
Load a script into the scripts cache from the specified input stream (until the end is reached) without executing it. The stream is not closed after read. After the specified command is loaded into the script cache it will be callable using
evalsha(String, String[], Object...)
with the correct SHA1 digest of the script, exactly like after the first successful invocation ofeval(String, String[], Object...)
.- Specified by:
scriptLoad
in interfaceRedisConnectionCommands
- Returns:
- the SHA1 digest of the script added into the script cache.
- Throws:
IOException
-
sadd
public long sadd(String key, String member, String... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sadd:
Available since 1.0.0.
Time complexity: O(N) where N is the number of members to be added.
Add the specified members to the set stored at
key
. Specified members that are already a member of this set are ignored. Ifkey
does not exist, a new set is created before adding the specified members.- Specified by:
sadd
in interfaceRedisConnectionCommands
- Returns:
- the number of elements that were added to the set, not including all the elements already present into the set.
-
sadd
public long sadd(String key, Object member, Object... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sadd:
Available since 1.0.0.
Time complexity: O(N) where N is the number of members to be added.
Add the specified members to the set stored at
key
. Specified members that are already a member of this set are ignored. Ifkey
does not exist, a new set is created before adding the specified members.- Specified by:
sadd
in interfaceRedisConnectionCommands
-
scard
public long scard(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/scard:
Available since 1.0.0.
Time complexity: O(1)
Returns the set cardinality (number of elements) of the set stored at
key
.- Specified by:
scard
in interfaceRedisConnectionCommands
- Returns:
- the cardinality (number of elements) of the set, or
0
ifkey
does not exist.
-
sdiff
public String[] sdiff(String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sdiff:
Available since 1.0.0.
Time complexity: O(N) where N is the total number of elements in all given sets.
Returns the members of the set resulting from the difference between the first set and all the successive sets.
- Specified by:
sdiff
in interfaceRedisConnectionCommands
- Returns:
- list with members of the resulting set.
-
sdiffstore
public long sdiffstore(String destination, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sdiffstore:
Available since 1.0.0.
Time complexity: O(N) where N is the total number of elements in all given sets.
This command is equal to SDIFF, but instead of returning the resulting set, it is stored in
destination
.- Specified by:
sdiffstore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the resulting set.
-
sinter
public String[] sinter(String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sinter:
Available since 1.0.0.
Time complexity: O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.
Returns the members of the set resulting from the intersection of all the given sets.
- Specified by:
sinter
in interfaceRedisConnectionCommands
- Returns:
- list with members of the resulting set.
-
sinterstore
public long sinterstore(String destination, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sinterstore:
Available since 1.0.0.
Time complexity: O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.
This command is equal to SINTER, but instead of returning the resulting set, it is stored in
destination
.- Specified by:
sinterstore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the resulting set.
-
sismember
public boolean sismember(String key, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sismember:
Available since 1.0.0.
Time complexity: O(1)
Returns if
member
is a member of the set stored atkey
.- Specified by:
sismember
in interfaceRedisConnectionCommands
- Returns:
- true if the member is in the set, or false if not.
-
sismember
public boolean sismember(String key, Number member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sismember:
Available since 1.0.0.
Time complexity: O(1)
Returns if
member
is a member of the set stored atkey
.- Specified by:
sismember
in interfaceRedisConnectionCommands
- Returns:
- true if the member is in the set, or false if not.
-
smembers
public String[] smembers(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/smembers:
Available since 1.0.0.
Time complexity: O(N) where N is the set cardinality.
Returns all the members of the set value stored at
key
.- Specified by:
smembers
in interfaceRedisConnectionCommands
- Returns:
- all elements of the set.
-
smove
public boolean smove(String source, String destination, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/smove:
Available since 1.0.0.
Time complexity: O(1)
Move
member
from the set atsource
to the set atdestination
. This operation is atomic. In every given moment the element will appear to be a member ofsource
ordestination
for other clients.- Specified by:
smove
in interfaceRedisConnectionCommands
- Returns:
- true if the move of the member is successful, or false if the source list did not contain the member to move.
-
spop
public String spop(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/spop:
Available since 1.0.0.
Time complexity: O(1)
Removes and returns a random element from the set value stored at
key
.- Specified by:
spop
in interfaceRedisConnectionCommands
- Returns:
- the removed element, or
null
whenkey
does not exist.
-
spopLong
public Long spopLong(String key)
Likespop(String)
, except it casts the value to a long integer.- Parameters:
key
- the key.- Returns:
- the value returned as a long.
-
srandmember
public String srandmember(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/srandmember:
Available since 1.0.0.
Time complexity: O(1).
When called with just the
key
argument, return a random element from the set value stored atkey
.- Specified by:
srandmember
in interfaceRedisConnectionCommands
- Returns:
- the randomly selected element, or
null
whenkey
does not exist.
-
srandmember
public String[] srandmember(String key, long count)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/srandmember:
Available since 1.0.0.
Time complexity: O(N) where N is the absolute value of the passed count.
When called with just the
key
argument, return a random element from the set value stored atkey
.- Specified by:
srandmember
in interfaceRedisConnectionCommands
- Returns:
- an array of elements, or an empty array when
key
does not exist.
-
srem
public long srem(String key, String member, String... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/srem:
Available since 1.0.0.
Time complexity: O(N) where N is the number of members to be removed.
Remove the specified members from the set stored at
key
. Specified members that are not a member of this set are ignored. Ifkey
does not exist, it is treated as an empty set and this command returns0
.- Specified by:
srem
in interfaceRedisConnectionCommands
- Returns:
- the number of members that were removed from the set, not including non existing members.
-
srem
public long srem(String key, Object member, Object... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/srem:
Available since 1.0.0.
Time complexity: O(N) where N is the number of members to be removed.
Remove the specified members from the set stored at
key
. Specified members that are not a member of this set are ignored. Ifkey
does not exist, it is treated as an empty set and this command returns0
.- Specified by:
srem
in interfaceRedisConnectionCommands
- Returns:
- the number of members that were removed from the set, not including non existing members.
-
sunion
public String[] sunion(String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sunion:
Available since 1.0.0.
Time complexity: O(N) where N is the total number of elements in all given sets.
Returns the members of the set resulting from the union of all the given sets.
- Specified by:
sunion
in interfaceRedisConnectionCommands
- Returns:
- list with members of the resulting set.
-
sunionstore
public long sunionstore(String destination, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/sunionstore:
Available since 1.0.0.
Time complexity: O(N) where N is the total number of elements in all given sets.
This command is equal to SUNION, but instead of returning the resulting set, it is stored in
destination
.- Specified by:
sunionstore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the resulting set.
-
sscan
public RedisCursor sscan(String key, long cursor)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/hscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
sscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the set to scan.cursor
- the cursor value.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
sscan
public RedisCursor sscan(String key, long cursor, String pattern)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/hscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
sscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the set to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
sscan
public RedisCursor sscan(String key, long cursor, long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/hscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
sscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the set to scan.cursor
- the cursor value.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
sscan
public RedisCursor sscan(String key, String cursor, String pattern, Long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/sscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
sscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the set to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
zadd
public long zadd(String key, double score, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zadd:
Available since 1.2.0.
Time complexity: O(log(N)) where N is the number of elements in the sorted set.
Adds all the specified members with the specified scores to the sorted set stored at
key
. It is possible to specify multiple score/member pairs. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering. Ifkey
does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.- Specified by:
zadd
in interfaceRedisConnectionCommands
- Returns:
- the number of elements added to the sorted sets, not including elements already existing for which the score was updated.
-
zadd
public long zadd(String key, double score, Number member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zadd:
Available since 1.2.0.
Time complexity: O(log(N)) where N is the number of elements in the sorted set.
Adds all the specified members with the specified scores to the sorted set stored at
key
. It is possible to specify multiple score/member pairs. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering. Ifkey
does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.- Specified by:
zadd
in interfaceRedisConnectionCommands
-
zadd
public long zadd(String key, KeyValue<Double,String>... pairs)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zadd:
Available since 1.2.0.
Time complexity: O(log(N)) where N is the number of elements in the sorted set.
Adds all the specified members with the specified scores to the sorted set stored at
key
. It is possible to specify multiple score/member pairs. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering. Ifkey
does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.- Specified by:
zadd
in interfaceRedisConnectionCommands
- Returns:
- the number of elements added to the sorted sets, not including elements already existing for which the score was updated.
-
zcard
public long zcard(String key)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zcard:
Available since 1.2.0.
Time complexity: O(1)
Returns the sorted set cardinality (number of elements) of the sorted set stored at
key
.- Specified by:
zcard
in interfaceRedisConnectionCommands
- Returns:
- the cardinality (number of elements) of the sorted set, or
0
ifkey
does not exist.
-
zcount
public long zcount(String key, String min, String max)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zcount:
Available since 2.0.0.
Time complexity: O(log(N)) with N being the number of elements in the sorted set.
Returns the number of elements in the sorted set at
key
with a score betweenmin
andmax
.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zcount
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the specified score range.
-
zcount
public long zcount(String key, double min, double max)
Likezcount(String, String, String)
, except it accepts doubles for min and max, not strings.- Specified by:
zcount
in interfaceRedisConnectionCommands
-
zincrby
public double zincrby(String key, double increment, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zincrby:
Available since 1.2.0.
Time complexity: O(log(N)) where N is the number of elements in the sorted set.
Increments the score of
member
in the sorted set stored atkey
byincrement
. Ifmember
does not exist in the sorted set, it is added withincrement
as its score (as if its previous score was0.0
). Ifkey
does not exist, a new sorted set with the specifiedmember
as its sole member is created.- Specified by:
zincrby
in interfaceRedisConnectionCommands
- Returns:
- the new score of
member
(a double precision floating point number).
-
zrange
public String[] zrange(String key, long start, long stop, boolean withScores)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrange:
Available since 1.2.0.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
Returns the specified range of elements in the sorted set stored at
key
. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score.- Specified by:
zrange
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified range (optionally with their scores).
-
zrangebyscore
public String[] zrangebyscore(String key, String min, String max, boolean withScores, Long limitOffset, Long limitCount)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrangebyscore:
Available since 1.0.5.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
Returns all the elements in the sorted set at
key
with a score betweenmin
andmax
(including elements with score equal tomin
ormax
). The elements are considered to be ordered from low to high scores.The optional
LIMIT
argument can be used to only get a range of the matching elements (similar to SELECT LIMIT offset, count in SQL). Keep in mind that ifoffset
is large, the sorted set needs to be traversed foroffset
elements before getting to the elements to return, which can add up to O(N) time complexity.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zrangebyscore
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified score range (optionally with their scores).
-
zrangebyscore
public String[] zrangebyscore(String key, double min, double max, boolean withScores)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean)
, except it accepts doubles for min and max, not strings.- Specified by:
zrangebyscore
in interfaceRedisConnectionCommands
-
zrangebyscore
public String[] zrangebyscore(String key, String min, String max, boolean withScores)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean, Long, Long)
, except specifies no limit.- Specified by:
zrangebyscore
in interfaceRedisConnectionCommands
-
zrangebyscore
public String[] zrangebyscore(String key, double min, double max, boolean withScores, Long limitOffset, Long limitCount)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrangebyscore(String, String, String, boolean, Long, Long)
, except it accepts doubles for min and max, not strings.- Specified by:
zrangebyscore
in interfaceRedisConnectionCommands
-
zrank
public Long zrank(String key, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrank:
Available since 2.0.0.
Time complexity: O(log(N))
Returns the rank of
member
in the sorted set stored atkey
, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank0
.- Specified by:
zrank
in interfaceRedisConnectionCommands
- Returns:
- If
member
exists in the sorted set, the rank ofmember
. Ifmember
does not exist in the sorted set orkey
does not exist,null
.
-
zrank
public Long zrank(String key, Number member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrank:
Available since 2.0.0.
Time complexity: O(log(N))
Returns the rank of
member
in the sorted set stored atkey
, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank0
.- Specified by:
zrank
in interfaceRedisConnectionCommands
- Returns:
- If
member
exists in the sorted set, the rank ofmember
. Ifmember
does not exist in the sorted set orkey
does not exist,null
.
-
zrem
public long zrem(String key, String member, String... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrem:
Available since 1.2.0.
Time complexity: O(M*log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.
Removes the specified members from the sorted set stored at
key
. Non existing members are ignored.- Specified by:
zrem
in interfaceRedisConnectionCommands
- Returns:
- the number of members removed from the sorted set, not including non existing members.
-
zrem
public long zrem(String key, Number member, Number... members)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrem:
Available since 1.2.0.
Time complexity: O(M*log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.
Removes the specified members from the sorted set stored at
key
. Non existing members are ignored.- Specified by:
zrem
in interfaceRedisConnectionCommands
- Returns:
- the number of members removed from the sorted set, not including non existing members.
-
zremrangebyrank
public long zremrangebyrank(String key, long start, long stop)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zremrangebyrank:
Available since 2.0.0.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
Removes all elements in the sorted set stored at
key
with rank betweenstart
andstop
. Bothstart
andstop
are0
-based indexes with0
being the element with the lowest score. These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score. For example:-1
is the element with the highest score,-2
the element with the second highest score and so forth.- Specified by:
zremrangebyrank
in interfaceRedisConnectionCommands
- Returns:
- the number of elements removed.
-
zremrangebyscore
public long zremrangebyscore(String key, String min, String max)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zremrangebyscore:
Available since 1.2.0.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
Removes all elements in the sorted set stored at
key
with a score betweenmin
andmax
(inclusive).The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zremrangebyscore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements removed.
-
zremrangebyscore
public long zremrangebyscore(String key, double min, double max)
Likezremrangebyscore(String, String, String)
, except it accepts doubles for min and max, not strings.- Specified by:
zremrangebyscore
in interfaceRedisConnectionCommands
-
zrevrank
public Long zrevrank(String key, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrevrank:
Available since 2.0.0.
Time complexity: O(log(N))
Returns the rank of
member
in the sorted set stored atkey
, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank0
.- Specified by:
zrevrank
in interfaceRedisConnectionCommands
- Returns:
- If
member
exists in the sorted set, the rank ofmember
. Ifmember
does not exist in the sorted set orkey
does not exist,null
.
-
zrevrange
public String[] zrevrange(String key, long start, long stop, boolean withScores)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrevrange:
Available since 1.2.0.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
Returns the specified range of elements in the sorted set stored at
key
. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.- Specified by:
zrevrange
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified range (optionally with their scores).
-
zrevrangebyscore
public String[] zrevrangebyscore(String key, String min, String max, boolean withScores, Long limitOffset, Long limitCount)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrevrangebyscore:
Available since 2.2.0.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
Returns all the elements in the sorted set at key with a score between
max
andmin
(including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.The optional
LIMIT
argument can be used to only get a range of the matching elements (similar to SELECT LIMIT offset, count in SQL). Keep in mind that ifoffset
is large, the sorted set needs to be traversed foroffset
elements before getting to the elements to return, which can add up to O(N) time complexity.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zrevrangebyscore
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified score range (optionally with their scores).
-
zrevrangebyscore
public String[] zrevrangebyscore(String key, double min, double max, boolean withScores)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean)
, except it accepts doubles for min and max, not strings.- Specified by:
zrevrangebyscore
in interfaceRedisConnectionCommands
-
zrevrangebyscore
public String[] zrevrangebyscore(String key, String min, String max, boolean withScores)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean, Long, Long)
, except specifies no limit.- Specified by:
zrevrangebyscore
in interfaceRedisConnectionCommands
-
zrevrangebyscore
public String[] zrevrangebyscore(String key, double min, double max, boolean withScores, Long limitOffset, Long limitCount)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrevrangebyscore(String, String, String, boolean, Long, Long)
, except it accepts doubles for min and max, not strings.- Specified by:
zrevrangebyscore
in interfaceRedisConnectionCommands
-
zscore
public Double zscore(String key, String member)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zscore:
Available since 1.2.0.
Time complexity: O(1)
Returns the score of
member
in the sorted set atkey
.- Specified by:
zscore
in interfaceRedisConnectionCommands
- Returns:
- the score of
member
(a double precision floating point number).
-
zinterstore
public long zinterstore(String destination, double[] weights, Aggregation aggregation, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zinterstore:
Available since 2.0.0.
Time complexity: O(N*K)+O(M*log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
Computes the intersection of
numkeys
sorted sets given by the specified keys, and stores the result indestination
. It is mandatory to provide the number of input keys (numkeys
) before passing the input keys and the other (optional) arguments.- Specified by:
zinterstore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the resulting sorted set at
destination
.
-
zinterstore
public long zinterstore(String destination, Aggregation aggregation, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores.Equivalent to:
zinterstore(destination, null, aggregation, key, keys)
- Specified by:
zinterstore
in interfaceRedisConnectionCommands
-
zinterstore
public long zinterstore(String destination, double[] weights, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except it does no aggregation of scores.Equivalent to:
zinterstore(destination, weights, null, key, keys)
- Specified by:
zinterstore
in interfaceRedisConnectionCommands
-
zinterstore
public long zinterstore(String destination, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zinterstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores, and does no aggregation of scores.Equivalent to:
zinterstore(destination, null, null, key, keys)
- Specified by:
zinterstore
in interfaceRedisConnectionCommands
-
zunionstore
public long zunionstore(String destination, double[] weights, Aggregation aggregation, String key, String... keys)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zunionstore:
Available since 2.0.0.
Time complexity: O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.
Computes the union of
numkeys
sorted sets given by the specified keys, and stores the result indestination
. It is mandatory to provide the number of input keys (numkeys
) before passing the input keys and the other (optional) arguments.- Specified by:
zunionstore
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the resulting sorted set at
destination
.
-
zunionstore
public long zunionstore(String destination, Aggregation aggregation, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores.Equivalent to:
zunionstore(destination, null, aggregation, key, keys)
- Specified by:
zunionstore
in interfaceRedisConnectionCommands
-
zunionstore
public long zunionstore(String destination, double[] weights, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except it does no aggregation of scores.Equivalent to:
zunionstore(destination, weights, null, key, keys)
- Specified by:
zunionstore
in interfaceRedisConnectionCommands
-
zunionstore
public long zunionstore(String destination, String key, String... keys)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zunionstore(String, double[], Aggregation, String, String...)
, except no weights are applied to the source value scores, and does no aggregation of scores.Equivalent to:
zunionstore(destination, null, null, key, keys)
- Specified by:
zunionstore
in interfaceRedisConnectionCommands
-
zlexcount
public long zlexcount(String key, String min, String max)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zlexcount:
Available since 2.8.9.
Time complexity: O(log(N)) with N being the number of elements in the sorted set.
When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns the number of elements in the sorted set at
key
with a value betweenmin
andmax
.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zlexcount
in interfaceRedisConnectionCommands
- Returns:
- the number of elements in the specified score range.
-
zlexcount
public long zlexcount(String key, double min, double max)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zlexcount(String, String, String)
, except it accepts doubles for min and max, not strings.- Specified by:
zlexcount
in interfaceRedisConnectionCommands
-
zrangebylex
public long zrangebylex(String key, String min, String max, Long limitOffset, Long limitCount)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zrangebylex:
Available since 2.8.9.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at
key
with a value betweenmin
andmax
.The optional
LIMIT
argument can be used to only get a range of the matching elements (similar to SELECT LIMIT offset, count in SQL). Keep in mind that ifoffset
is large, the sorted set needs to be traversed foroffset
elements before getting to the elements to return, which can add up to O(N) time complexity.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zrangebylex
in interfaceRedisConnectionCommands
- Returns:
- list of elements in the specified score range.
-
zrangebylex
public long zrangebylex(String key, double min, double max, Long limitOffset, Long limitCount)
Likezrangebylex(String, String, String, Long, Long)
, except it accepts doubles for min and max, not strings.- Specified by:
zrangebylex
in interfaceRedisConnectionCommands
-
zrangebylex
public long zrangebylex(String key, String min, String max)
Likezrangebylex(String, String, String, Long, Long)
, with no limit.- Specified by:
zrangebylex
in interfaceRedisConnectionCommands
-
zrangebylex
public long zrangebylex(String key, double min, double max)
Likezrangebylex(String, String, String)
, except it accepts doubles for min and max, not strings, with no limit.- Specified by:
zrangebylex
in interfaceRedisConnectionCommands
-
zremrangebylex
public long zremrangebylex(String key, String min, String max)
Description copied from interface:RedisConnectionCommands
From http://redis.io/commands/zremrangebylex:
Available since 2.8.9.
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command removes all elements in the sorted set stored at
key
between the lexicographical range specified bymin
andmax
.The arguments
min
andmax
are Strings so they can accept special ranges.- Specified by:
zremrangebylex
in interfaceRedisConnectionCommands
- Returns:
- the number of elements removed.
-
zremrangebylex
public long zremrangebylex(String key, double min, double max)
Description copied from interface:RedisConnectionCommands
LikeRedisConnectionCommands.zrangebylex(String, String, String)
, except it accepts doubles for min and max.- Specified by:
zremrangebylex
in interfaceRedisConnectionCommands
-
zscan
public RedisCursor zscan(String key, long cursor)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/zscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
zscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the sorted set to scan.cursor
- the cursor value.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
zscan
public RedisCursor zscan(String key, long cursor, String pattern)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/zscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
zscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the sorted set to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
zscan
public RedisCursor zscan(String key, long cursor, long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/zscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
zscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the sorted set to scan.cursor
- the cursor value.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
zscan
public RedisCursor zscan(String key, long cursor, String pattern, Long count)
Description copied from interface:RedisScanCommands
From http://redis.io/commands/zscan:
Available since 2.8.0.
Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
- Specified by:
zscan
in interfaceRedisScanCommands
- Parameters:
key
- the key of the sorted set to scan.cursor
- the cursor value.pattern
- if not null, return keys that fit a pattern.count
- if not null, cap the iterable keys at a limit.- Returns:
- a RedisCursor that represents the result of a SCAN call.
-
specialDouble
protected String specialDouble(double d)
Converts some of Java's primitive doubles to Redis interval values.Double.NEGATIVE_INFINITY
converts to "-".Double.POSITIVE_INFINITY
converts to "+".- All others convert to their string representation.
- Parameters:
d
- the input double.- Returns:
- the string representation of the value.
-
-