Created
October 22, 2019 15:01
-
-
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.
This file contains hidden or 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 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