Last active
September 18, 2019 13:45
-
-
Save kristoff-it/0c9c51a09b8dc804ff5c2909f7af234f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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