com.lordofthejars.nosqlunit.redis.embedded
public class KeysServerOperations extends Object
| Modifier and Type | Method and Description |
|---|---|
String |
bgrewriteaof() |
String |
bgsave() |
List<byte[]> |
configGet(byte[] pattern)
Retrieve the configuration of a running Redis server.
|
String |
configResetStat()
Reset the stats returned by INFO
|
byte[] |
configSet(byte[] parameter,
byte[] value)
Alter the configuration of a running Redis server.
|
static KeysServerOperations |
createKeysServerOperations(RedisDatatypeOperations... redisDatatypeOperations) |
Long |
dbSize()
Return the number of keys in the currently selected database.
|
Long |
del(byte[]... keys)
Remove the specified keys.
|
Boolean |
exists(byte[] key)
Test if the specified key exists.
|
Long |
expire(byte[] key,
int seconds)
Set a timeout on the specified key.
|
Long |
expireAt(byte[] key,
long unixTime)
EXPIREAT works exctly like
EXPIRE but
instead to get the number of seconds representing the Time To Live of the
key as a second argument (that is a relative way of specifing the TTL),
it takes an absolute one in the form of a UNIX timestamp (Number of
seconds elapsed since 1 Gen 1970). |
String |
flushAll()
Delete all the keys of all the existing databases, not just the currently
selected one.
|
String |
flushDB()
Delete all the keys of the currently selected DB.
|
Long |
getDB() |
String |
info()
Provide information and statistics about the server.
|
boolean |
isConnected() |
Set<byte[]> |
keys(byte[] patternbyte)
Returns all the keys matching the glob-style pattern as space separated
strings.
|
Long |
lastsave()
Return the UNIX time stamp of the last successfully saving of the dataset
on disk.
|
void |
monitor(redis.clients.jedis.JedisMonitor jedisMonitor)
Dump all the received requests in real time.
|
Long |
move(byte[] key,
int dbIndex) |
byte[] |
objectEncoding(byte[] string) |
Long |
objectIdletime(byte[] string) |
Long |
objectRefcount(byte[] string) |
Long |
persist(byte[] key)
Undo a
expire at turning the expire key into
a normal key. |
byte[] |
randomKey()
Return a randomly selected key from the currently selected DB.
|
String |
rename(byte[] oldKey,
byte[] newKey)
Atomically renames the key oldkey to newkey.
|
Long |
renamenx(byte[] oldkey,
byte[] newkey)
Rename oldkey into newkey but fails if the destination key newkey already
exists.
|
String |
save() |
String |
shutdown()
Synchronously save the DB on disk, then shutdown the server.
|
String |
slaveof(String host,
int port)
Change the replication settings.
|
String |
slaveofNoOne() |
List<redis.clients.util.Slowlog> |
slowlogGet() |
List<redis.clients.util.Slowlog> |
slowlogGet(long entries) |
List<byte[]> |
slowlogGetBinary() |
List<byte[]> |
slowlogGetBinary(long entries) |
long |
slowlogLen() |
byte[] |
slowlogReset() |
List<byte[]> |
sort(byte[] key)
Sort a Set or a List.
|
void |
sync() |
Long |
time() |
Long |
ttl(byte[] key)
The TTL command returns the remaining time to live in seconds of a key
that has an
EXPIRE set. |
String |
type(byte[] key)
Return the type of the value stored at key in form of a string.
|
void |
updateTtl() |
void |
updateTtl(byte[] key) |
protected static final String NONE
public static KeysServerOperations createKeysServerOperations(RedisDatatypeOperations... redisDatatypeOperations)
public Long dbSize()
public String flushAll()
public String flushDB()
public Long del(byte[]... keys)
keys - public Boolean exists(byte[] key)
key - public String rename(byte[] oldKey, byte[] newKey)
Time complexity: O(1)
oldKey - newKey - public Long renamenx(byte[] oldkey, byte[] newkey)
Time complexity: O(1)
oldkey - newkey - public Long expire(byte[] key, int seconds)
Voltile keys are stored on disk like the other keys, the timeout is persistent too like all the other aspects of the dataset. Saving a dataset containing expires and stopping the server does not stop the flow of time as Redis stores on disk the time when the key will no longer be available as Unix time, and not the remaining seconds.
Since Redis 2.1.3 you can update the value of the timeout of a key
already having an expire set. It is also possible to undo the expire at
all turning the key into a normal key using the PERSIST command.
Time complexity: O(1)
key - seconds - public Long expireAt(byte[] key, long unixTime)
EXPIRE but
instead to get the number of seconds representing the Time To Live of the
key as a second argument (that is a relative way of specifing the TTL),
it takes an absolute one in the form of a UNIX timestamp (Number of
seconds elapsed since 1 Gen 1970).
EXPIREAT was introduced in order to implement the Append Only File persistence mode so that EXPIRE commands are automatically translated into EXPIREAT commands for the append only file. Of course EXPIREAT can also used by programmers that need a way to simply specify that a given key should expire at a given time in the future.
Since Redis 2.1.3 you can update the value of the timeout of a key
already having an expire set. It is also possible to undo the expire at
all turning the key into a normal key using the PERSIST command.
Time complexity: O(1)
key - unixTime - public Set<byte[]> keys(byte[] patternbyte)
Note that while the time complexity for this operation is O(n) the constant times are pretty low. For example Redis running on an entry level laptop can scan a 1 million keys database in 40 milliseconds. Still it's better to consider this one of the slow commands that may ruin the DB performance if not used with care.
In other words this command is intended only for debugging and special operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis Sets in order to group together a subset of objects.
Glob style patterns examples:
Use \ to escape special chars if you want to match them verbatim.
pattern - public Long persist(byte[] key)
expire at turning the expire key into
a normal key.
Time complexity: O(1)
key - public Long ttl(byte[] key)
EXPIRE set. This introspection
capability allows a Redis client to check how many seconds a given key
will continue to be part of the dataset.key - public String type(byte[] key)
key - public List<byte[]> sort(byte[] key)
Sort the elements contained in the List, Set, or Sorted Set value at key. By default sorting is numeric with elements being compared as double precision floating point numbers. This is the simplest form of SORT.
key - #sort(String, String),
#sort(String, SortingParams),
#sort(String, SortingParams, String)public void updateTtl()
public void updateTtl(byte[] key)
public Long move(byte[] key, int dbIndex)
public Long objectRefcount(byte[] string)
public byte[] objectEncoding(byte[] string)
public Long objectIdletime(byte[] string)
public byte[] randomKey()
Time complexity: O(1)
public String bgrewriteaof()
public String save()
public String bgsave()
public List<byte[]> configGet(byte[] pattern)
CONFIG GET returns the current configuration parameters. This sub command only accepts a single argument, that is glob style pattern. All the configuration parameters matching this parameter are reported as a list of key-value pairs.
Example:
$ redis-cli config get '*' 1. "dbfilename" 2. "dump.rdb" 3. "requirepass" 4. (nil) 5. "masterauth" 6. (nil) 7. "maxmemory" 8. "0\n" 9. "appendfsync" 10. "everysec" 11. "save" 12. "3600 1 300 100 60 10000" $ redis-cli config get 'm*' 1. "masterauth" 2. (nil) 3. "maxmemory" 4. "0\n"
pattern - public byte[] configSet(byte[] parameter,
byte[] value)
The list of configuration parameters supported by CONFIG SET can be
obtained issuing a CONFIG GET * command.
The configuration set using CONFIG SET is immediately loaded by the Redis server that will start acting as specified starting from the next command.
Parameters value format
The value of the configuration parameter is the same as the one of the same parameter in the Redis configuration file, with the following exceptions:
parameter - value - public String configResetStat()
public String info()
The info command returns different information and statistics about the server in an format that's simple to parse by computers and easy to read by humans.
Format of the returned String:
All the fields are in the form field:value
edis_version:0.07 connected_clients:1 connected_slaves:0 used_memory:3187 changes_since_last_save:0 last_save_time:1237655729 total_connections_received:1 total_commands_processed:1 uptime_in_seconds:25 uptime_in_days:0Notes
used_memory is returned in bytes, and is the total number of bytes allocated by the program using malloc.
uptime_in_days is redundant since the uptime in seconds contains already the full uptime information, this field is only mainly present for humans.
changes_since_last_save does not refer to the number of key changes, but to the number of operations that produced some kind of change in the dataset.
public Long lastsave()
Return the UNIX TIME of the last DB save executed with success. A client
may check if a BGSAVE command succeeded reading the
LASTSAVE value, then issuing a BGSAVE command and checking at regular
intervals every N seconds if LASTSAVE changed.
public void monitor(redis.clients.jedis.JedisMonitor jedisMonitor)
MONITOR is a debugging command that outputs the whole sequence of commands received by the Redis server. is very handy in order to understand what is happening into the database. This command is used directly via telnet.
jedisMonitor - public String shutdown()
Stop all the clients, save the DB, then quit the server. This commands
makes sure that the DB is switched off without the lost of any data. This
is not guaranteed if the client uses simply SAVE and then
QUIT because other clients may alter the DB data between
the two commands.
public String slaveof(String host, int port)
The SLAVEOF command can change the replication settings of a slave on the fly. If a Redis server is arleady acting as slave, the command SLAVEOF NO ONE will turn off the replicaiton turning the Redis server into a MASTER. In the proper form SLAVEOF hostname port will make the server a slave of the specific server listening at the specified hostname and port.
If a server is already a slave of some master, SLAVEOF hostname port will stop the replication against the old server and start the synchrnonization against the new one discarding the old dataset.
The form SLAVEOF no one will stop replication turning the server into a MASTER but will not discard the replication. So if the old master stop working it is possible to turn the slave into a master and set the application to use the new master in read/write. Later when the other Redis server will be fixed it can be configured in order to work as slave.
host - port - public String slaveofNoOne()
public List<redis.clients.util.Slowlog> slowlogGet()
public List<redis.clients.util.Slowlog> slowlogGet(long entries)
public byte[] slowlogReset()
public long slowlogLen()
public List<byte[]> slowlogGetBinary()
public List<byte[]> slowlogGetBinary(long entries)
public void sync()
public Long time()
public Long getDB()
public boolean isConnected()
Copyright © 2014. All Rights Reserved.