Completed
Push — master ( 48c94d...019fe1 )
by Andrew
01:07
created

new_read()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
import logging
2
3
import redis
4
import tornadoredis
5
6
from chat.settings import ALL_REDIS_ROOM
7
8
logger = logging.getLogger(__name__)
9
10
11
def new_read(instance, *args, **kwargs):
12
	try:
13
		return instance.old_read(*args, **kwargs)
14
	except Exception as e:
15
		redis_online = sync_redis.hgetall(ALL_REDIS_ROOM)
16
		logger.error("Error occurred during reading tornadoredis connection. Redis online  %s", redis_online)
17
		raise e
18
19
20
def patch(tornado_redis):
21
	fabric = type(tornado_redis.connection.read)
22
	tornado_redis.connection.old_read = tornado_redis.connection.read
23
	tornado_redis.connection.read = fabric(new_read, tornado_redis.connection)
24
25
26
# # global connection to read synchronously
27
sync_redis = redis.StrictRedis()
28
# patch(sync_redis)
29
# Redis connection cannot be shared between publishers and subscribers.
30
async_redis_publisher = tornadoredis.Client()
31
patch(async_redis_publisher)
32
async_redis_publisher.connect()