Skip to content

Instantly share code, notes, and snippets.

@ryderdamen
Created October 22, 2019 15:01
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 ryderdamen/6df615894ee5b7a7c0d3ec9513080949 to your computer and use it in GitHub Desktop.
Save ryderdamen/6df615894ee5b7a7c0d3ec9513080949 to your computer and use it in GitHub Desktop.
An example of a function that tests if a connection to Redis can be established.
import os
import redis
def can_connect_to_redis():
if not os.environ.get('REDIS_URL'):
return False
try:
conn = redis.from_url(os.environ.get('REDIS_URL'))
conn.ping()
return True
except redis.ConnectionError:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment