Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created November 9, 2012 00:37
Show Gist options
  • Select an option

  • Save cablehead/4042939 to your computer and use it in GitHub Desktop.

Select an option

Save cablehead/4042939 to your computer and use it in GitHub Desktop.
caches:
user_unread
# tracks total unread count for each user
key
user_id -> count
receipt_users
# tracks which users are at a given read receipt
# used to know when we can stop tracking the count for a receipt
set
receipt_id -> users
channel_receipt
# tracks unread count for a given read receipt
# used to provide quick decr when a user updates a rooms read receipt
hash
channel_id, receipt_id -> count
channel_read
# tracks which read receipt a user is at,
# used to quickly locate a user's previous read receipt
hash
channel_id, user_id -> (receipt_id, command_id)
channel_command
# the stream for a channel
# note for receipt commands only the most recent from a user is kept
scored set
channel_id, command_id -> command_type, commands
flows:
message new ->
channel_command append new
for receipt in channel_receipt:
channel_receipt incr receipt count
# :(
for user in room:
user_unread incr user
message read ->
channel_command append new
last = channel_read get user
channel_read put user new
channel_command remove last
receipt_users smove last new user
if receipt_users scard last == 0:
receipt_users remove last
channel_receipt remove last
if receipt_users scard new == 1:
channel_receipt put new (count channel_command of type message > new)
user_unread decr user (channel_receipt last - channel_receipt new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment