hisosic

ElastiCache (Redis) Socket Connect Timeout Check 본문

Python

ElastiCache (Redis) Socket Connect Timeout Check

hisosic 2021. 6. 24. 20:12

 

#!/bin/env python3

from redis import Redis
from datetime import datetime
import time

redis_host = 'cxx-redis-sxxx.lxxxm.0001.usw2.cache.amazonaws.com'

while True:
	res = False
	time.sleep(0.5)
	now = datetime.today().strftime("%H:%M:%S")
	try:
		r = Redis(redis_host, socket_connect_timeout=1) # short timeout for the test
		res = r.ping()
	except Exception as e:
		print(f"[{now}] ERROR {res}, {e}")
	if res:
    	print(f'[{now}] connected to redis {redis_host}')
Comments