Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Short answer: use sets + pipelining + MULTI/EXEC, or sets + Lua.</p> <p><strong>1) Add user to a channel</strong></p> <p><a href="http://redis.io/commands/sadd" rel="nofollow">SADD</a> command</p> <p><strong>2) Remove user from a channel</strong></p> <p><a href="http://redis.io/commands/srem" rel="nofollow">SREM</a> command</p> <p><strong>3) Get list of all users in several selected channels</strong></p> <p>There are several ways to do it.</p> <p>If you don't need strict atomicity, you just have to <a href="http://redis.io/topics/pipelining" rel="nofollow">pipeline</a> several <a href="http://redis.io/commands/smembers" rel="nofollow">SMEMBERS</a> commands to retrieve all the sets in one roundtrip. If you are just interested whether channels have users or not, you can replace SMEMBERS by <a href="http://redis.io/commands/scard" rel="nofollow">SCARD</a>.</p> <p>If you need strict atomicity, you can pipeline a MULTI/EXEC block containing SMEMBERS or SCARD commands. The output of the EXEC command will contain all the results. This is the solution I would recommend.</p> <p>An alternative (atomic) way is to call a server-side Lua script using the <a href="http://redis.io/commands/eval" rel="nofollow">EVAL</a> command. Lua script executions are always atomic. The script could take a number of channel as input parameters, and build a multi-layer bulk reply to return the output.</p> <p><strong>4) Detect if a specific user is in a channel</strong></p> <p><a href="http://redis.io/commands/sismember" rel="nofollow">SISMEMBER</a> command - pipeline them if you need to check for several users.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload