Cheat Sheet #day2 - Redis Commands

Cheat Sheet #day2 - Redis Commands

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Key Commands:

    • DEL key: Deletes a key.
    • EXISTS key: Checks if a key exists.
    • EXPIRE key seconds: Sets a timeout on a key.
  7. Transaction Commands:

    • MULTI: Marks the start of a transaction block.
    • EXEC: Executes all commands issued after MULTI.
    • DISCARD: Discards all commands issued after MULTI.
  8. Pub/Sub Commands:

    • PUBLISH channel message: Publishes a message to a channel.
    • SUBSCRIBE channel: Subscribes to a channel to receive messages.
  9. Connection Commands:

    • PING: Tests if a connection to the server is still alive.
    • AUTH password: Authenticates to the server with a password.

Did you find this article valuable?

Support Cloud Tuned by becoming a sponsor. Any amount is appreciated!