Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Idea for contextvars-based API design for ring-cache
import redis
from ring import Ring
import contextvars
redis_connection = contextvars.ContextVar('redis_connection', None)
ring = Ring(...)
class A:
@ring.redis(redis_connection, ...)
def get_something(self):
...
if __name__ == '__main__':
redis_connection.set(redis.Redis(...))
a = A()
print(a.get_something())
print(a.get_something())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.