com.lordofthejars.nosqlunit.redis.embedded
Class KeysServerOperations

java.lang.Object
  extended by com.lordofthejars.nosqlunit.redis.embedded.KeysServerOperations

public class KeysServerOperations
extends Object


Field Summary
protected static String NONE
           
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

protected static final String NONE
See Also:
Constant Field Values
Method Detail

createKeysServerOperations

public static KeysServerOperations createKeysServerOperations(RedisDatatypeOperations... redisDatatypeOperations)

dbSize

public Long dbSize()
Return the number of keys in the currently selected database.

Returns:
Integer reply

flushAll

public String flushAll()
Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.

Returns:
Status code reply

flushDB

public String flushDB()
Delete all the keys of the currently selected DB. This command never fails.

Returns:
Status code reply

del

public Long del(byte[]... keys)
Remove the specified keys. If a given key does not exist no operation is performed for this key. The command returns the number of keys removed. Time complexity: O(1)

Parameters:
keys -
Returns:
Integer reply, specifically: an integer greater than 0 if one or more keys were removed 0 if none of the specified key existed

exists

public Boolean exists(byte[] key)
Test if the specified key exists. The command returns "1" if the key exists, otherwise "0" is returned. Note that even keys set with an empty string as value will return "1". Time complexity: O(1)

Parameters:
key -
Returns:
Boolean reply, true if the key exists, otherwise false

rename

public String rename(byte[] oldKey,
                     byte[] newKey)
Atomically renames the key oldkey to newkey. If the source and destination name are the same an error is returned. If newkey already exists it is overwritten.

Time complexity: O(1)

Parameters:
oldKey -
newKey -
Returns:
Status code repy

renamenx

public Long renamenx(byte[] oldkey,
                     byte[] newkey)
Rename oldkey into newkey but fails if the destination key newkey already exists.

Time complexity: O(1)

Parameters:
oldkey -
newkey -
Returns:
Integer reply, specifically: 1 if the key was renamed 0 if the target key already exist

expire

public Long expire(byte[] key,
                   int seconds)
Set a timeout on the specified key. After the timeout the key will be automatically deleted by the server. A key with an associated timeout is said to be volatile in Redis terminology.

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)

Parameters:
key -
seconds -
Returns:
Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since the key already has an associated timeout (this may happen only in Redis versions < 2.1.3, Redis >= 2.1.3 will happily update the timeout), or the key does not exist.
See Also:
ExpireCommand

expireAt

public 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).

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)

Parameters:
key -
unixTime -
Returns:
Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since the key already has an associated timeout (this may happen only in Redis versions < 2.1.3, Redis >= 2.1.3 will happily update the timeout), or the key does not exist.
See Also:
ExpireCommand

keys

public Set<byte[]> keys(byte[] patternbyte)
Returns all the keys matching the glob-style pattern as space separated strings. For example if you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return "foo foobar".

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.

Parameters:
pattern -
Returns:
Multi bulk reply

persist

public Long persist(byte[] key)
Undo a expire at turning the expire key into a normal key.

Time complexity: O(1)

Parameters:
key -
Returns:
Integer reply, specifically: 1: the key is now persist. 0: the key is not persist (only happens when key not set).

ttl

public Long ttl(byte[] key)
The TTL command returns the remaining time to live in seconds of a key that has an 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.

Parameters:
key -
Returns:
Integer reply, returns the remaining time to live in seconds of a key that has an EXPIRE. If the Key does not exists or does not have an associated expire, -1 is returned.

type

public String type(byte[] key)
Return the type of the value stored at key in form of a string. The type can be one of "none", "string", "list", "set". "none" is returned if the key does not exist. Time complexity: O(1)

Parameters:
key -
Returns:
Status code reply, specifically: "none" if the key does not exist "string" if the key contains a String value "list" if the key contains a List value "set" if the key contains a Set value "zset" if the key contains a Sorted Set value "hash" if the key contains a Hash value

sort

public List<byte[]> sort(byte[] key)
Sort a Set or a List.

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.

Parameters:
key -
Returns:
Assuming the Set/List at key contains a list of numbers, the return value will be the list of numbers ordered from the smallest to the biggest number.
See Also:
#sort(String, String), #sort(String, SortingParams), #sort(String, SortingParams, String)

updateTtl

public void updateTtl()

updateTtl

public void updateTtl(byte[] key)

move

public Long move(byte[] key,
                 int dbIndex)

objectRefcount

public Long objectRefcount(byte[] string)

objectEncoding

public byte[] objectEncoding(byte[] string)

objectIdletime

public Long objectIdletime(byte[] string)

randomKey

public byte[] randomKey()
Return a randomly selected key from the currently selected DB.

Time complexity: O(1)

Returns:
Singe line reply, specifically the randomly selected key or an empty string is the database is empty

bgrewriteaof

public String bgrewriteaof()

save

public String save()

bgsave

public String bgsave()

configGet

public List<byte[]> configGet(byte[] pattern)
Retrieve the configuration of a running Redis server. Not all the configuration parameters are supported.

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"
 

Parameters:
pattern -
Returns:
Bulk reply.

configSet

public byte[] configSet(byte[] parameter,
                        byte[] value)
Alter the configuration of a running Redis server. Not all the configuration parameters are supported.

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:

Parameters:
parameter -
value -
Returns:
Status code reply

configResetStat

public String configResetStat()
Reset the stats returned by INFO

Returns:

info

public String info()
Provide information and statistics about the server.

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:0
 
Notes

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.

Returns:
Bulk reply

lastsave

public Long lastsave()
Return the UNIX time stamp of the last successfully saving of the dataset on disk.

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.

Returns:
Integer reply, specifically an UNIX time stamp.

monitor

public void monitor(redis.clients.jedis.JedisMonitor jedisMonitor)
Dump all the received requests in real time.

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.

Parameters:
jedisMonitor -

shutdown

public String shutdown()
Synchronously save the DB on disk, then shutdown the server.

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.

Returns:
Status code reply on error. On success nothing is returned since the server quits and the connection is closed.

slaveof

public String slaveof(String host,
                      int port)
Change the replication settings.

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.

Parameters:
host -
port -
Returns:
Status code reply

slaveofNoOne

public String slaveofNoOne()

slowlogGet

public List<redis.clients.util.Slowlog> slowlogGet()

slowlogGet

public List<redis.clients.util.Slowlog> slowlogGet(long entries)

slowlogReset

public byte[] slowlogReset()

slowlogLen

public long slowlogLen()

slowlogGetBinary

public List<byte[]> slowlogGetBinary()

slowlogGetBinary

public List<byte[]> slowlogGetBinary(long entries)

sync

public void sync()

time

public Long time()

getDB

public Long getDB()

isConnected

public boolean isConnected()


Copyright © 2012. All Rights Reserved.