COMMON Introduction

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Introduction

Common Keys

Commands under Common apply to all keys regardless of the 6 data types.
DEL originally belongs to Common, but it is placed under Strings for convenience of explanation.

TYPE added

From redisGate Enterprise ver 8.1.1 (ent811), a type option was added to Common Keys commands.
🟢 Reason: Previously all keys were stored and managed in a single dict (hash table). The problem was that you could not know the key count by type. For example, if there are 1 million keys total, with 500,000 strings, 100,000 lists, and 400,000 hashes, you could not know the count by type. That made it hard to understand the key composition and workload. For this reason, from ent811 the dict (hash table) was split into 6 by type.
📍 type: string/list/set/zset/hash/stream
🟡 Now when you use Common Keys commands such as exists, del, expire, and ttl, please specify the type (string/list/set/zset/hash/stream) so Redis can tell which type the key belongs to.
You can still use them without specifying type, but Redis must search all 6 dicts (hash tables), so performance is lower.
➡ [Updated 2025.08.20(Wed)]

SORT command

A useful command that can sort data that is not already sorted, such as Lists or Sets.
You can also join with other keys to query.
While NoSQL products generally have no join, Redis SORT has a join feature.
Used well, you can get satisfying results.
Go to the SORT command description

Data (key) auto-expire Related commands

This is a data (key) auto-expire feature that RDBMS (relational database systems) do not have, but typical NoSQL products do.
With auto-expire, if you set a time on a key, the key is deleted automatically after that time.
You can set seconds or a specific time, and milliseconds are also possible.
This feature applies to keys only.
Key auto-expire Related commands: EXPIRE, EXPIREAT, TTL, PEXPIRE, EXPIREAT, PTTL, PERSIST

Data (key) copy / move Related commands

Redis creates 16 DBs per instance by default. The command to move a key between DBs is MOVE.
The command to copy/move a key between servers is MIGRATE.

Command summary


Common Keys command list

CommandsVersionSyntaxDescription
EXISTS1.0.0keyCheck whether a key exists
UNLINK1.0.0keyDelete a key
RM6.1.0key (subquery)Delete a key (Enterprise server)
KEYS1.0.0key patternQuery keys by pattern
RENAME1.0.0key new_keyRename a key
RENAMENX1.0.0key new_keyRename a key only if new_key does not exist
EXPIRE1.0.0key secondsDelete the key automatically after the specified seconds
RANDOMKEY1.0.0Query a random key
SORT1.0.0key [BY pattern] [LIMIT offset count]
[GET pattern [GET pattern ...]]
[ASC|DESC] [ALPHA] [STORE destination]
Join with other keys, sort, and query
TTL1.0.0keyQuery remaining expire time (seconds)
TYPE1.0.0keyQuery the data type of a key
EXPIREAT1.2.0key timestampDelete the key automatically at the specified Unix timestamp
PERSIST2.2.0keyRemove expire time
OBJECT2.2.3subcommand keyQuery information about a key
PEXPIRE2.6.0key millisecondsDelete the key automatically after the specified milliseconds
PEXPIREAT2.6.0key milliseconds-timestampDelete the key automatically at the specified Unix milliseconds-timestamp
PTTL2.6.0keyQuery remaining expire time in milliseconds
MOVE1.0.0key dbMove a key to another DB
DUMP2.6.0keyDump data
RESTORE2.6.0key ttl serialized-value [REPLACE]Restore data
MIGRATE2.6.0host port key destination-db
timeout [COPY] [REPLACE]
Move/copy data to another Redis Server
SCAN2.8.0cursor [MATCH pattern]
[COUNT count]
Query keys in batches of a given count

Total : 22

Common keys command description




PDF manual


<< XINFO COMMON Intro EXISTS >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.