diff options
author | gs230937207 <32325444+gs230937207@users.noreply.github.com> | 2017-11-15 17:41:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-15 17:41:13 +0100 |
commit | d8c60e10a99bcb91694231f9c3b8a7e9d8f90f31 (patch) | |
tree | 1b01f152a2acbfba623ff719caee1ad178f6f562 | |
parent | ceefaadf4463f5e264ab68563d94df66ce4bf409 (diff) | |
download | pymemcache-d8c60e10a99bcb91694231f9c3b8a7e9d8f90f31.tar.gz |
Update getting_started.rst
With python3 (3.5 here) json_deserializer receives the values as bytes.
Disclaimer: I am a python beginner, so if there is another way to achieve the same result please let me know.
-rw-r--r-- | docs/getting_started.rst | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 6e1b8d7..9b0e111 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -30,7 +30,6 @@ on if a server goes down. client.set('some_key', 'some value') result = client.get('some_key') - Serialization -------------- @@ -56,6 +55,17 @@ Serialization client.set('key', {'a':'b', 'c':'d'}) result = client.get('key') +Deserialization with python3 +---------------------------- + +.. code-block:: python + + def json_deserializer(key, value, flags): + if flags == 1: + return value.decode('utf-8') + if flags == 2: + return json.loads(value.decode('utf-8')) + raise Exception("Unknown serialization format") Key Constraints --------------- @@ -69,7 +79,6 @@ set `allow_unicode_keys` to support unicode keys, but beware of what unicode encoding you use to make sure multiple clients can find the same key. - Best Practices --------------- |