Skip to content

Instantly share code, notes, and snippets.

@technocake
Last active September 23, 2022 10:41
Show Gist options
  • Save technocake/5335d58fe9f2a9e258cc39eb386a6828 to your computer and use it in GitHub Desktop.
Save technocake/5335d58fe9f2a9e258cc39eb386a6828 to your computer and use it in GitHub Desktop.
python redis 101
redis:
image: redis
web:
build: .
environment:
# Points to docker hostname redis (from servicename above)
REDIS_URL: "redis://redis/0"
import redis
from magicenv import env
# Get Redis URL from environment - points to default db 0.
REDIS_URL = env('REDIS_URL', "redis://127.0.0.1/0")
cache = redis.from_url(redis_url)
# write:
cache.set('foo', 'bar')
# read:
value = cache.get('foo')
if value is None:
print("Key is missing from cache")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment