org.idevlab.rjc
Class RedisNode
java.lang.Object
org.idevlab.rjc.RedisNode
- All Implemented Interfaces:
- RedisOperations, SingleRedisOperations
public class RedisNode
- extends Object
- implements SingleRedisOperations
Creates new Session object for each command execution
|
Method Summary |
Long |
append(String key,
String value)
Time complexity
O(1). |
String |
auth(String password)
|
String |
bgrewriteaof()
|
String |
bgsave()
|
List<String> |
blpop(int timeout,
String... keys)
Time complexity
O(1)
BLPOP is a blocking list pop primitive. |
List<String> |
brpop(int timeout,
String... keys)
Time complexity
O(1)
BRPOP is a blocking list pop primitive. |
String |
brpoplpush(String source,
String destination,
int timeout)
Time complexity
O(1). |
List<String> |
configGet(String pattern)
|
String |
configSet(String parameter,
String value)
|
Long |
dbSize()
|
String |
debug(DebugParams params)
|
Long |
decr(String key)
Time complexity O(1)
Decrements the number stored at key by one. |
Long |
decrBy(String key,
int value)
Time complexity O(1)
Decrements the number stored at key by decrement. |
Long |
del(String... keys)
Time complexity O(N) where N is the number of keys that will be removed. |
String |
echo(String string)
|
Boolean |
exists(String key)
Time complexity O(1)
Determine if a key exists |
Boolean |
expire(String key,
int seconds)
Time complexity O(1)
Set a timeout on key. |
Boolean |
expireAt(String key,
long unixTime)
Time complexity O(1)
Set a timeout on key. |
String |
flushAll()
|
String |
flushDB()
|
String |
get(String key)
Time complexity O(1)
Get the value of key. |
Long |
getBit(String key,
int offset)
Time complexity O(1)
Returns the bit value at offset in the string value stored at key. |
String |
getRange(String key,
int start,
int end)
Time complexity O(N) where N is the length of the returned string. |
String |
getSet(String key,
String value)
Time complexity O(1)
Atomically sets key to value and returns the old value stored at key. |
Boolean |
hdel(String key,
String field)
Time complexity O(1)
Removes field from the hash stored at key. |
Boolean |
hexists(String key,
String field)
Time complexity O(1)
Returns if field is an existing field in the hash stored at key. |
String |
hget(String key,
String field)
Time complexity O(1)
Returns the value associated with field in the hash stored at key. |
Map<String,String> |
hgetAll(String key)
Time complexity O(N) where N is the size of the hash. |
Long |
hincrBy(String key,
String field,
int value)
Time complexity O(1)
Increments the number stored at field in the hash stored at key by increment. |
Set<String> |
hkeys(String key)
Time complexity
O(N) where N is the size of the hash. |
Long |
hlen(String key)
Time complexity
O(1)
Returns the number of fields contained in the hash stored at key. |
List<String> |
hmget(String key,
String... fields)
Time complexity
O(N) where N is the number of fields being requested. |
String |
hmset(String key,
Map<String,String> hash)
Time complexity
O(N) where N is the number of fields being set. |
Boolean |
hset(String key,
String field,
String value)
Time complexity
O(1)
Sets field in the hash stored at key to value. |
Boolean |
hsetnx(String key,
String field,
String value)
Time complexity
O(1)
Sets field in the hash stored at key to value, only if field does not yet exist. |
List<String> |
hvals(String key)
Time complexity
O(N) where N is the size of the hash. |
Long |
incr(String key)
Time complexity O(1)
Increments the number stored at key by one. |
Long |
incrBy(String key,
int value)
Time complexity O(1)
Increments the number stored at key by increment. |
String |
info()
|
Set<String> |
keys(String pattern)
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. |
Long |
lastsave()
|
String |
lindex(String key,
int index)
Time complexity
O(N) where N is the number of elements to traverse to get to the element at index. |
Long |
linsert(String key,
Client.LIST_POSITION where,
String pivot,
String value)
Time complexity
O(N) where N is the number of elements to traverse before seeing the value pivot. |
Long |
llen(String key)
Time complexity
O(1)
Returns the length of the list stored at key. |
String |
lpop(String key)
Time complexity
O(1)
Removes and returns the first element of the list stored at key. |
Long |
lpush(String key,
String value)
Time complexity
O(1)
Inserts value at the head of the list stored at key. |
Long |
lpushx(String key,
String value)
Time complexity
O(1)
Inserts value at the head of the list stored at key, only if key already exists and holds a list. |
List<String> |
lrange(String key,
int start,
int end)
Time complexity
O(S+N) where S is the start offset and N is the number of elements in the specified range. |
Long |
lrem(String key,
int count,
String value)
Time complexity
O(N) where N is the length of the list. |
String |
lset(String key,
int index,
String value)
Time complexity
O(N) where N is the length of the list. |
String |
ltrim(String key,
int start,
int end)
Time complexity
O(N) where N is the number of elements to be removed by the operation. |
List<String> |
mget(String... keys)
Time complexity O(N) where N is the number of keys to retrieve
Returns the values of all specified keys. |
void |
monitor(RedisMonitor redisMonitor)
|
Boolean |
move(String key,
int dbIndex)
Time complexity O(1)
Move key from the currently selected database (see SELECT) to the speficied destination database. |
String |
mset(String... keysvalues)
Time complexity O(N) where N is the number of keys to set
Sets the given keys to their respective values. |
Boolean |
msetnx(String... keysvalues)
Time complexity O(N) where N is the number of keys to set
Sets the given keys to their respective values. |
Boolean |
persist(String key)
Time complexity O(1)
Remove the existing timeout on key. |
String |
ping()
|
List<Object> |
pipeline(Pipeline pipeline)
|
Long |
publish(String channel,
String message)
|
void |
quit()
|
String |
randomKey()
Time complexity O(1)
Return a random key from the currently selected database. |
String |
rename(String key,
String newKey)
Time complexity O(1)
Renames key to newKey. |
Boolean |
renamenx(String key,
String newKey)
Time complexity O(1)
Renames key to newKey if newKey does not yet exist. |
String |
rpop(String key)
Time complexity
O(1)
Removes and returns the last element of the list stored at key. |
String |
rpoplpush(String srckey,
String dstkey)
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 at destination. |
Long |
rpush(String key,
String value)
Time complexity
O(1)
Inserts value at the tail of the list stored at key. |
Long |
rpushx(String key,
String value)
Time complexity
O(1)
Inserts value at the tail of the list stored at key, only if key already exists and holds a list. |
Boolean |
sadd(String key,
String member)
Time complexity
O(1)
Add member to the set stored at key. |
String |
save()
|
Long |
scard(String key)
Time complexity
O(1)
Returns the set cardinality (number of elements) of the set stored at key. |
Set<String> |
sdiff(String... keys)
Time complexity
O(N) where N is the total number of elements in all given sets. |
Long |
sdiffstore(String dstkey,
String... keys)
Time complexity
O(N) where N is the total number of elements in all given sets. |
String |
set(String key,
String value)
Time complexity O(1)
Set key to hold the string value. |
Long |
setBit(String key,
int offset,
String value)
Time complexity O(1)
Sets or clears the bit at offset in the string value stored at key. |
void |
setDataSource(DataSource dataSource)
|
String |
setex(String key,
int seconds,
String value)
Time complexity O(1)
Set key to hold the string value and set key to timeout after a given number of seconds. |
Boolean |
setnx(String key,
String value)
Time complexity O(1)
Set key to hold string value if key does not exist. |
Long |
setRange(String key,
int offset,
String value)
Time complexity O(1), not counting the time taken to copy the new string in place. |
String |
shutdown()
|
Set<String> |
sinter(String... keys)
Time complexity
O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets. |
Long |
sinterstore(String dstkey,
String... keys)
Time complexity
O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets. |
Boolean |
sismember(String key,
String member)
Time complexity
O(1)
Returns if member is a member of the set stored at key. |
String |
slaveof(String host,
int port)
|
String |
slaveofNoOne()
|
Set<String> |
smembers(String key)
Time complexity
O(N) where N is the set cardinality. |
Boolean |
smove(String srckey,
String dstkey,
String member)
Time complexity
O(1)
Move member from the set at source to the set at destination. |
List<String> |
sort(String key)
Time complexity O(N*log(N)) where N is the number of elements returned. |
List<String> |
sort(String key,
SortingParams sortingParameters)
Time complexity O(N*log(N)) where N is the number of elements returned. |
Long |
sort(String key,
SortingParams sortingParameters,
String dstkey)
|
Long |
sort(String key,
String dstkey)
|
String |
spop(String key)
Time complexity
O(1)
Removes and returns a random element from the set value stored at key. |
String |
srandmember(String key)
Time complexity
O(1)
Returns a random element from the set value stored at key. |
Boolean |
srem(String key,
String member)
Time complexity
O(1)
Remove member from the set stored at key. |
Long |
strlen(String key)
Time complexity O(1)
Returns the length of the string value stored at key. |
Set<String> |
sunion(String... keys)
Time complexity
O(N) where N is the total number of elements in all given sets. |
Long |
sunionstore(String dstkey,
String... keys)
Time complexity
O(N) where N is the total number of elements in all given sets. |
void |
sync()
|
Long |
ttl(String key)
Time complexity O(1)
Returns the remaining time to live of a key that has a timeout. |
String |
type(String key)
Time complexity O(1)
Returns the string representation of the type of the value stored at key. |
Boolean |
zadd(String key,
Number score,
String member)
Time complexity
O(log(N)) where N is the number of elements in the sorted set. |
Long |
zcard(String key)
Time complexity
O(1)
Returns the sorted set cardinality (number of elements) of the sorted set stored at key. |
Long |
zcount(String key,
Number min,
Number max)
Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M being the number of elements between min and max. |
String |
zincrby(String key,
Number score,
String member)
Time complexity
O(log(N)) where N is the number of elements in the sorted set. |
Long |
zinterstore(String dstkey,
String... sets)
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. |
Long |
zinterstore(String dstkey,
ZParams params,
String... sets)
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. |
List<String> |
zrange(String key,
int start,
int end)
Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned. |
List<String> |
zrangeByScore(String key,
String min,
String max)
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. |
List<String> |
zrangeByScore(String key,
String min,
String max,
int offset,
int count)
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. |
List<ElementScore> |
zrangeByScoreWithScores(String key,
String min,
String max)
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. |
List<ElementScore> |
zrangeByScoreWithScores(String key,
String min,
String max,
int offset,
int count)
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. |
List<ElementScore> |
zrangeWithScores(String key,
int start,
int end)
Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned. |
Long |
zrank(String key,
String member)
Time complexity
O(log(N))
Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. |
Boolean |
zrem(String key,
String member)
Time complexity
O(log(N)) with N being the number of elements in the sorted set. |
Long |
zremrangeByRank(String key,
int start,
int end)
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. |
Long |
zremrangeByScore(String key,
String min,
String max)
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. |
List<String> |
zrevrange(String key,
int start,
int end)
Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned. |
List<String> |
zrevrangeByScore(String key,
String max,
String min)
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. |
List<String> |
zrevrangeByScore(String key,
String max,
String min,
int offset,
int count)
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. |
List<ElementScore> |
zrevrangeByScoreWithScores(String key,
String max,
String min)
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. |
List<ElementScore> |
zrevrangeByScoreWithScores(String key,
String max,
String min,
int offset,
int count)
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. |
List<ElementScore> |
zrevrangeWithScores(String key,
int start,
int end)
Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned. |
Long |
zrevrank(String key,
String member)
Time complexity
O(log(N))
Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. |
String |
zscore(String key,
String member)
Time complexity
O(1)
Returns the score of member in the sorted set at key. |
Long |
zunionstore(String dstkey,
String... sets)
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. |
Long |
zunionstore(String dstkey,
ZParams params,
String... sets)
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RedisNode
public RedisNode()
RedisNode
public RedisNode(DataSource dataSource)
setDataSource
public void setDataSource(DataSource dataSource)
ping
public String ping()
- Specified by:
ping in interface SingleRedisOperations
randomKey
public String randomKey()
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
Return a random key from the currently selected database.
- Specified by:
randomKey in interface SingleRedisOperations
- Returns:
- the random key, or null when the database is empty.
set
public String set(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type.
- Specified by:
set in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- always OK since SET can't fail
get
public String get(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Get the value of key. If the key does not exist the special value nil is returned.
An error is returned if the value stored at key is not a string, because GET only handles string values.
- Specified by:
get in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the value of key, or null when key does not exist.
quit
public void quit()
- Specified by:
quit in interface SingleRedisOperations
exists
public Boolean exists(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Determine if a key exists
- Specified by:
exists in interface RedisOperations
- Parameters:
key - the key
- Returns:
- true if a key exists otherwise false
del
public Long del(String... keys)
- Description copied from interface:
RedisOperations
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 interface RedisOperations
- Parameters:
keys - keys
- Returns:
- The number of keys that were removed.
type
public String type(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the string representation of the type of the value stored at key.
The different types that can be returned are: string, list, set, zset and hash.
- Specified by:
type in interface RedisOperations
- Parameters:
key - the key
- Returns:
- type of key, or none when key does not exist.
flushDB
public String flushDB()
- Specified by:
flushDB in interface SingleRedisOperations
keys
public Set<String> keys(String pattern)
- Description copied from interface:
RedisOperations
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.
While the time complexity for this operation is O(N), the constant times are fairly low.
For example, Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds.
Warning: consider KEYS as a command that should only be used in production environments with extreme care.
It may ruin performance when it is executed against large databases.
This command is intended for debugging and special operations, such as changing your keyspace layout.
Don't use KEYS in your regular application code. If you're looking for a way to find keys
in a subset of your keyspace, consider using sets.
Supported glob-style patterns:
- h?llo matches hello, hallo and hxllo
- h*llo matches hllo and heeeello
- h[ae]llo matches hello and hallo, but not hillo
Use \ to escape special characters if you want to match them verbatim.
- Specified by:
keys in interface RedisOperations
- Parameters:
pattern - pattern
- Returns:
- list of keys matching pattern.
rename
public String rename(String key,
String newKey)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
Renames key to newKey. It returns an error when the source and destination names are the same,
or when key does not exist. If newKey already exists it is overwritten.
- Specified by:
rename in interface SingleRedisOperations
- Parameters:
key - a keynewKey - new key
- Returns:
- status code reply
renamenx
public Boolean renamenx(String key,
String newKey)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
Renames key to newKey if newKey does not yet exist. It returns an error under the same conditions as RENAME.
- Specified by:
renamenx in interface SingleRedisOperations
- Parameters:
key - a keynewKey - new key
- Returns:
- true if key was renamed to newKey or false if newKey already exists
dbSize
public Long dbSize()
- Specified by:
dbSize in interface SingleRedisOperations
expire
public Boolean expire(String key,
int seconds)
- Description copied from interface:
RedisOperations
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 said to be volatile in Redis terminology.
For Redis versions < 2.1.3, existing timeouts cannot be overwritten.
So, if key already has an associated timeout, it will do nothing and return 0.
Since Redis 2.1.3, you can update the timeout of a key.
It is also possible to remove the timeout using the PERSIST command.
See the page on key expiry for more information.
- Specified by:
expire in interface RedisOperations
- Parameters:
key - the keyseconds - key timeout
- Returns:
- true if the timeout was set otherwise false
expireAt
public Boolean expireAt(String key,
long unixTime)
- Description copied from interface:
RedisOperations
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 said to be volatile in Redis terminology.
EXPIREAT has the same effect and semantic as EXPIRE, 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).
Background
EXPIREAT was introduced in order to convert relative timeouts to absolute timeouts for the AOF persistence mode.
Of course, it can be used directly to specify that a given key should expire at a given time in the future.
- Specified by:
expireAt in interface RedisOperations
- Parameters:
key - a keyunixTime - an absolute UNIX timestamp (seconds since January 1, 1970)
- Returns:
- true if the timeout was set otherwise false
ttl
public Long ttl(String key)
- Description copied from interface:
RedisOperations
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 interface RedisOperations
- Parameters:
key - the key
- Returns:
- TTL in seconds or -1 when key does not exist or does not have a timeout.
move
public Boolean move(String key,
int dbIndex)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
Move key from the currently selected database (see SELECT) to the speficied destination database.
When key 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 interface SingleRedisOperations
- Parameters:
key - a keydbIndex - database index
- Returns:
- true if key was moved otherwise false
flushAll
public String flushAll()
- Specified by:
flushAll in interface SingleRedisOperations
getSet
public String getSet(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Atomically sets key to value and returns the old value stored at key.
Returns an error when key exists but does not hold a string value.
- Specified by:
getSet in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the old value stored at key, or null when key did not exist.
mget
public List<String> mget(String... keys)
- Description copied from interface:
SingleRedisOperations
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 interface SingleRedisOperations
- Parameters:
keys - the keys
- Returns:
- list of values at the specified keys.
setnx
public Boolean setnx(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Set key to hold string value if key does not exist. In that case, it is equal to SET.
When key already holds a value, no operation is performed. SETNX is short for "SET if Not eXists".
- Specified by:
setnx in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- true if the key was set otherwise false
setex
public String setex(String key,
int seconds,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Set key to hold the string value and set key to timeout after a given number of seconds.
This command is equivalent to executing the following commands:
SET key value
EXPIRE key seconds
SETEX is atomic, and can be reproduced by using the previous two commands inside an MULTI/EXEC block.
It is provided as a faster alternative to the given sequence of operations,
because this operation is very common when Redis is used as a cache.
An error is returned when seconds is invalid.
- Specified by:
setex in interface RedisOperations
- Parameters:
key - the keyseconds - ttl in secondsvalue - the value
- Returns:
- Status code reply
mset
public String mset(String... keysvalues)
- Description copied from interface:
SingleRedisOperations
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. See MSETNX if you don't want to overwrite existing values.
MSET is atomic, so all given keys are set at once. It is not possible for clients to see
that some of the keys were updated while others are unchanged.
- Specified by:
mset in interface SingleRedisOperations
- Parameters:
keysvalues - array of keys and values, for instance {"key1", "value1", "key2", "value2"}
- Returns:
- always OK since MSET can't fail.
msetnx
public Boolean msetnx(String... keysvalues)
- Description copied from interface:
SingleRedisOperations
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.
Because of this semantic MSETNX can be used in order to set different keys representing different fields
of an unique logic object in a way that ensures that either all the fields or none at all are set.
MSETNX is atomic, so all given keys are set at once. It is not possible for clients to see
that some of the keys were updated while others are unchanged.
- Specified by:
msetnx in interface SingleRedisOperations
- Parameters:
keysvalues - array of keys and values, for instance {"key1", "value1", "key2", "value2"}
- Returns:
- true if the all the keys were set or false if no key was set (at least one key already existed).
decrBy
public Long decrBy(String key,
int value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Decrements the number stored at key by decrement. If the key does not exist or contains a value of
the wrong type, it is set to 0 before performing the operation.
This operation is limited to 64 bit signed integers.
See INCR for extra information on increment/decrement operations.
- Specified by:
decrBy in interface RedisOperations
- Parameters:
key - the keyvalue - decrement value
- Returns:
- the value of key after the decrement
decr
public Long decr(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Decrements the number stored at key by one. If the key does not exist or contains a value of the wrong type,
it is set to 0 before performing the operation. This operation is limited to 64 bit signed integers.
See INCR for extra information on increment/decrement operations.
- Specified by:
decr in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the value of key after the decrement
incrBy
public Long incrBy(String key,
int value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Increments the number stored at key by increment. If the key does not exist or contains
a value of the wrong type, it is set to 0 before performing the operation.
This operation is limited to 64 bit signed integers.
See INCR for extra information on increment/decrement operations.
- Specified by:
incrBy in interface RedisOperations
- Parameters:
key - the keyvalue - increment value
- Returns:
- the value of key after the increment
incr
public Long incr(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Increments the number stored at key by one. If the key does not exist or contains a value
of the wrong type, it is set to 0 before performing the operation.
This operation is limited to 64 bit signed integers.
Note: this is a string operation because Redis does not have a dedicated integer type.
The the string stored at the key is interpreted as a base-10 64 bit signed integer to execute the operation.
Redis stores integers in their integer representation, so for string values that actually hold an integer, there is no overhead for storing the string representation of the integer.
- Specified by:
incr in interface RedisOperations
- Parameters:
key - the value
- Returns:
- the value of key after the increment
append
public Long append(String key,
String value)
- Description copied from interface:
RedisOperations
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 the value at the end of the string.
If key 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 interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the length of the string after the append operation
getRange
public String getRange(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
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.
Warning: this command was renamed to GETRANGE, it is called SUBSTR in Redis versions <= 2.0.
Returns the substring of the string value stored at key, determined by the offsets start
and end (both are inclusive). Negative offsets can be used in order to provide an offset starting
from the end of the string. So -1 means the last character, -2 the penultimate and so forth.
The function handles out of range requests by limiting the resulting range to the actual length of the string.
- Specified by:
getRange in interface RedisOperations
- Parameters:
key - the keystart - offset startend - offset end
- Returns:
- substring of the string value stored at key
setRange
public Long setRange(String key,
int offset,
String value)
- Description copied from interface:
RedisOperations
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.
Note that the maximum offset that you can set is 229 -1 (536870911), as Redis Strings are limited to 512 megabytes. If you need to grow beyond this size, you can use multiple keys.
Warning: When setting the last possible byte and the string value stored at key does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can block the server for some time. On a 2010 Macbook Pro, setting byte number 536870911 (512MB allocation) takes ~300ms, setting byte number 134217728 (128MB allocation) takes ~80ms, setting bit number 33554432 (32MB allocation) takes ~30ms and setting bit number 8388608 (8MB allocation) takes ~8ms. Note that once this first allocation is done, subsequent calls to SETRANGE for the same key will not have the allocation overhead.
Patterns
Thanks to SETRANGE and the analogous GETRANGE commands, you can use Redis strings as a linear
array with O(1) random access. This is a very fast and efficient storage in many real world use cases.
- Specified by:
setRange in interface RedisOperations
- Parameters:
key - the keyoffset - the offsetvalue - the value
- Returns:
- the length of the string after it was modified by the command.
hset
public Boolean hset(String key,
String field,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Sets field in the hash stored at key to value.
If key does not exist, a new key holding a hash is created.
If field already exists in the hash, it is overwritten.
- Specified by:
hset in interface RedisOperations
- Parameters:
key - the keyfield - the fieldvalue - the value
- Returns:
- true if field is a new field in the hash and value was set or false if field already exists in the hash and the value was updated.
hget
public String hget(String key,
String field)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the value associated with field in the hash stored at key.
- Specified by:
hget in interface RedisOperations
- Parameters:
key - the keyfield - the field
- Returns:
- the value associated with field, or null when field is not present in the hash or key does not exist.
hsetnx
public Boolean hsetnx(String key,
String field,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Sets field in the hash stored at key to value, only if field does not yet exist.
If key does not exist, a new key holding a hash is created.
If field already exists, this operation has no effect.
- Specified by:
hsetnx in interface RedisOperations
- Parameters:
key - the keyfield - the fieldvalue - the value
- Returns:
- true if field is a new field in the hash and value was set or
false if field already exists in the hash and no operation was performed
hmset
public String hmset(String key,
Map<String,String> hash)
- Description copied from interface:
RedisOperations
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. If key does not exist, a new key holding a hash is created.
- Specified by:
hmset in interface RedisOperations
- Parameters:
key - the keyhash - the hash
- Returns:
- Status code reply
hmget
public List<String> hmget(String key,
String... fields)
- Description copied from interface:
RedisOperations
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 at key.
For every field that does not exist in the hash, a nil value is returned.
Because a non-existing keys are treated as empty hashes,
running HMGET against a non-existing key will return a list of nil values.
- Specified by:
hmget in interface RedisOperations
- Parameters:
key - the keyfields - the fields
- Returns:
- list of values associated with the given fields, in the same order as they are requested.
hincrBy
public Long hincrBy(String key,
String field,
int value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Increments the number stored at field in the hash stored at key by increment.
If key does not exist, a new key holding a hash is created.
If field does not exist or holds a string that cannot be interpreted as integer,
the value is set to 0 before the operation is performed.
The range of values supported by HINCRBY is limited to 64 bit signed integers.
- Specified by:
hincrBy in interface RedisOperations
- Parameters:
key - the keyfield - the fieldvalue - the value
- Returns:
- the value at field after the increment operation
hexists
public Boolean hexists(String key,
String field)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns if field is an existing field in the hash stored at key.
- Specified by:
hexists in interface RedisOperations
- Parameters:
key - the keyfield - the field
- Returns:
- true if the hash contains field or false if the hash does not contain field, or key does not exist.
hdel
public Boolean hdel(String key,
String field)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Removes field from the hash stored at key.
- Specified by:
hdel in interface RedisOperations
- Parameters:
key - the keyfield - the field
- Returns:
- true if field was present in the hash and is now removed or
false if field does not exist in the hash, or key does not exist.
hlen
public Long hlen(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the number of fields contained in the hash stored at key.
- Specified by:
hlen in interface RedisOperations
- Parameters:
key - the key
- Returns:
- number of fields in the hash, or 0 when key does not exist.
hkeys
public Set<String> hkeys(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(N) where N is the size of the hash.
Returns all field names of the hash stored at key.
- Specified by:
hkeys in interface RedisOperations
- Parameters:
key - the key
- Returns:
- list of fields in the hash, or an empty list when key does not exist.
hvals
public List<String> hvals(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(N) where N is the size of the hash.
Returns all values of the hash stored at key.
- Specified by:
hvals in interface RedisOperations
- Parameters:
key - the key
- Returns:
- list of values in the hash, or an empty list when key does not exist.
hgetAll
public Map<String,String> hgetAll(String key)
- Description copied from interface:
RedisOperations
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 interface RedisOperations
- Parameters:
key - the key
- Returns:
- map of fields and their values stored in the hash, or an empty map when key does not exist
rpush
public Long rpush(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Inserts value at the tail of the list stored at key.
If key does not exist, it is created as empty list before performing the push operation.
When key holds a value that is not a list, an error is returned.
- Specified by:
rpush in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the length of the list after the push operation.
lpush
public Long lpush(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Inserts value at the head of the list stored at key.
If key does not exist, it is created as empty list before performing the push operation.
When key holds a value that is not a list, an error is returned.
- Specified by:
lpush in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the length of the list after the push operation.
llen
public Long llen(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the length of the list stored at key. If key does not exist,
it is interpreted as an empty list and 0 is returned.
An error is returned when the value stored at key is not a list.
- Specified by:
llen in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the length of the list at key.
lrange
public List<String> lrange(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
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 offsets start and end are zero-based indexes,
with 0 being the first element of the list (the head of the list), 1 being the next element and so on.
These offsets can also be negative numbers indicating offsets starting at the end of the list.
For example, -1 is the last element of the list, -2 the penultimate, and so on.
Consistency with range functions in various programming languages
Note that if you have a list of numbers from 0 to 100, LRANGE list 0 10 will return 11 elements,
that is, the rightmost item is included. This may or may not be consistent with behavior
of range-related functions in your programming language of choice
(think Ruby's Range.new, Array#slice or Python's range() function).
Out-of-range indexes
Out of range indexes will not produce an error.
If start is larger than the end of the list, or start > end, an empty list is returned.
If end is larger than the actual end of the list, Redis will treat it like the last element of the list.
- Specified by:
lrange in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- list of elements in the specified range.
ltrim
public String ltrim(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
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 and stop are zero-based indexes, where 0 is the first element of the list (the head),
1 the next element and so on.
For example: LTRIM foobar 0 2 will modify the list stored at foobar so
that only the first three elements of the list will remain.
start and end can also be negative numbers indicating offsets from the end of the list,
where -1 is the last element of the list, -2 the penultimate element and so on.
Out of range indexes will not produce an error: if start is larger than the end of the list,
or start > end, the result will be an empty list (which causes key to be removed).
If end is larger than the end of the list, Redis will treat it like the last element of the list.
A common use of LTRIM is together with LPUSH/RPUSH. For example:
LPUSH mylist someelement
LTRIM mylist 0 99
This pair of commands will push a new element on the list,
while making sure that the list will not grow larger than 100 elements.
This is very useful when using Redis to store logs for example.
It is important to note that when used in this way LTRIM is an O(1) operation
because in the average case just one element is removed from the tail of the list.
- Specified by:
ltrim in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- Status code reply
lindex
public String lindex(String key,
int index)
- Description copied from interface:
RedisOperations
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 at key.
The index is zero-based, so 0 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.
When the value at key is not a list, an error is returned.
- Specified by:
lindex in interface RedisOperations
- Parameters:
key - the keyindex - the index
- Returns:
- the requested element, or null when index is out of range.
lset
public String lset(String key,
int index,
String value)
- Description copied from interface:
RedisOperations
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 to value. For more information on the index argument, see LINDEX.
An error is returned for out of range indexes.
- Specified by:
lset in interface RedisOperations
- Parameters:
key - the keyindex - the indexvalue - the value
- Returns:
- Status code reply
lrem
public Long lrem(String key,
int count,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(N) where N is the length of the list.
Removes the first count occurrences of elements equal to value from the list stored at key.
The count argument influences the operation in the following ways:
- count > 0: Remove elements equal to value moving from head to tail.
- count < 0: Remove elements equal to value moving from tail to head.
- count = 0: Remove all elements equal to value.
For example, LREM list -2 "hello" will remove the last two occurrences of "hello" in the list stored at list.
Note that non-existing keys are treated like empty lists, so when key does not exist, the command will always return 0.
- Specified by:
lrem in interface RedisOperations
- Parameters:
key - the keycount - the countvalue - the value
- Returns:
- the number of removed elements.
lpop
public String lpop(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Removes and returns the first element of the list stored at key.
- Specified by:
lpop in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the value of the first element, or null when key does not exist.
rpop
public String rpop(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Removes and returns the last element of the list stored at key.
- Specified by:
rpop in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the value of the last element, or nil when key does not exist.
rpoplpush
public String rpoplpush(String srckey,
String dstkey)
- Description copied from interface:
SingleRedisOperations
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 at destination.
For example: consider source holding the list a,b,c, and destination holding the list x,y,z.
Executing RPOPLPUSH results in source holding a,b and destination holding c,x,y,z.
If source does not exist, the value nil is returned and no operation is performed.
If source and destination are the same, the operation is equivalent to removing
the last element from the list and pushing it as first element of the list,
so it can be considered as a list rotation command.
- Specified by:
rpoplpush in interface SingleRedisOperations
- Parameters:
srckey - source keydstkey - destination key
- Returns:
- the element being popped and pushed.
brpoplpush
public String brpoplpush(String source,
String destination,
int timeout)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1).
BRPOPLPUSH is the blocking variant of RPOPLPUSH. When source contains elements,
this command behaves exactly like RPOPLPUSH. When source is empty,
Redis will block the connection until another client pushes to it or until timeout is reached.
A timeout of zero can be used to block indefinitely.
See RPOPLPUSH for more information.
- Specified by:
brpoplpush in interface SingleRedisOperations
- Parameters:
source - source keydestination - destination keytimeout - blocking timeout
- Returns:
- the element being popped from source and pushed to destination. If timeout is reached, a null is returned.
sadd
public Boolean sadd(String key,
String member)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Add member to the set stored at key. If member is already a member of this set, no operation is performed.
If key does not exist, a new set is created with member as its sole member.
An error is returned when the value stored at key is not a set.
- Specified by:
sadd in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- true if the element was added or false if the element was already a member of the set
smembers
public Set<String> smembers(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(N) where N is the set cardinality.
Returns all the members of the set value stored at key.
This has the same effect as running SINTER with one argument key.
- Specified by:
smembers in interface RedisOperations
- Parameters:
key - the key
- Returns:
- all elements of the set.
srem
public Boolean srem(String key,
String member)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Remove member from the set stored at key. If member is not a member of this set, no operation is performed.
An error is returned when the value stored at key is not a set.
- Specified by:
srem in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- true if the element was removed or false if the element was not a member of the set.
spop
public String spop(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Removes and returns a random element from the set value stored at key.
This operation is similar to SRANDMEMBER, that returns a random element from a set but does not remove it.
- Specified by:
spop in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the removed element, or null when key does not exist.
smove
public Boolean smove(String srckey,
String dstkey,
String member)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
Move member from the set at source to the set at destination. This operation is atomic.
In every given moment the element will appear to be a member of source or destination for other clients.
If the source set does not exist or does not contain the specified element,
no operation is performed and 0 is returned.
Otherwise, the element is removed from the source set and added to the destination set.
When the specified element already exists in the destination set, it is only removed from the source set.
An error is returned if source or destination does not hold a set value.
- Specified by:
smove in interface SingleRedisOperations
- Parameters:
srckey - source keydstkey - destination keymember - the member
- Returns:
- true if the element is moved or false if the element is not a member of source and no operation was performed.
scard
public Long scard(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the set cardinality (number of elements) of the set stored at key.
- Specified by:
scard in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the cardinality (number of elements) of the set, or 0 if key does not exist.
sismember
public Boolean sismember(String key,
String member)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns if member is a member of the set stored at key.
- Specified by:
sismember in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- if the element is a member of the set or false if the element is not a member of the set, or if key does not exist.
sinter
public Set<String> sinter(String... keys)
- Description copied from interface:
SingleRedisOperations
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.
For example:
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SINTER key1 key2 key3 = {c}
Keys that do not exist are considered to be empty sets. With one of the keys being an empty set,
the resulting set is also empty (since set intersection with an empty set always results in an empty set).
- Specified by:
sinter in interface SingleRedisOperations
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sinterstore
public Long sinterstore(String dstkey,
String... keys)
- Description copied from interface:
SingleRedisOperations
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.
If destination already exists, it is overwritten.
- Specified by:
sinterstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- the number of elements in the resulting set.
sunion
public Set<String> sunion(String... keys)
- Description copied from interface:
SingleRedisOperations
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.
For example:
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SUNION key1 key2 key3 = {a,b,c,d,e}
Keys that do not exist are considered to be empty sets.
- Specified by:
sunion in interface SingleRedisOperations
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sunionstore
public Long sunionstore(String dstkey,
String... keys)
- Description copied from interface:
SingleRedisOperations
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.
If destination already exists, it is overwritten.
- Specified by:
sunionstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- he number of elements in the resulting set.
sdiff
public Set<String> sdiff(String... keys)
- Description copied from interface:
SingleRedisOperations
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.
For example:
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SDIFF key1 key2 key3 = {b,d}
Keys that do not exist are considered to be empty sets.
- Specified by:
sdiff in interface SingleRedisOperations
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sdiffstore
public Long sdiffstore(String dstkey,
String... keys)
- Description copied from interface:
SingleRedisOperations
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.
If destination already exists, it is overwritten.
- Specified by:
sdiffstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- the number of elements in the resulting set.
srandmember
public String srandmember(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns a random element from the set value stored at key.
This operation is similar to SPOP, that also removes the randomly selected element.
- Specified by:
srandmember in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the randomly selected element, or null when key does not exist.
zadd
public Boolean zadd(String key,
Number score,
String member)
- Description copied from interface:
RedisOperations
- Time complexity
O(log(N)) where N is the number of elements in the sorted set.
Adds the member with the specified score to the sorted set stored at key.
If 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.
If key does not exist, a new sorted set with the specified member as sole member is created.
If the key exists but does not hold a sorted set, an error is returned.
The score value should be the string representation of a numeric value,
and accepts double precision floating point numbers.
For an introduction to sorted sets, see the data types page on sorted sets.
- Specified by:
zadd in interface RedisOperations
- Parameters:
key - the keyscore - the scoremember - the member
- Returns:
- true if the element was added or false if the element was already a member of the sorted set and the score was updated.
zrange
public List<String> zrange(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
- 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.
See ZREVRANGE when you need the elements ordered from highest to lowest score.
Both start and stop are zero-based indexes, where 0 is the first element, 1 is the next element and so on.
They can also be negative numbers indicating offsets from the end of the sorted set,
with -1 being the last element of the sorted set, -2 the penultimate element and so on.
Out of range indexes will not produce an error.
If start is larger than the largest index in the sorted set, or start > stop, an empty list is returned.
If stop is larger than the end of the sorted set Redis will treat
it like it is the last element of the sorted set.
It is possible to pass the WITHSCORES option in order to return the scores of the elements
together with the elements. The returned list will contain value1,score1,...,valueN,scoreN instead of
value1,...,valueN. Client libraries are free to return a more appropriate data type
(suggestion: an array with (value, score)
- Specified by:
zrange in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- list of elements in the specified range.
zrem
public Boolean zrem(String key,
String member)
- Description copied from interface:
RedisOperations
- Time complexity
O(log(N)) with N being the number of elements in the sorted set.
Removes the member from the sorted set stored at key. If member is not a member of the sorted set, no operation is performed.
An error is returned when key exists and does not hold a sorted set.
- Specified by:
zrem in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- true if member was removed or false if member is not a member of the sorted set.
zincrby
public String zincrby(String key,
Number score,
String member)
- Description copied from interface:
RedisOperations
- 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 at key by increment.
If member does not exist in the sorted set, it is added with increment as
its score (as if its previous score was 0.0).
If key does not exist, a new sorted set with the specified member as its sole member is created.
An error is returned when key exists but does not hold a sorted set.
The score value should be the string representation of a numeric value,
and accepts double precision floating point numbers.
It is possible to provide a negative value to decrement the score.
- Specified by:
zincrby in interface RedisOperations
- Parameters:
key - the keyscore - the scoremember - the member
- Returns:
- he new score of member (a double precision floating point number), represented as string.
zrank
public Long zrank(String key,
String member)
- Description copied from interface:
RedisOperations
- Time complexity
O(log(N))
Returns the rank of member in the sorted set stored at key, 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 rank 0.
Use ZREVRANK to get the rank of an element with the scores ordered from high to low.
- Specified by:
zrank in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- If member exists in the sorted set, the rank of member.
- If member does not exist in the sorted set or key does not exist, null.
zrevrank
public Long zrevrank(String key,
String member)
- Description copied from interface:
RedisOperations
- Time complexity
O(log(N))
Returns the rank of member in the sorted set stored at key, 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 rank 0.
Use ZRANK to get the rank of an element with the scores ordered from low to high.
- Specified by:
zrevrank in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- If member exists in the sorted set, the rank of member.
- If member does not exist in the sorted set or key does not exist, Bulk reply: null.
zrevrange
public List<String> zrevrange(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
- 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.
Apart from the reversed ordering, ZREVRANGE is similar to ZRANGE.
- Specified by:
zrevrange in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- list of elements in the specified range
zrangeWithScores
public List<ElementScore> zrangeWithScores(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
- 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.
See ZREVRANGE when you need the elements ordered from highest to lowest score.
Both start and stop are zero-based indexes, where 0 is the first element, 1 is the next element and so on.
They can also be negative numbers indicating offsets from the end of the sorted set,
with -1 being the last element of the sorted set, -2 the penultimate element and so on.
Out of range indexes will not produce an error.
If start is larger than the largest index in the sorted set, or start > stop, an empty list is returned.
If stop is larger than the end of the sorted set Redis will treat
it like it is the last element of the sorted set.
It is possible to pass the WITHSCORES option in order to return the scores of the elements
together with the elements. The returned list will contain value1,score1,...,valueN,scoreN instead of
value1,...,valueN. Client libraries are free to return a more appropriate data type
(suggestion: an array with (value, score)
- Specified by:
zrangeWithScores in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- list of elements in the specified range with their scores.
zrevrangeWithScores
public List<ElementScore> zrevrangeWithScores(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
- 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.
Apart from the reversed ordering, ZREVRANGE is similar to ZRANGE.
- Specified by:
zrevrangeWithScores in interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- list of elements in the specified range with their scores
zrevrangeByScore
public List<String> zrevrangeByScore(String key,
String max,
String min)
- Description copied from interface:
RedisOperations
- 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 between max and min
(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 elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.
- Specified by:
zrevrangeByScore in interface RedisOperations
- Parameters:
key - the keymax - max scoremin - min score
- Returns:
- list of elements in the specified score range (optionally with their scores).
zrevrangeByScore
public List<String> zrevrangeByScore(String key,
String max,
String min,
int offset,
int count)
- Description copied from interface:
RedisOperations
- 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 between max and min
(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 elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.
- Specified by:
zrevrangeByScore in interface RedisOperations
- Parameters:
key - the keymax - max scoremin - min scoreoffset - limit offsetcount - limit count
- Returns:
- list of elements in the specified score range (optionally with their scores).
zrevrangeByScoreWithScores
public List<ElementScore> zrevrangeByScoreWithScores(String key,
String max,
String min)
- Description copied from interface:
RedisOperations
- 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 between max and min
(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 elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.
- Specified by:
zrevrangeByScoreWithScores in interface RedisOperations
- Parameters:
key - the keymax - max scoremin - min score
- Returns:
- list of elements in the specified score range (optionally with their scores).
zrevrangeByScoreWithScores
public List<ElementScore> zrevrangeByScoreWithScores(String key,
String max,
String min,
int offset,
int count)
- Description copied from interface:
RedisOperations
- 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 between max and min
(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 elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.
- Specified by:
zrevrangeByScoreWithScores in interface RedisOperations
- Parameters:
key - the keymax - max scoremin - min scoreoffset - limit offsetcount - limit count
- Returns:
- list of elements in the specified score range (optionally with their scores).
zcard
public Long zcard(String key)
- Description copied from interface:
RedisOperations
- Time complexity
O(1)
Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
- Specified by:
zcard in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the cardinality (number of elements) of the sorted set, or 0 if key does not exist.
zscore
public String zscore(String key,
String member)
- Description copied from interface:
RedisOperations
- Time complexity
O(1)
Returns the score of member in the sorted set at key.
If member does not exist in the sorted set, or key does not exist, nil is returned.
- Specified by:
zscore in interface RedisOperations
- Parameters:
key - the keymember - the member
- Returns:
- the score of member (a double precision floating point number), represented as string.
sort
public List<String> sort(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(N*log(N)) where N is the number of elements returned.
When the elements are not sorted, complexity is O(N).
Returns 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 interface RedisOperations
- Parameters:
key - the key
- Returns:
- list of sorted elements.
sort
public List<String> sort(String key,
SortingParams sortingParameters)
- Description copied from interface:
RedisOperations
Time complexity
O(N*log(N)) where N is the number of elements returned.
When the elements are not sorted, complexity is O(N).
Returns 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 interface RedisOperations
- Parameters:
key - a keysortingParameters - sorting parameters
- Returns:
- list of sorted elements.
- See Also:
- SORT command
blpop
public List<String> blpop(int timeout,
String... keys)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
BLPOP is a blocking list pop primitive. It is the blocking version of LPOP 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.
Non-blocking behavior
When BLPOP is called, if at least one of the specified keys contain a non-empty list,
an element is popped from the head of the list and returned to the caller
together with the key it was popped from.
Keys are checked in the order that they are given.
Let's say that the key list1 doesn't exist and list2 and list3 hold non-empty lists.
Consider the following command:
BLPOP list1 list2 list3 0
BLPOP guarantees to return an element from the list stored at list2
(since it is the first non empty list when checking list1, list2 and list3 in that order).
Blocking behavior
If none of the specified keys exist or contain non-empty lists,
BLPOP blocks the connection until another client performs an LPUSH or RPUSH operation against one of the lists.
Once new data is present on one of the lists,
the client returns with the name of the key unblocking it and the popped value.
When BLPOP causes a client to block and a non-zero timeout is specified,
the client will unblock returning a nil multi-bulk value when the specified timeout has expired
without a push operation against at least one of the specified keys.
The timeout argument is interpreted as an integer value. A timeout of zero can be used to block indefinitely.
Multiple clients blocking for the same keys
Multiple clients can block for the same key. They are put into a queue, so the first to be served will be
the one that started to wait earlier, in a first-BLPOP first-served fashion.
BLPOP inside a MULTI/EXEC transaction
BLPOP can be used with pipelining (sending multiple commands and reading the replies in batch),
but it does not make sense to use BLPOP inside a MULTI/EXEC block. This would require blocking the entire
server in order to execute the block atomically,
which in turn does not allow other clients to perform a push operation.
The behavior of BLPOP inside MULTI/EXEC when the list is empty is to return a nil multi-bulk reply,
which is the same thing that happens when the timeout is reached. If you like science fiction, think of time flowing at infinite speed inside a MULTI/EXEC block.
- Specified by:
blpop in interface SingleRedisOperations
- Parameters:
timeout - blocking timeout. A timeout of zero can be used to block indefinitely.keys - the keys
- Returns:
- A null when no element could be popped and the timeout expired.
- A two-element multi-bulk with the first element being the name of the key where an element was
popped and the second element being the value of the popped element.
sort
public Long sort(String key,
SortingParams sortingParameters,
String dstkey)
- Specified by:
sort in interface SingleRedisOperations
sort
public Long sort(String key,
String dstkey)
- Specified by:
sort in interface SingleRedisOperations
brpop
public List<String> brpop(int timeout,
String... keys)
- Description copied from interface:
SingleRedisOperations
Time complexity
O(1)
BRPOP is a blocking list pop primitive. It is the blocking version of RPOP 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.
See BLPOP for the exact semantics. BRPOP is identical to BLPOP,
apart from popping from the tail of a list instead of the head of a list.
- Specified by:
brpop in interface SingleRedisOperations
- Parameters:
timeout - blocking timeoutkeys - the keys
- Returns:
- A null when no element could be popped and the timeout expired.
- A two-element multi-bulk with the first element being the name of the key where an element was
popped and the second element being the value of the popped element.
auth
public String auth(String password)
- Specified by:
auth in interface SingleRedisOperations
pipeline
public List<Object> pipeline(Pipeline pipeline)
- Specified by:
pipeline in interface SingleRedisOperations
publish
public Long publish(String channel,
String message)
- Specified by:
publish in interface RedisOperations
getBit
public Long getBit(String key,
int offset)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the bit value at offset in the string value stored at key.
When offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits.
When key does not exist it is assumed to be an empty string, so offset is always out of
range and the value is also assumed to be a contiguous space with 0 bits.
- Specified by:
getBit in interface RedisOperations
- Parameters:
key - the keyoffset - offset in the string value stored at key
- Returns:
- the bit value stored at offset.
setBit
public Long setBit(String key,
int offset,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Sets or clears the bit at offset in the string value stored at key.
The bit is either set or cleared depending on value, which can be either 0 or 1.
When key does not exist, a new string value is created. The string is grown to make sure
it can hold a bit at offset. The offset argument is required to be greater than or equal to 0,
and smaller than 232 (this limits bitmaps to 512MB).
When the string at key is grown, added bits are set to 0.
Warning: When setting the last possible bit (offset equal to 232 -1) and the string value stored at key does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can block the server for some time. On a 2010 Macbook Pro, setting bit number 232 -1 (512MB allocation) takes ~300ms, setting bit number 230 -1 (128MB allocation) takes ~80ms, setting bit number 228 -1 (32MB allocation) takes ~30ms and setting bit number 226 -1 (8MB allocation) takes ~8ms. Note that once this first allocation is done, subsequent calls to SETBIT for the same key will not have the allocation overhead.
- Specified by:
setBit in interface RedisOperations
- Parameters:
key - the keyoffset - the offsetvalue - the value, must be 0 or 1
- Returns:
- the original bit value stored at offset.
zcount
public Long zcount(String key,
Number min,
Number max)
- Description copied from interface:
RedisOperations
- Time complexity
O(log(N)+M) with N being the number of elements in the sorted set and M being the number of elements between min and max.
Returns the number of elements in the sorted set at key with a score between min and max.
The min and max arguments have the same semantic as described for ZRANGEBYSCORE.
- Specified by:
zcount in interface RedisOperations
- Parameters:
key - the keymin - min valuemax - max value
- Returns:
- the number of elements in the specified score range.
zrangeByScore
public List<String> zrangeByScore(String key,
String min,
String max)
- Description copied from interface:
RedisOperations
- 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 between min and max
(including elements with score equal to min or max).
The elements are considered to be ordered from low to high scores.
The elements having the same score are returned in lexicographical order
(this follows from a property of the sorted set implementation in
Redis and does not involve further computation).
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 if offset is large,
the sorted set needs to be traversed for offset elements before getting to the elements
to return, which can add up to O(N) time complexity.
The optional WITHSCORES argument makes the command return both the element and its score,
instead of the element alone. This option is available since Redis 2.0.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know the highest or
lowest score in the sorted set to get all elements from or up to a certain score.
By default, the interval specified by min and max is closed (inclusive).
It is possible to specify an open interval (exclusive) by prefixing the score with the character (.
For example:
ZRANGEBYSCORE zset (1 5
Will return all elements with 1 < score <= 5 while:
ZRANGEBYSCORE zset (5 (10
Will return all the elements with 5 < score < 10 (5 and 10 excluded).
- Specified by:
zrangeByScore in interface RedisOperations
- Parameters:
key - the keymin - min scoremax - max score
- Returns:
- list of elements in the specified score range.
zrangeByScore
public List<String> zrangeByScore(String key,
String min,
String max,
int offset,
int count)
- Description copied from interface:
RedisOperations
- 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 between min and max
(including elements with score equal to min or max).
The elements are considered to be ordered from low to high scores.
The elements having the same score are returned in lexicographical order
(this follows from a property of the sorted set implementation in
Redis and does not involve further computation).
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 if offset is large,
the sorted set needs to be traversed for offset elements before getting to the elements
to return, which can add up to O(N) time complexity.
The optional WITHSCORES argument makes the command return both the element and its score,
instead of the element alone. This option is available since Redis 2.0.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know the highest or
lowest score in the sorted set to get all elements from or up to a certain score.
By default, the interval specified by min and max is closed (inclusive).
It is possible to specify an open interval (exclusive) by prefixing the score with the character (.
For example:
ZRANGEBYSCORE zset (1 5
Will return all elements with 1 < score <= 5 while:
ZRANGEBYSCORE zset (5 (10
Will return all the elements with 5 < score < 10 (5 and 10 excluded).
- Specified by:
zrangeByScore in interface RedisOperations
- Parameters:
key - the keymin - min scoremax - max scoreoffset - limit offsetcount - limit count
- Returns:
- list of elements in the specified score range.
zrangeByScoreWithScores
public List<ElementScore> zrangeByScoreWithScores(String key,
String min,
String max)
- Description copied from interface:
RedisOperations
- 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 between min and max
(including elements with score equal to min or max).
The elements are considered to be ordered from low to high scores.
The elements having the same score are returned in lexicographical order
(this follows from a property of the sorted set implementation in
Redis and does not involve further computation).
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 if offset is large,
the sorted set needs to be traversed for offset elements before getting to the elements
to return, which can add up to O(N) time complexity.
The optional WITHSCORES argument makes the command return both the element and its score,
instead of the element alone. This option is available since Redis 2.0.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know the highest or
lowest score in the sorted set to get all elements from or up to a certain score.
By default, the interval specified by min and max is closed (inclusive).
It is possible to specify an open interval (exclusive) by prefixing the score with the character (.
For example:
ZRANGEBYSCORE zset (1 5
Will return all elements with 1 < score <= 5 while:
ZRANGEBYSCORE zset (5 (10
Will return all the elements with 5 < score < 10 (5 and 10 excluded).
- Specified by:
zrangeByScoreWithScores in interface RedisOperations
- Parameters:
key - the keymin - min scoremax - max score
- Returns:
- list of elements in the specified score range with their scores.
zrangeByScoreWithScores
public List<ElementScore> zrangeByScoreWithScores(String key,
String min,
String max,
int offset,
int count)
- Description copied from interface:
RedisOperations
- 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 between min and max
(including elements with score equal to min or max).
The elements are considered to be ordered from low to high scores.
The elements having the same score are returned in lexicographical order
(this follows from a property of the sorted set implementation in
Redis and does not involve further computation).
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 if offset is large,
the sorted set needs to be traversed for offset elements before getting to the elements
to return, which can add up to O(N) time complexity.
The optional WITHSCORES argument makes the command return both the element and its score,
instead of the element alone. This option is available since Redis 2.0.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know the highest or
lowest score in the sorted set to get all elements from or up to a certain score.
By default, the interval specified by min and max is closed (inclusive).
It is possible to specify an open interval (exclusive) by prefixing the score with the character (.
For example:
ZRANGEBYSCORE zset (1 5
Will return all elements with 1 < score <= 5 while:
ZRANGEBYSCORE zset (5 (10
Will return all the elements with 5 < score < 10 (5 and 10 excluded).
- Specified by:
zrangeByScoreWithScores in interface RedisOperations
- Parameters:
key - the keymin - min scoremax - max scoreoffset - limit offsetcount - limit count
- Returns:
- list of elements in the specified score range (optionally with their scores).
zremrangeByRank
public Long zremrangeByRank(String key,
int start,
int end)
- Description copied from interface:
RedisOperations
- 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 between start and stop.
Both start and stop are 0-based indexes with 0 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 interface RedisOperations
- Parameters:
key - the keystart - range startend - range end
- Returns:
- the number of elements removed.
zremrangeByScore
public Long zremrangeByScore(String key,
String min,
String max)
- Description copied from interface:
RedisOperations
- 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 between min and max (inclusive).
Since version 2.1.6, min and max can be exclusive, following the syntax of ZRANGEBYSCORE.
- Specified by:
zremrangeByScore in interface RedisOperations
- Parameters:
key - the keymin - min scoremax - max score
- Returns:
- the number of elements removed.
zunionstore
public Long zunionstore(String dstkey,
String... sets)
- Description copied from interface:
SingleRedisOperations
- 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 in destination.
It is mandatory to provide the number of input keys (numkeys) before passing the input keys
and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.
Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set.
This means that the score of every element in every input sorted set is multiplied by this factor
before being passed to the aggregation function.
When WEIGHTS is not given, the multiplication factors default to 1.
With the AGGREGATE option, it is possible to specify how the results of the union are aggregated.
This option defaults to SUM, where the score of an element is summed across the inputs where it exists.
When this option is set to either MIN or MAX, the resulting set will contain the minimum or maximum score
of an element across the inputs where it exists.
If destination already exists, it is overwritten.
- Specified by:
zunionstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keysets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zunionstore
public Long zunionstore(String dstkey,
ZParams params,
String... sets)
- Description copied from interface:
SingleRedisOperations
- 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 in destination.
It is mandatory to provide the number of input keys (numkeys) before passing the input keys
and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.
Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set.
This means that the score of every element in every input sorted set is multiplied by this factor
before being passed to the aggregation function.
When WEIGHTS is not given, the multiplication factors default to 1.
With the AGGREGATE option, it is possible to specify how the results of the union are aggregated.
This option defaults to SUM, where the score of an element is summed across the inputs where it exists.
When this option is set to either MIN or MAX, the resulting set will contain the minimum or maximum score
of an element across the inputs where it exists.
If destination already exists, it is overwritten.
- Specified by:
zunionstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keyparams - union paramssets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zinterstore
public Long zinterstore(String dstkey,
String... sets)
- Description copied from interface:
SingleRedisOperations
- 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 in destination. It is mandatory to provide the number of input keys
(numkeys) before passing the input keys and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.
Because intersection requires an element to be a member of every given sorted set,
this results in the score of every element in the resulting sorted set to be equal
to the number of input sorted sets.
For a description of the WEIGHTS and AGGREGATE options, see ZUNIONSTORE.
If destination already exists, it is overwritten.
- Specified by:
zinterstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keysets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zinterstore
public Long zinterstore(String dstkey,
ZParams params,
String... sets)
- Description copied from interface:
SingleRedisOperations
- 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 in destination. It is mandatory to provide the number of input keys
(numkeys) before passing the input keys and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.
Because intersection requires an element to be a member of every given sorted set,
this results in the score of every element in the resulting sorted set to be equal
to the number of input sorted sets.
For a description of the WEIGHTS and AGGREGATE options, see ZUNIONSTORE.
If destination already exists, it is overwritten.
- Specified by:
zinterstore in interface SingleRedisOperations
- Parameters:
dstkey - destination keyparams - the intersection paramssets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
save
public String save()
- Specified by:
save in interface SingleRedisOperations
bgsave
public String bgsave()
- Specified by:
bgsave in interface SingleRedisOperations
bgrewriteaof
public String bgrewriteaof()
- Specified by:
bgrewriteaof in interface SingleRedisOperations
lastsave
public Long lastsave()
- Specified by:
lastsave in interface SingleRedisOperations
shutdown
public String shutdown()
- Specified by:
shutdown in interface SingleRedisOperations
info
public String info()
- Specified by:
info in interface SingleRedisOperations
monitor
public void monitor(RedisMonitor redisMonitor)
- Specified by:
monitor in interface SingleRedisOperations
slaveof
public String slaveof(String host,
int port)
- Specified by:
slaveof in interface SingleRedisOperations
slaveofNoOne
public String slaveofNoOne()
- Specified by:
slaveofNoOne in interface SingleRedisOperations
configGet
public List<String> configGet(String pattern)
- Specified by:
configGet in interface SingleRedisOperations
configSet
public String configSet(String parameter,
String value)
- Specified by:
configSet in interface SingleRedisOperations
strlen
public Long strlen(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Returns the length of the string value stored at key. An error is returned when key holds a non-string value.
- Specified by:
strlen in interface RedisOperations
- Parameters:
key - the key
- Returns:
- the length of the string at key, or 0 when key does not exist.
sync
public void sync()
- Specified by:
sync in interface SingleRedisOperations
lpushx
public Long lpushx(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Inserts value at the head of the list stored at key, only if key already exists and holds a list.
In contrary to LPUSH, no operation will be performed when key does not yet exist.
- Specified by:
lpushx in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the length of the list after the push operation.
persist
public Boolean persist(String key)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Remove the existing timeout on key.
- Specified by:
persist in interface RedisOperations
- Parameters:
key - the key
- Returns:
- true if the timeout was removed otherwise false
rpushx
public Long rpushx(String key,
String value)
- Description copied from interface:
RedisOperations
Time complexity
O(1)
Inserts value at the tail of the list stored at key, only if key already exists and holds a list.
In contrary to RPUSH, no operation will be performed when key does not yet exist.
- Specified by:
rpushx in interface RedisOperations
- Parameters:
key - the keyvalue - the value
- Returns:
- the length of the list after the push operation.
echo
public String echo(String string)
- Specified by:
echo in interface SingleRedisOperations
linsert
public Long linsert(String key,
Client.LIST_POSITION where,
String pivot,
String value)
- Description copied from interface:
RedisOperations
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 at key either before or after the reference value pivot.
When key does not exist, it is considered an empty list and no operation is performed.
An error is returned when key exists but does not hold a list value.
- Specified by:
linsert in interface RedisOperations
- Parameters:
key - the keywhere - list positionpivot - the pivotvalue - the value
- Returns:
- the length of the list after the insert operation, or -1 when the value pivot was not found.
debug
public String debug(DebugParams params)
- Specified by:
debug in interface SingleRedisOperations
Copyright © 2011. All Rights Reserved.