Show List

Data types in Redis

Here are some of the data types in Redis along with some examples:

  • Strings: The simplest data type in Redis, a string can hold any binary data, such as a serialized object or JSON data. Examples:

sql
Copy code
SET name "John" GET name
  • Lists: A list in Redis is a collection of ordered elements, where each element can be any string. Examples:

  • Copy code
    LPUSH numbers 1 2 3 RPUSH numbers 4 5 6 LRANGE numbers 0 -1
  • Sets: A set is an unordered collection of unique strings. Examples:

  • python
    Copy code
    SADD fruits "apple" "banana" "orange" SISMEMBER fruits "banana" SMEMBERS fruits
  • Hashes: A hash in Redis is a collection of key-value pairs, where each key is a string and each value can be any string. Examples:

  • sql
    Copy code
    HSET user id 1 name "John" age 25 HGETALL user
  • Sorted Sets: A sorted set in Redis is similar to a regular set, but each element is associated with a score, which is used to order the elements. Examples:

  • python
    Copy code
    ZADD scores 90 "Alice" 80 "Bob" 95 "Charlie" ZRANGE scores 0 -1 WITHSCORES

        Leave a Comment


    • captcha text