Redis 简明教程
Redis - Keys
Redis keys 命令用于管理 Redis 中的键。以下是使用 redis keys 命令的语法。
Redis keys commands are used for managing keys in Redis. Following is the syntax for using redis keys commands.
Example
redis 127.0.0.1:6379> SET tutorialspoint redis
OK
redis 127.0.0.1:6379> DEL tutorialspoint
(integer) 1
在以上示例中, DEL 是命令,而 tutorialspoint 是键。如果删除了键,则该命令的输出将为 (整数) 1,否则为 (整数) 0。
In the above example, DEL is the command, while tutorialspoint is the key. If the key is deleted, then the output of the command will be (integer) 1, otherwise it will be (integer) 0.
Redis Keys Commands
下表列出了与键相关的一些基本命令。
Following table lists some basic commands related to keys.
Sr.No |
Command & Description |
1 |
DEL keyThis command deletes the key, if it exists. |
2 |
DUMP keyThis command returns a serialized version of the value stored at the specified key. |
3 |
EXISTS keyThis command checks whether the key exists or not. |
4 |
EXPIRE key seconds Sets the expiry of the key after the specified time. |
5 |
EXPIREAT key timestampSets the expiry of the key after the specified time. Here time is in Unix timestamp format. |
6 |
PEXPIRE key millisecondsSet the expiry of key in milliseconds. |
7 |
PEXPIREAT key milliseconds-timestampSets the expiry of the key in Unix timestamp specified as milliseconds. |
8 |
KEYS patternFinds all keys matching the specified pattern. |
9 |
MOVE key dbMoves a key to another database. |
10 |
PERSIST keyRemoves the expiration from the key. |
11 |
PTTL keyGets the remaining time in keys expiry in milliseconds. |
12 |
TTL keyGets the remaining time in keys expiry. |
13 |
RANDOMKEYReturns a random key from Redis. |
14 |
RENAME key newkeyChanges the key name. |
15 |
RENAMENX key newkeyRenames the key, if a new key doesn’t exist. |
16 |
TYPE keyReturns the data type of the value stored in the key. |