Set Data type in Redis
Set Data Types in Redis is an un-ordered collection of unique strings. it can be used to detect unique elements in a list, also for intersections, unions, and differences.
Basic Commands used in Set Data types in Redis
- SADD: This command is used to add a new element to the set.
- SREM: This command will remove the specified element from set.
- SISMEMBER: This command will tests a string for test membership.
- SINTER: this command will return the intersection of lists.
- SCARD: This command will return the size of the set.
- SMEMBERS : This command will return all the members of the set value stored at key.
Example:
SADD user: GFG name: Ankit
SADD user: GFG name: Aditya
SADD user: GFG name: Aarohi
SMEMBERS user: GFGOutput:
1) Ankit
2) Aditya
3) Aarohi
Note: The max size of a Redis set is 2^32 – 1 (4,294,967,295) members.
How Redis Stores Set Data Types?
- Sets are implemented as an unordered collection of unique elements.
- Redis uses an optimized data structure to ensure that elements in a set are unique.
- Set operations like union, intersection, and difference are efficient.
Complete Guide on Redis Data Types with Commands and Storage
Redis is an open-source, in-memory data store that supports various data types: such as String, Sets, Lists, Hashes, etc. to store data according to the needs of the user. These diverse data types make Redis versatile for caching, messaging, real-time analytics, and more.
Different Data Types in Redis
- 1. String Data Type in Redis
- 2. Hash Data type in Redis
- 3. List Data Type in Redis
- 4. Set Data type in Redis:
- 5. Sorted Set in Redis:
- 6. Streams in Redis:
- 7. HyperLogLog in Redis:
- 8. Bitmaps in Redis:
- 9. Bitfields in Redis
- 10. Probabilistic in Redis:
- 11. Geospatial Indexes in Redis:
- 12. Time-Series in Redis
Contact Us