Skip to content

Commit 01362fa

Browse files
committed
Added prefix support
1 parent 52138d6 commit 01362fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

splitio/engine/impressions/adapters.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ class PluggableSenderAdapter(ImpressionsSenderAdapter):
127127
IMP_COUNT_QUEUE_KEY = 'SPLITIO.impressions.count'
128128
IMP_COUNT_KEY_DEFAULT_TTL = 3600
129129

130-
def __init__(self, adapter_client):
130+
def __init__(self, adapter_client, prefix=None):
131131
"""
132132
Initialize pluggable sender adapter instance
133133
134134
:param telemtry_http_client: instance of telemetry http api
135135
:type telemtry_http_client: splitio.api.telemetry.TelemetryAPI
136136
"""
137137
self._adapter_client = adapter_client
138+
self._prefix = ""
139+
if prefix is not None:
140+
self._prefix = prefix + "."
138141

139142
def record_unique_keys(self, uniques):
140143
"""
@@ -146,7 +149,7 @@ def record_unique_keys(self, uniques):
146149
bulk_mtks = _uniques_formatter(uniques)
147150
try:
148151
inserted = self._adapter_client.push_items(self.MTK_QUEUE_KEY, *bulk_mtks)
149-
self._expire_keys(self.MTK_QUEUE_KEY, self.MTK_KEY_DEFAULT_TTL, inserted, len(bulk_mtks))
152+
self._expire_keys(self._prefix + self.MTK_QUEUE_KEY, self.MTK_KEY_DEFAULT_TTL, inserted, len(bulk_mtks))
150153
return True
151154
except RedisAdapterException:
152155
_LOGGER.error('Something went wrong when trying to add mtks to storage adapter')
@@ -163,8 +166,8 @@ def flush_counters(self, to_send):
163166
try:
164167
resulted = 0
165168
for pf_count in to_send:
166-
resulted = self._adapter_client.increment(self.IMP_COUNT_QUEUE_KEY + "." + pf_count.feature + "::" + str(pf_count.timeframe), pf_count.count)
167-
self._expire_keys(self.IMP_COUNT_QUEUE_KEY + "." + pf_count.feature + "::" + str(pf_count.timeframe),
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),
168171
self.IMP_COUNT_KEY_DEFAULT_TTL, resulted, pf_count.count)
169172
return True
170173
except RedisAdapterException:

0 commit comments

Comments
 (0)