Created
June 25, 2020 21:40
-
-
Save guyroyse/1f35936a6468a81189d0a163fd5e7ea4 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 asyncio | |
import aioredis | |
from pprint import pp | |
async def main(): | |
redis = await aioredis.create_redis('redis://:foobared@localhost:6379/0', encoding='utf-8') | |
await asyncio.gather( | |
add_sighting(redis, 1, 'Possible vocalizations east of Makanda', 'Class B'), | |
add_sighting(redis, 2, 'Sighting near the Columbia River', 'Class A'), | |
add_sighting(redis, 3, 'Chased by a tall hairy creature', 'Class A')) | |
sightings = await asyncio.gather( | |
read_sighting(redis, 1), | |
read_sighting(redis, 2), | |
read_sighting(redis, 3)) | |
pp(sightings) | |
redis.close() | |
await redis.wait_closed() | |
def add_sighting(redis, id, title, classification): | |
return redis.hmset(f'bigfoot:sighting:{id}', | |
'id', id, 'title', title, 'classification', classification) | |
def read_sighting(redis, id): | |
return redis.hgetall(f'bigfoot:sighting:{id}') | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment