55from splitio .storage .adapters .redis import RedisAdapterException
66
77_LOGGER = logging .getLogger (__name__ )
8+ _MTK_QUEUE_KEY = 'SPLITIO.uniquekeys'
9+ _MTK_KEY_DEFAULT_TTL = 3600
10+ _IMP_COUNT_QUEUE_KEY = 'SPLITIO.impressions.count'
11+ _IMP_COUNT_KEY_DEFAULT_TTL = 3600
812
913class ImpressionsSenderAdapter (object , metaclass = abc .ABCMeta ):
1014 """Impressions Sender Adapter interface."""
@@ -53,11 +57,6 @@ def _uniques_formatter(self, uniques):
5357class RedisSenderAdapter (ImpressionsSenderAdapter ):
5458 """In Memory Impressions Sender Adapter class."""
5559
56- MTK_QUEUE_KEY = 'SPLITIO.uniquekeys'
57- MTK_KEY_DEFAULT_TTL = 3600
58- IMP_COUNT_QUEUE_KEY = 'SPLITIO.impressions.count'
59- IMP_COUNT_KEY_DEFAULT_TTL = 3600
60-
6160 def __init__ (self , redis_client ):
6261 """
6362 Initialize In memory sender adapter instance
@@ -76,8 +75,8 @@ def record_unique_keys(self, uniques):
7675 """
7776 bulk_mtks = _uniques_formatter (uniques )
7877 try :
79- inserted = self ._redis_client .rpush (self . MTK_QUEUE_KEY , * bulk_mtks )
80- self ._expire_keys (self . MTK_QUEUE_KEY , self . MTK_KEY_DEFAULT_TTL , inserted , len (bulk_mtks ))
78+ inserted = self ._redis_client .rpush (_MTK_QUEUE_KEY , * bulk_mtks )
79+ self ._expire_keys (_MTK_QUEUE_KEY , _MTK_KEY_DEFAULT_TTL , inserted , len (bulk_mtks ))
8180 return True
8281 except RedisAdapterException :
8382 _LOGGER .error ('Something went wrong when trying to add mtks to redis' )
@@ -96,11 +95,11 @@ def flush_counters(self, to_send):
9695 counted = 0
9796 pipe = self ._redis_client .pipeline ()
9897 for pf_count in to_send :
99- pipe .hincrby (self . IMP_COUNT_QUEUE_KEY , pf_count .feature + "::" + str (pf_count .timeframe ), pf_count .count )
98+ pipe .hincrby (_IMP_COUNT_QUEUE_KEY , pf_count .feature + "::" + str (pf_count .timeframe ), pf_count .count )
10099 counted += pf_count .count
101100 resulted = sum (pipe .execute ())
102- self ._expire_keys (self . IMP_COUNT_QUEUE_KEY ,
103- self . IMP_COUNT_KEY_DEFAULT_TTL , resulted , counted )
101+ self ._expire_keys (_IMP_COUNT_QUEUE_KEY ,
102+ _IMP_COUNT_KEY_DEFAULT_TTL , resulted , counted )
104103 return True
105104 except RedisAdapterException :
106105 _LOGGER .error ('Something went wrong when trying to add counters to redis' )
@@ -122,11 +121,6 @@ def _expire_keys(self, queue_key, key_default_ttl, total_keys, inserted):
122121class PluggableSenderAdapter (ImpressionsSenderAdapter ):
123122 """In Memory Impressions Sender Adapter class."""
124123
125- MTK_QUEUE_KEY = 'SPLITIO.uniquekeys'
126- MTK_KEY_DEFAULT_TTL = 3600
127- IMP_COUNT_QUEUE_KEY = 'SPLITIO.impressions.count'
128- IMP_COUNT_KEY_DEFAULT_TTL = 3600
129-
130124 def __init__ (self , adapter_client , prefix = None ):
131125 """
132126 Initialize pluggable sender adapter instance
@@ -148,8 +142,8 @@ def record_unique_keys(self, uniques):
148142 """
149143 bulk_mtks = _uniques_formatter (uniques )
150144 try :
151- inserted = self ._adapter_client .push_items (self . MTK_QUEUE_KEY , * bulk_mtks )
152- self ._expire_keys (self ._prefix + self . MTK_QUEUE_KEY , self . MTK_KEY_DEFAULT_TTL , inserted , len (bulk_mtks ))
145+ inserted = self ._adapter_client .push_items (_MTK_QUEUE_KEY , * bulk_mtks )
146+ self ._expire_keys (self ._prefix + _MTK_QUEUE_KEY , _MTK_KEY_DEFAULT_TTL , inserted , len (bulk_mtks ))
153147 return True
154148 except RedisAdapterException :
155149 _LOGGER .error ('Something went wrong when trying to add mtks to storage adapter' )
@@ -166,9 +160,9 @@ def flush_counters(self, to_send):
166160 try :
167161 resulted = 0
168162 for pf_count in to_send :
169- resulted = self ._adapter_client . increment ( self . _prefix + self . IMP_COUNT_QUEUE_KEY + "." + pf_count .feature + "::" + str (pf_count .timeframe ), pf_count . count )
170- self . _expire_keys ( self . _prefix + self .IMP_COUNT_QUEUE_KEY + "." + pf_count .feature + "::" + str ( pf_count . timeframe ),
171- self .IMP_COUNT_KEY_DEFAULT_TTL , resulted , pf_count .count )
163+ key = self ._prefix + _IMP_COUNT_QUEUE_KEY + "." + pf_count .feature + "::" + str (pf_count .timeframe )
164+ resulted = self ._adapter_client . increment ( key , pf_count .count )
165+ self ._expire_keys ( key , _IMP_COUNT_KEY_DEFAULT_TTL , resulted , pf_count .count )
172166 return True
173167 except RedisAdapterException :
174168 _LOGGER .error ('Something went wrong when trying to add counters to storage adapter' )
0 commit comments