@@ -66,6 +66,8 @@ def __init__(self, redis_client):
6666 :type telemtry_http_client: splitio.api.telemetry.TelemetryAPI
6767 """
6868 self ._redis_client = redis_client
69+ self .pipe = self ._redis_client .pipeline ()
70+
6971
7072 def record_unique_keys (self , uniques ):
7173 """
@@ -88,13 +90,14 @@ def flush_counters(self, to_send):
8890 """
8991 post the impression counters to redis.
9092
91- :param uniques : unique keys disctionary
92- :type uniques : Dictionary {'feature1': set(), 'feature2': set(), .. }
93+ :param to_send : unique keys disctionary
94+ :type to_send : Dictionary {'feature1': set(), 'feature2': set(), .. }
9395 """
94- bulk_counts = self ._build_counters (to_send )
9596 try :
96- inserted = self ._redis_client .rpush (self .IMP_COUNT_QUEUE_KEY , bulk_counts )
97- self ._expire_keys (self .IMP_COUNT_QUEUE_KEY , self .IMP_COUNT_KEY_DEFAULT_TTL , inserted , len (to_send ))
97+ for pf_count in to_send :
98+ self .pipe .hincrby (self .IMP_COUNT_QUEUE_KEY , pf_count .feature + "::" + str (pf_count .timeframe ), pf_count .count )
99+ result = self .pipe .execute ()
100+ self ._expire_keys (self .IMP_COUNT_QUEUE_KEY , self .IMP_COUNT_KEY_DEFAULT_TTL , result [0 ], pf_count .count )
98101 return True
99102 except RedisAdapterException :
100103 _LOGGER .error ('Something went wrong when trying to add counters to redis' )
0 commit comments