Skip to content

Commit 79364a6

Browse files
committed
Updated callbacks to include required arguments
1 parent 2c50adc commit 79364a6

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

redis/_parsers/helpers.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from redis.utils import str_if_bytes
44

55

6-
def timestamp_to_datetime(response):
6+
def timestamp_to_datetime(response, **options):
77
"Converts a unix timestamp to a Python datetime object"
88
if not response:
99
return None
@@ -14,7 +14,7 @@ def timestamp_to_datetime(response):
1414
return datetime.datetime.fromtimestamp(response)
1515

1616

17-
def parse_debug_object(response):
17+
def parse_debug_object(response, **options):
1818
"Parse the results of Redis's DEBUG OBJECT command into a Python dict"
1919
# The 'type' of the object is the first item in the response, but isn't
2020
# prefixed with a name
@@ -32,7 +32,7 @@ def parse_debug_object(response):
3232
return response
3333

3434

35-
def parse_info(response):
35+
def parse_info(response, **options):
3636
"""Parse the result of Redis's INFO command into a Python dict"""
3737
info = {}
3838
response = str_if_bytes(response)
@@ -121,7 +121,7 @@ def parse_memory_stats(response, **kwargs):
121121
}
122122

123123

124-
def parse_sentinel_state(item):
124+
def parse_sentinel_state(item, **options):
125125
result = pairs_to_dict_typed(item, SENTINEL_STATE_TYPES)
126126
flags = set(result["flags"].split(","))
127127
for name, flag in (
@@ -137,11 +137,11 @@ def parse_sentinel_state(item):
137137
return result
138138

139139

140-
def parse_sentinel_master(response):
140+
def parse_sentinel_master(response, **options):
141141
return parse_sentinel_state(map(str_if_bytes, response))
142142

143143

144-
def parse_sentinel_state_resp3(response):
144+
def parse_sentinel_state_resp3(response, **options):
145145
result = {}
146146
for key in response:
147147
try:
@@ -154,27 +154,27 @@ def parse_sentinel_state_resp3(response):
154154
return result
155155

156156

157-
def parse_sentinel_masters(response):
157+
def parse_sentinel_masters(response, **options):
158158
result = {}
159159
for item in response:
160160
state = parse_sentinel_state(map(str_if_bytes, item))
161161
result[state["name"]] = state
162162
return result
163163

164164

165-
def parse_sentinel_masters_resp3(response):
165+
def parse_sentinel_masters_resp3(response, **options):
166166
return [parse_sentinel_state(master) for master in response]
167167

168168

169-
def parse_sentinel_slaves_and_sentinels(response):
169+
def parse_sentinel_slaves_and_sentinels(response, **options):
170170
return [parse_sentinel_state(map(str_if_bytes, item)) for item in response]
171171

172172

173-
def parse_sentinel_slaves_and_sentinels_resp3(response):
173+
def parse_sentinel_slaves_and_sentinels_resp3(response, **options):
174174
return [parse_sentinel_state_resp3(item) for item in response]
175175

176176

177-
def parse_sentinel_get_master(response):
177+
def parse_sentinel_get_master(response, **options):
178178
return response and (response[0], int(response[1])) or None
179179

180180

@@ -235,7 +235,7 @@ def sort_return_tuples(response, **options):
235235
return list(zip(*[response[i::n] for i in range(n)]))
236236

237237

238-
def parse_stream_list(response):
238+
def parse_stream_list(response, **options):
239239
if response is None:
240240
return None
241241
data = []
@@ -247,11 +247,11 @@ def parse_stream_list(response):
247247
return data
248248

249249

250-
def pairs_to_dict_with_str_keys(response):
250+
def pairs_to_dict_with_str_keys(response, **options):
251251
return pairs_to_dict(response, decode_keys=True)
252252

253253

254-
def parse_list_of_dicts(response):
254+
def parse_list_of_dicts(response, **options):
255255
return list(map(pairs_to_dict_with_str_keys, response))
256256

257257

@@ -299,13 +299,13 @@ def parse_xinfo_stream(response, **options):
299299
return data
300300

301301

302-
def parse_xread(response):
302+
def parse_xread(response, **options):
303303
if response is None:
304304
return []
305305
return [[r[0], parse_stream_list(r[1])] for r in response]
306306

307307

308-
def parse_xread_resp3(response):
308+
def parse_xread_resp3(response, **options):
309309
if response is None:
310310
return {}
311311
return {key: [parse_stream_list(value)] for key, value in response.items()}
@@ -323,12 +323,12 @@ def parse_xpending(response, **options):
323323
}
324324

325325

326-
def parse_xpending_range(response):
326+
def parse_xpending_range(response, **options):
327327
k = ("message_id", "consumer", "time_since_delivered", "times_delivered")
328328
return [dict(zip(k, r)) for r in response]
329329

330330

331-
def float_or_none(response):
331+
def float_or_none(response, **options):
332332
if response is None:
333333
return None
334334
return float(response)

redis/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ class initializer. In the case of conflicting arguments, querystring
144144
"""
145145
single_connection_client = kwargs.pop("single_connection_client", False)
146146
use_cache = kwargs.pop("use_cache", False)
147+
cache_ttl = kwargs.pop("cache_ttl", 300)
148+
cache_size = kwargs.pop("cache_size", 128)
147149
connection_pool = ConnectionPool.from_url(url, **kwargs)
148150
client = cls(
149151
connection_pool=connection_pool,
150152
single_connection_client=single_connection_client,
151-
use_cache=use_cache
153+
use_cache=use_cache,
154+
cache_ttl=cache_ttl,
155+
cache_size=cache_size
152156
)
153157
client.auto_close_connection_pool = True
154158
return client

redis/commands/timeseries/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ def parse_range(response, **kwargs):
1010
return [tuple((r[0], float(r[1]))) for r in response]
1111

1212

13-
def parse_m_range(response):
13+
def parse_m_range(response, **options):
1414
"""Parse multi range response. Used by TS.MRANGE and TS.MREVRANGE."""
1515
res = []
1616
for item in response:
1717
res.append({nativestr(item[0]): [list_to_dict(item[1]), parse_range(item[2])]})
1818
return sorted(res, key=lambda d: list(d.keys()))
1919

2020

21-
def parse_get(response):
21+
def parse_get(response, **options):
2222
"""Parse get response. Used by TS.GET."""
2323
if not response:
2424
return None
2525
return int(response[0]), float(response[1])
2626

2727

28-
def parse_m_get(response):
28+
def parse_m_get(response, **options):
2929
"""Parse multi get response. Used by TS.MGET."""
3030
res = []
3131
for item in response:

0 commit comments

Comments
 (0)