Skip to content

Instantly share code, notes, and snippets.

@oldarmyc
Created December 19, 2018 17:52
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 oldarmyc/e1048916d64603ceb683c9bcadb49532 to your computer and use it in GitHub Desktop.
Save oldarmyc/e1048916d64603ceb683c9bcadb49532 to your computer and use it in GitHub Desktop.
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