org.idevlab.rjc
Interface SingleRedisOperations
- All Superinterfaces:
- RedisOperations
- All Known Subinterfaces:
- Session
- All Known Implementing Classes:
- RedisNode
public interface SingleRedisOperations
- extends RedisOperations
- Author:
- Evgeny Dolgov
|
Method Summary |
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)
|
String |
echo(String string)
|
String |
flushAll()
|
String |
flushDB()
|
String |
info()
|
Long |
lastsave()
|
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. |
String |
ping()
|
List<Object> |
pipeline(Pipeline pipeline)
|
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 |
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. |
String |
save()
|
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 |
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. |
String |
slaveof(String host,
int port)
|
String |
slaveofNoOne()
|
Boolean |
smove(String srckey,
String dstkey,
String member)
Time complexity
O(1)
Move member from the set at source to the set at destination. |
Long |
sort(String key,
SortingParams sortingParameters,
String dstkey)
|
Long |
sort(String key,
String dstkey)
|
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 |
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. |
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 interface org.idevlab.rjc.RedisOperations |
append, decr, decrBy, del, exists, expire, expireAt, get, getBit, getRange, getSet, hdel, hexists, hget, hgetAll, hincrBy, hkeys, hlen, hmget, hmset, hset, hsetnx, hvals, incr, incrBy, keys, lindex, linsert, llen, lpop, lpush, lpushx, lrange, lrem, lset, ltrim, persist, publish, rpop, rpush, rpushx, sadd, scard, set, setBit, setex, setnx, setRange, sismember, smembers, sort, sort, spop, srandmember, srem, strlen, ttl, type, zadd, zcard, zcount, zincrby, zrange, zrangeByScore, zrangeByScore, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeWithScores, zrank, zrem, zremrangeByRank, zremrangeByScore, zrevrange, zrevrangeByScore, zrevrangeByScore, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeWithScores, zrevrank, zscore |
ping
String ping()
randomKey
String randomKey()
Time complexity
O(1)
Return a random key from the currently selected database.
- Returns:
- the random key, or null when the database is empty.
quit
void quit()
flushDB
String flushDB()
rename
String rename(String key,
String newKey)
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.
- Parameters:
key - a keynewKey - new key
- Returns:
- status code reply
renamenx
Boolean renamenx(String key,
String newKey)
Time complexity
O(1)
Renames key to newKey if newKey does not yet exist. It returns an error under the same conditions as RENAME.
- Parameters:
key - a keynewKey - new key
- Returns:
- true if key was renamed to newKey or false if newKey already exists
dbSize
Long dbSize()
move
Boolean move(String key,
int dbIndex)
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.
- Parameters:
key - a keydbIndex - database index
- Returns:
- true if key was moved otherwise false
flushAll
String flushAll()
mget
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. 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.
- Parameters:
keys - the keys
- Returns:
- list of values at the specified keys.
mset
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. 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.
- Parameters:
keysvalues - array of keys and values, for instance {"key1", "value1", "key2", "value2"}
- Returns:
- always OK since MSET can't fail.
msetnx
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. 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.
- 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).
rpoplpush
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.
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.
- Parameters:
srckey - source keydstkey - destination key
- Returns:
- the element being popped and pushed.
brpoplpush
String brpoplpush(String source,
String destination,
int timeout)
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.
- 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.
smove
Boolean smove(String srckey,
String dstkey,
String member)
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.
- 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.
sinter
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.
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).
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sinterstore
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.
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.
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- the number of elements in the resulting set.
sunion
Set<String> sunion(String... keys)
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.
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sunionstore
Long sunionstore(String dstkey,
String... keys)
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.
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- he number of elements in the resulting set.
sdiff
Set<String> sdiff(String... keys)
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.
- Parameters:
keys - the keys
- Returns:
- list with members of the resulting set.
sdiffstore
Long sdiffstore(String dstkey,
String... keys)
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.
- Parameters:
dstkey - destination keykeys - the keys
- Returns:
- the number of elements in the resulting set.
blpop
List<String> blpop(int timeout,
String... keys)
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.
- 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
Long sort(String key,
SortingParams sortingParameters,
String dstkey)
sort
Long sort(String key,
String dstkey)
brpop
List<String> brpop(int timeout,
String... keys)
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.
- 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
String auth(String password)
pipeline
List<Object> pipeline(Pipeline pipeline)
zunionstore
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.
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.
- Parameters:
dstkey - destination keysets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zunionstore
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.
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.
- Parameters:
dstkey - destination keyparams - union paramssets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zinterstore
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.
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.
- Parameters:
dstkey - destination keysets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
zinterstore
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.
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.
- Parameters:
dstkey - destination keyparams - the intersection paramssets - the keys
- Returns:
- the number of elements in the resulting sorted set at destination.
save
String save()
bgsave
String bgsave()
bgrewriteaof
String bgrewriteaof()
lastsave
Long lastsave()
shutdown
String shutdown()
info
String info()
monitor
void monitor(RedisMonitor redisMonitor)
slaveof
String slaveof(String host,
int port)
slaveofNoOne
String slaveofNoOne()
configGet
List<String> configGet(String pattern)
configSet
String configSet(String parameter,
String value)
sync
void sync()
echo
String echo(String string)
debug
String debug(DebugParams params)
Copyright © 2011. All Rights Reserved.