website/docs/commands/generic-commands.md
AUTH <placeholderforpassword>
Authenticates the connection.
Simple string reply: OK, or an error if the password, or username/password pair, is invalid.
Security notice:
Only use strong and long passwords so an attack is infeasible. A better way to manage authentication will be using the ACL feature.
ECHO <message>
Returns message.
Bulk string reply: the given string.
HELLO [protover [AUTH username password] [SETNAME clientname]]
Switch to a different protocol, optionally authenticating and setting the connection's name, or provide a contextual client report.
When called with the optional protover argument, this command switches the protocol to the specified version and also accepts the following options:
AUTH <username> <password>: directly authenticate the connection in addition to switching to the specified protocol version. This makes calling AUTH before HELLO unnecessary when setting up a new connection. Note that the username can be set to "default" to authenticate against a server that does not use ACLs, but rather the simpler requirepass mechanism of Redis prior to version 6.
SETNAME <clientname>: this is the equivalent of calling CLIENT SETNAME.
Map reply: a list of server properties. Simple error reply: if the protover requested does not exist.
PING key
Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk string.
Any of the following:
QUIT
Ask the server to close the connection. The connection is close when all pending replies have been written to the client.
Simple string reply: OK.
SELECT
Select the Redis logical database having the specified zero-based numeric index. New connections always use the database 0.
Simple string reply: OK.
DEL key [key ...]
Removes the specified keys. A key is ignored if it does not exist.
Integer reply: the number of keys that were removed.
EXISTS key [key ...]
Determines whether one or more keys exist. If the same existing key is mentioned in the arguments multiple times, it will be counted multiple times. So if foo exists, EXISTS foo foo will return 2.
Integer reply: the number of keys that exist from those specified as arguments.
EXPIRE key seconds [NX | XX | GT | LT]
Set a timeout on key in seconds. After the timeout has expired, the key will automatically be deleted.
The EXPIRE command supports a set of options:
NX -- Set expiry only when the key has no expiryXX -- Set expiry only when the key has an existing expiryGT -- Set expiry only when the new expiry is greater than current oneLT -- Set expiry only when the new expiry is less than current oneThe GT, LT and NX options are mutually exclusive.
One of the following:
EXPIREAT key seconds [NX | XX | GT | LT]
Set a timeout on key using absolute Unix timestamp (seconds since January 1, 1970) in seconds. After the timestamp, the key will automatically be deleted.
The EXPIREAT command supports a set of options:
NX -- Set expiry only when the key has no expiryXX -- Set expiry only when the key has an existing expiryGT -- Set expiry only when the new expiry is greater than current oneLT -- Set expiry only when the new expiry is less than current oneThe GT, LT and NX options are mutually exclusive.
One of the following:
EXPIRETIME key
Returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire.
One of the following:
KEYS pattern
Returns all keys matching pattern.
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.
Examples of supported patterns:
Use \ to escape special characters if you want to match them verbatim.
Array reply: a list of keys matching pattern.
TODO: Verify syntax and functionality
PERSIST key
Removes the existing timeout on a key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).
PEXPIRE key milliseconds [NX | XX | GT | LT]
This command works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.
One of the following:
PEXPIRETIME key
Returns the absolute Unix timestamp (since January 1, 1970) in milliseconds at which the given key will expire.
One of the following:
PEXPIREAT key seconds [NX | XX | GT | LT]
Set a timeout on key using absolute Unix timestamp (seconds since January 1, 1970) in milliseconds. After the timestamp, the key will automatically be deleted.
The PEXPIREAT command supports a set of options:
NX -- Set expiry only when the key has no expiryXX -- Set expiry only when the key has an existing expiryGT -- Set expiry only when the new expiry is greater than current oneLT -- Set expiry only when the new expiry is less than current oneThe GT, LT and NX options are mutually exclusive.
One of the following:
PTTL key
Like TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.
One of the following:
RENAME key newkey [WITHETAG]
Renames key to newkey. It returns an error when key does not exist. If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation.
Simple string reply: OK.
RENAMENX key newkey [WITHETAG]
Renames key to newkey if newkey does not yet exist. It returns an error when key does not exist.
One of the following:
SCAN cursor [MATCH pattern] [COUNT count] [TYPE type]
Iterates over the keys that exist in the store and returns only the ones matching the selected filters.
The MATCH option It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the KEYS command that takes a pattern as its only argument.
The TYPE option You can use the TYPE option to ask SCAN to only return objects that match a given type, allowing you to iterate through the database looking for keys of a specific type.
The COUNT option
The default COUNT value is 10, but the user is free to change it.
Array reply: specifically, an array with two elements.
TTL key
Returns the remaining time to live of a key that has a timeout.
One of the following:
TYPE key
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.
Simple string reply: the type of key, or none when key doesn't exist.
This command is very similar to DEL: it removes the specified keys. Just like DEL a key is ignored if it does not exist. However the command performs the actual memory reclaiming in a different thread, so it is not blocking, while DEL is.
Integer reply: the number of keys that were unlinked.
[!IMPORTANT]
DUMP currently only supports string types without lzf compression
DUMP mykey
Serialize the value stored at key in a Redis-specific format and return it to the user. The returned value can be synthesized back into a Redis key using the RESTORE command.
String reply: The serialization format is opaque and non-standard, however it has a few semantic characteristics:
[!IMPORTANT]
RESTORE currently only supports string types without lzf compression
restore mykey 0 "\x00\x0evallllllllllll\x0b\x00|\xeb\xe2|\xd2.\xfa7"
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via DUMP).
If ttl is 0 the key is created without any expire, otherwise the specified expire time (in milliseconds) is set.
Simple string reply: OK.