Last active
September 23, 2022 10:41
-
-
Save technocake/5335d58fe9f2a9e258cc39eb386a6828 to your computer and use it in GitHub Desktop.
python redis 101
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
redis: | |
image: redis | |
web: | |
build: . | |
environment: | |
# Points to docker hostname redis (from servicename above) | |
REDIS_URL: "redis://redis/0" |
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 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