So, following the excellent suggestion in both this answer and that answer, I decided to replace a whole bunch of encode/decode
to/from UTF-8 all over the place by
Here is what I came up with. Not sure how it would handle complex connections and what else it may break. Just don't run your self-driving car with that...
def new_client(client, **kwargs):
"""return a new Redis client based on an existing one,
with some kwargs modified.
"""
kwargs = {**client.connection_pool.connection_kwargs, **kwargs}
return redis.StrictRedis(**kwargs)
With this, now we can do, e.g.:
client.set(name, pickle.dumps(stuff))
...
# later
with new_client(client, decode_responses=False) as binclient:
data = binclient.get(name)
stuff = pickle.loads(data)