Please wait...

小波Note

四川 · 成都市13 ℃
English

Redis Common Commands

成都 (cheng du)8/28/2024, 12:24:25 AM4.21kEstimated reading time 14 minFavoriteCtrl + D / ⌘ + D
cover
IT FB(up 主)
Back-end development engineer

Here are some common Redis commands and their explanations

Strings

SET key value: Set the value of the specified key.

GET key: Get the value of the specified key.

DEL key: Delete the specified key.

INCR key: Increment the value of the specified key by 1 (assuming the value is an integer).

DECR key: Decrement the value of the specified key by 1 (assuming the value is an integer).

Hashes

HSET key field value: Set the value of the field in the hash table key.

HGET key field: Get the value of the field in the hash table key.

HDEL key field: Delete one or more specified fields in the hash table key.

HGETALL key: Get all fields and values in the hash table key.

Lists

LPUSH key value: Insert a value at the head of the list key.

RPUSH key value: Insert a value at the tail of the list key.

LPOP key: Remove and return the head element of the list key.

RPOP key: Remove and return the tail element of the list key.

LRANGE key start stop: Get elements within the specified range from the list key.

Sets

SADD key member: Add a member to the set key.

SREM key member: Remove a member from the set key.

SMEMBERS key: Return all members of the set key.

SISMEMBER key member: Check if the member is part of the set key.

Sorted Sets

ZADD key score member: Add a member and its score to the sorted set key.

ZREM key member: Remove a member from the sorted set key.

ZRANGE key start stop: Return members within the specified range from the sorted set key.

ZRANGEBYSCORE key min max: Return members within the specified score range from the sorted set key.

Keys

EXISTS key: Check if the key exists.

DEL key: Delete the key.

EXPIRE key seconds: Set the expiration time for the key.

TTL key: Get the remaining expiration time of the key.

KEYS pattern: Find all keys matching the given pattern.

Connection

AUTH password: Authenticate with the password.

PING: Check if the server is running.

QUIT: Close the connection.

Server

INFO: Get information and statistics about the server.

DBSIZE: Get the number of keys in the current database.

FLUSHDB: Delete all keys in the current database.

FLUSHALL: Delete all keys in all databases.

Publish and Subscribe

PUBLISH channel message: Send a message to the channel.

SUBSCRIBE channel: Subscribe to one or more channels.

UNSUBSCRIBE [channel [channel ...]]: Unsubscribe from one or more channels.

Transactions

MULTI: Mark the start of a transaction block.

EXEC: Execute all commands in the transaction block.

DISCARD: Cancel the transaction, discarding all commands in the transaction block.

Scripting

EVAL script numkeys key [key ...] arg [arg ...]: Execute a Lua script.

Client

CLIENT LIST: Get the list of clients connected to the server.

CLIENT KILL ip:port: Close a client connection.

CLIENT SETNAME connection-name: Set the name of the current connection.

Configuration

CONFIG GET parameter: Get the value of a configuration parameter.

CONFIG SET parameter value: Set the value of a configuration parameter.

Other

ECHO message: Print a message.

SELECT index: Switch to the specified database.

MOVE key db: Move the key to the specified database.

RENAME key newkey: Rename the key.

TYPE key: Return the data type of the key.