Who is connected?

Hi,

I want to keep a list of UserIDs who are now online.
I can keep a string as a doc and append to it (using Append) whenever a new user logs in. That’s easy and fast.
But how can I remove from it as easily and fast ?

I can also read the appended string, remove the value from it and save it again on log out but I’m looking for an only write (not read, modify, write) way.

I can also create a doc with key UserID::login when a user logs in and remove that key when a user logs out. But I cannot compose a list of who is connected.

What if the list is very long, ~100,000s ?

What is the preferred way ? Is there a better way here ?

Thanks, Itay

Have a look at Dustin’s blog on Maintaining a Set. I think you can use a combination of your idea and Dustin’s compaction idea.

As far as having a long list, that may be okay if your item is under the 20MByte limit, though you’ll pay for it in transport time. The other way to do it is distribute them (shard) based on ranges or hashes.

Finally, one way to do it could be to have a separate bucket and just use stats for number of items and have each item expire when the session ends. That one may be easiest. The touch() operation can be used to extend the TTL.

@ingenthr

That was very interesting and thanks for your prompt reply.
I’ll give it a thought and consider all the trade offs.

Your last suggestion is also interesting. touch() can be useful, however I don’t understand how stats is going to retrieve UserIDs, as I wrote:

Indeed, that’d be a slight challenge. The only supported method for that at the moment is to use a view. You’ll have to tune down the expiry pager time if you use a view as well to ensure the items are removed.

Let me know if you need a more thorough description.

10x
I’ll play with it and get back to you later