📜  Redis-键

📅  最后修改于: 2020-11-26 07:01:40             🧑  作者: Mango


Redis keys命令用于管理Redis中的密钥。以下是使用redis keys命令的语法。

句法

redis 127.0.0.1:6379> COMMAND KEY_NAME

redis 127.0.0.1:6379> SET tutorialspoint redis 
OK 
redis 127.0.0.1:6379> DEL tutorialspoint 
(integer) 1

在上面的示例中, DEL是命令,而tutorialspoint是键。如果键被删除,则命令的输出将为(整数)1,否则将为(整数)0。

Redis键命令

下表列出了一些与按键有关的基本命令。

Sr.No Command & Description
1 DEL key

This command deletes the key, if it exists.

2 DUMP key

This command returns a serialized version of the value stored at the specified key.

3 EXISTS key

This 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 timestamp

Sets the expiry of the key after the specified time. Here time is in Unix timestamp format.

6 PEXPIRE key milliseconds

Set the expiry of key in milliseconds.

7 PEXPIREAT key milliseconds-timestamp

Sets the expiry of the key in Unix timestamp specified as milliseconds.

8 KEYS pattern

Finds all keys matching the specified pattern.

9 MOVE key db

Moves a key to another database.

10 PERSIST key

Removes the expiration from the key.

11 PTTL key

Gets the remaining time in keys expiry in milliseconds.

12 TTL key

Gets the remaining time in keys expiry.

13 RANDOMKEY

Returns a random key from Redis.

14 RENAME key newkey

Changes the key name.

15 RENAMENX key newkey

Renames the key, if a new key doesn’t exist.

16 TYPE key

Returns the data type of the value stored in the key.