0
0
Redisquery~5 mins

SISMEMBER for membership check in Redis

Choose your learning style9 modes available
Introduction

SISMEMBER helps you quickly check if a value is inside a set. It tells you yes or no.

Check if a user is in a list of online users.
Verify if a product ID is in a set of featured items.
See if an email address is in a blacklist.
Confirm if a tag exists in a set of tags for a blog post.
Determine if a session ID is active in a set of sessions.
Syntax
Redis
SISMEMBER key member

key is the name of the set you want to check.

member is the value you want to find in the set.

Examples
Check if 'user123' is in the 'online_users' set.
Redis
SISMEMBER online_users user123
Check if product ID '98765' is in the 'featured_products' set.
Redis
SISMEMBER featured_products 98765
Check if the email 'spam@example.com' is in the 'blacklist' set.
Redis
SISMEMBER blacklist spam@example.com
Sample Program

First, add three colors to the 'colors' set. Then check if 'green' is in the set (should be yes). Finally, check if 'yellow' is in the set (should be no).

Redis
SADD colors red green blue
SISMEMBER colors green
SISMEMBER colors yellow
OutputSuccess
Important Notes

SISMEMBER returns 1 if the member exists, 0 if it does not.

Sets in Redis do not allow duplicate members.

Use SISMEMBER for fast membership checks without scanning the whole set.

Summary

SISMEMBER checks if a value is in a Redis set.

Returns 1 for yes, 0 for no.

Great for quick membership tests in lists stored as sets.