Skip to content

Instantly share code, notes, and snippets.

@oldarmyc
Created Dec 19, 2018
Embed
What would you like to do?
Redis example
"""
Connecting to Redis server
Install the pip package for python to use for connecting to Redis
pip install redis
"""
# Import the library
import redis
queried_value = None
try:
# Generate the connection
r = redis.Redis(host='support-redis.dev.anaconda.com', port=6379)
# Set and retrieve the same key
r.set('test_key', 'This is a test value for showing redis connectivity')
queried_value = r.get('test_key')
except Exception as e:
print(f'Unable to connect or execute commands on Redis server: {e}')
# Print out queried value
print(queried_value.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment