Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Last active September 18, 2019 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoff-it/0c9c51a09b8dc804ff5c2909f7af234f to your computer and use it in GitHub Desktop.
Save kristoff-it/0c9c51a09b8dc804ff5c2909f7af234f to your computer and use it in GitHub Desktop.
import redis
# The operation to perform for each event
def add_new_win(conn, winner):
conn.zincrby('wins_counter', 1, winner)
conn.incr('total_games_played')
def main():
# Connect to Redis
conn = redis.Redis()
# Tail the event stream
last_id = '$'
while True:
events = conn.xread({'wins_stream': last_id}, block=0, count=10)
# Process each event by calling `add_new_win`
for _, e in events:
winner = e['winner']
add_new_win(conn, winner)
last_id = e['id']
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment