Skip to content

Instantly share code, notes, and snippets.

@achimnol
Last active May 30, 2019 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achimnol/a8d1d6899eb1a50d468aa20c438c8df2 to your computer and use it in GitHub Desktop.
Save achimnol/a8d1d6899eb1a50d468aa20c438c8df2 to your computer and use it in GitHub Desktop.
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