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

Function decode_field_value

redis/utils.py:81–95  ·  view source on GitHub ↗

Decode a field value respecting optional per-field encoding overrides. - If *field_encodings* is provided and *key* is in it, the corresponding encoding is used (``None`` means keep raw bytes). - Otherwise falls back to :func:`str_if_bytes`.

(value, key=None, field_encodings=None)

Source from the content-addressed store, hash-verified

79
80
81def decode_field_value(value, key=None, field_encodings=None):
82 """Decode a field value respecting optional per-field encoding overrides.
83
84 - If *field_encodings* is provided and *key* is in it, the corresponding
85 encoding is used (``None`` means keep raw bytes).
86 - Otherwise falls back to :func:`str_if_bytes`.
87 """
88 if not isinstance(value, bytes):
89 return value
90 if field_encodings and key is not None and key in field_encodings:
91 encoding = field_encodings[key]
92 if encoding is None:
93 return value
94 return value.decode(encoding, "replace")
95 return str_if_bytes(value)
96
97
98def dict_merge(*dicts: Mapping[str, Any]) -> Dict[str, Any]:

Callers 4

load_documentMethod · 0.90
load_documentMethod · 0.90
from_resp3Method · 0.90

Calls 2

str_if_bytesFunction · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected