There is such a list of dictionaries:

[{'insp': 4816}, {'insp': 3252}, {'insp': 7107}, {'insp': 5948}, {'insp': 5257}, {'insp': 5916}, { 'insp': 1673}, {'insp': 5503}, {'insp': 6030}, {'insp': 6439}, {'insp': 7151}, {'insp': 2411}, {'insp ': 2208}, {' insp ': 5010}, {' insp ': 9978}, {' insp ': 5613}, {' insp ': 2634}, {' insp ': 2308}, {' insp ': 4711}, {'insp': 5050}, {'insp': 7721}]

I need to competently translate it into a string, then to serialize it for memcached . How to do it ? And then how to deserialize it?

I tried str(mylist) , but in the end, after deserializing with the pymemcache library, I get a string that contains a lot of unnecessary characters, such as b and \ ...

  • For memcached? I know libraries to work with him like serialize everything on their own, not? - andreymal
  • In particular, python-memcached automatically uses pickle for serialization - andreymal
  • Could you give me an example? I can’t get a list of dictionaries in client.set() without additional manipulations and easily return it via client.get() ... :( - faoxis

1 answer 1

When creating a client, specify the serializer , deserializer parameters as shown in the documentation . The example shows json_serializer , json_deserializer . You can also use functions from pymemcache.serde that call pickle.

  • I tried to do the example functions from the documentation. An error occurs during deserialization: TypeError: the JSON object must be str, not 'bytes' . But on pymemcache.serde I did not pay attention in the dock. It all worked. Thank! - faoxis
  • @faoxis 1- if the example from the documentation does not work with the appropriate version of the library, then you can open an issue on GitHub 2- if you cannot use the example yourself, then you can ask a separate SO question. - jfs
  • Could you answer this question ? .stackoverflow.com /questions/ 604313 / ? - faoxis