This file contains hidden or 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
last_id = '$' | |
while True: | |
events = await pool.xread(['wins_stream'], latest_ids=[last_id], timeout=0, count=10) | |
tasks = [] | |
for _, e_id, e in events: | |
winner = e['winner'] | |
tasks.append(add_new_win(pool, winner)) | |
last_id = e_id | |
await asyncio.gather(*tasks) |
This file contains hidden or 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
last_id = '$' | |
while True: | |
events = await pool.xread(['wins_stream'], latest_ids=[last_id], timeout=0, count=10) | |
for _, e_id, e in events: | |
winner = e['winner'] | |
await add_new_win(pool, winner) | |
last_id = e_id |
This file contains hidden or 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
async def add_new_win(pool, winner): | |
task1 = pool.zincrby('wins_counter', 1, winner) | |
task2 = pool.incr('total_games_played') | |
await asyncio.gather(task1, task2) |
This file contains hidden or 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
async def add_new_win(pool, winner): | |
await pool.zincrby('wins_counter', 1, winner) | |
await pool.incr('total_games_played') |
This file contains hidden or 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 asyncio | |
import aioredis | |
async def add_new_win(pool, winner): | |
await pool.zincrby('wins_counter', 1, winner) | |
await pool.incr('total_games_played') | |
async def main(): | |
# Connect to Redis |
This file contains hidden or 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 |
This file contains hidden or 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
# Connect to the container. Use `docker container list` to know the container name. | |
$ docker exec -it CONTAINER_NAME bash | |
# Attach to the virtual environment. This is probably going to be streamlined in future versions. | |
$ apt-get update | |
$ apt-get install python-pip | |
$ pip install pipenv | |
$ cd /opt/redislabs/lib/modules/python3/ | |
$ pipenv shell |
This file contains hidden or 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
> RG.PYEXECUTE "GearsBuilder().filter(lambda x: int(x['value']['age']) > 35).foreach(lambda x: execute('del', x['key'])).run('user:*')" |
This file contains hidden or 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
GearsBuilder('StreamReader').foreach(lambda x: execute('zadd', 'audit-counts', '1', x['key'])).register('audit-logs') |
This file contains hidden or 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
GearsBuilder().filter(lambda x: x['key'].startswith('audited-')).foreach(lambda x: execute('xadd', 'audit-logs', '*', 'key', x['key'])).register() |