How to use the sismember function from redis

Find comprehensive JavaScript redis.sismember code examples handpicked from public code repositorys.

The Redis command SISMEMBER is used to check if a given element exists in a set or not, returning a boolean value.

92
93
94
95
96
97
98
99
100
101
    this.project_id
  )
})

return it('should clear the doc from the DocsWithHistoryOps set', function (done) {
  rclient.sismember(
    `DocsWithHistoryOps:${this.project_id}`,
    this.doc_id,
    (error, member) => {
      if (error) return done(error)
fork icon0
star icon2
watch icon1

+ 2 other calls in file

How does redis.sismember work?

redis.sismember is a Redis command used to check if a given member exists in a specified set or not, returning a boolean value of 1 (true) or 0 (false). It takes the set name and the member value as arguments.

Ai Example

1
2
3
4
5
client.sadd("myset", "apple", "orange", "banana", redis.print);
client.sismember("myset", "orange", function (err, reply) {
  if (err) throw err;
  console.log(reply); // Output: 1
});

In this example, the sadd method is used to add three members to a set named myset, and the sismember method is used to check if the member 'orange' exists in the set. The method returns 1 since 'orange' is a member of the set.