redis performance, store json object as a string

前端 未结 4 437
夕颜
夕颜 2021-01-31 04:13

I need to save a User model, something like:

{ \"nickname\": \"alan\",
  \"email\": ...,
  \"password\":...,
  ...} // and a couple of other fields
4条回答
  •  半阙折子戏
    2021-01-31 05:00

    One additional merit for JSON over hashes is maintaining type. 123.3 becomes the string "123.3" and depending on library Null/None can accidentally be casted to "null".

    Both are a bit tedious as that will require writing a transformer for extracting the strings and converting them back to their expected types.

    For space/memory consumption considerations, I've started leaning towards storing just the values as a JSON list ["my_type_version", 123.5, null , ... ] so I didn't have overhead of N * ( sum(len(concat(JSON key names))) which in my case was +60% of Redis's used memory footprint.

提交回复
热议问题