link: Redis
Redis Data Structures
Redis supports a variety of data structures, each suited for different use cases. Here are the main data structures supported by Redis, along with examples for each.
Overview
Data Structures
- Strings: The simplest type of value, can hold any type of data including binary.
- Hashes: Ideal for storing objects and user profiles.
- Lists: Ordered collections of strings, useful for queues.
- Sets: Unordered collections of unique strings, ideal for relationships and tags.
- Sorted Sets: Like sets but with an associated score, useful for leaderboards.
- Bitmaps: For bit-level operations.
- HyperLogLogs: For approximate counting of unique items.
Details
Strings
Strings are the simplest Redis data type, holding any kind of data, such as text or binary.
Example:
Hashes
Hashes are maps between string fields and string values, ideal for storing objects.
Example:
Lists
Lists are ordered collections of strings. They are useful for implementing queues.
Example:
Sets
Sets are unordered collections of unique strings, useful for managing relationships.
Example:
Sorted Sets
Sorted sets are similar to sets but with an associated score for each member, used for ranking.
Example:
Bitmaps
Bitmaps are used for bit-level operations.
Example:
SETBIT mybitmap 10 1 GETBIT mybitmap 10
HyperLogLogs
HyperLogLogs are used for approximating the cardinality of a set, or counting unique items.
Example: