0
0
Redisquery~3 mins

SMEMBERS to list all in Redis

Choose your learning style9 modes available
Introduction
SMEMBERS helps you see all the items stored in a set. It shows everything inside that group without any order.
You want to see all unique tags a user has added to their profile.
You need to list all online users stored in a set.
You want to check all unique categories assigned to a product.
You want to get all members of a group chat stored as a set.
Syntax
Redis
SMEMBERS key
The key is the name of the set you want to list.
The result is all members of the set, order is not guaranteed.
Examples
Lists all members in the set named 'fruits'.
Redis
SMEMBERS fruits
Shows all users currently online stored in the set 'online_users'.
Redis
SMEMBERS online_users
Returns an empty list if the set 'empty_set' does not exist or has no members.
Redis
SMEMBERS empty_set
Sample Program
First, we add three colors to the set 'colors'. Then, we list all colors in that set.
Redis
SADD colors red green blue
SMEMBERS colors
OutputSuccess
Important Notes
SMEMBERS returns all members in no particular order.
If the set does not exist, SMEMBERS returns an empty list.
Use SMEMBERS when you want to retrieve all unique items stored in a set quickly.
Summary
SMEMBERS lists all members of a set by its key.
It returns an unordered list of unique items.
If the set is empty or missing, it returns an empty list.