Skip to content

Instantly share code, notes, and snippets.

View kristoff-it's full-sized avatar
in your codebase, fixing your bugz

Loris Cro kristoff-it

in your codebase, fixing your bugz
View GitHub Profile
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)
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
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)
async def add_new_win(pool, winner):
await pool.zincrby('wins_counter', 1, winner)
await pool.incr('total_games_played')
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
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
@kristoff-it
kristoff-it / shell.sh
Last active June 11, 2019 12:59
Installing numpy
# 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
> RG.PYEXECUTE "GearsBuilder().filter(lambda x: int(x['value']['age']) > 35).foreach(lambda x: execute('del', x['key'])).run('user:*')"
GearsBuilder('StreamReader').foreach(lambda x: execute('zadd', 'audit-counts', '1', x['key'])).register('audit-logs')
GearsBuilder().filter(lambda x: x['key'].startswith('audited-')).foreach(lambda x: execute('xadd', 'audit-logs', '*', 'key', x['key'])).register()