Redis commands are the fundamental building blocks for interacting with Redis, an open-source, in-memory data structure store used as a database, cache, and message broker. These commands enable users to perform a wide range of operations on Redis data structures such as strings, hashes, lists, sets, and sorted sets. Here are some key Redis commands and their uses:
Key Redis Commands:
String Commands:
SET key value
: Sets the value of a key.GET key
: Retrieves the value of a key.INCR key
: Increments the integer value of a key by one.
Hash Commands:
HSET key field value
: Sets the value of a field in a hash.HGET key field
: Retrieves the value of a field in a hash.HGETALL key
: Retrieves all fields and values in a hash.
List Commands:
LPUSH key value
: Inserts a value at the head of a list.RPUSH key value
: Inserts a value at the tail of a list.LPOP key
: Removes and returns the first element of a list.LRANGE key start stop
: Retrieves a range of elements from a list.
Set Commands:
SADD key member
: Adds a member to a set.SMEMBERS key
: Retrieves all members of a set.SREM key member
: Removes a member from a set.
Sorted Set Commands:
ZADD key score member
: Adds a member to a sorted set, or updates its score if it already exists.ZRANGE key start stop [WITHSCORES]
: Retrieves a range of members in a sorted set, optionally with scores.ZREM key member
: Removes a member from a sorted set.
Key Commands:
DEL key
: Deletes a key.EXISTS key
: Checks if a key exists.EXPIRE key seconds
: Sets a timeout on a key.
Transaction Commands:
MULTI
: Marks the start of a transaction block.EXEC
: Executes all commands issued after MULTI.DISCARD
: Discards all commands issued after MULTI.
Pub/Sub Commands:
PUBLISH channel message
: Publishes a message to a channel.SUBSCRIBE channel
: Subscribes to a channel to receive messages.
Connection Commands:
PING
: Tests if a connection to the server is still alive.AUTH password
: Authenticates to the server with a password.