Debian Codegraph @

examples/simple_redis.py

raw
1 import asyncio
2
3 from aiocache import Cache
4
5
6 cache = Cache(Cache.REDIS, endpoint="127.0.0.1", port=6379, namespace="main")
7
8
9 async def redis():
10 await cache.set("key", "value")
11 await cache.set("expire_me", "value", ttl=10)
12
13 assert await cache.get("key") == "value"
14 assert await cache.get("expire_me") == "value"
15 assert await cache.raw("ttl", "main:expire_me") > 0
16
17
18 async def test_redis():
19 await redis()
20 await cache.delete("key")
21 await cache.delete("expire_me")
22 await cache.close()
23
24
25 if __name__ == "__main__":
26 asyncio.run(test_redis())