MCPcopy
hub / github.com/redis/redis-py / pairs_to_dict

Function pairs_to_dict

redis/_parsers/helpers.py:314–330  ·  view source on GitHub ↗

Create a dict given a list of key/value pairs

(response, decode_keys=False, decode_string_values=False)

Source from the content-addressed store, hash-verified

312
313
314def pairs_to_dict(response, decode_keys=False, decode_string_values=False):
315 """Create a dict given a list of key/value pairs"""
316 if response is None:
317 return {}
318 if decode_keys or decode_string_values:
319 # the iter form is faster, but I don't know how to make that work
320 # with a str_if_bytes() map
321 keys = response[::2]
322 if decode_keys:
323 keys = map(str_if_bytes, keys)
324 values = response[1::2]
325 if decode_string_values:
326 values = map(str_if_bytes, values)
327 return dict(zip(keys, values))
328 else:
329 it = iter(response)
330 return dict(zip(it, it))
331
332
333def pairs_to_dict_typed(response, type_info):

Callers 15

_parse_hybrid_searchMethod · 0.90
parse_vlinks_resultFunction · 0.90
parse_vsim_resultFunction · 0.90
__init__Method · 0.90
parse_memory_statsFunction · 0.85
parse_stream_listFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected