I need to save a User model, something like:
{ \"nickname\": \"alan\",
\"email\": ...,
\"password\":...,
...} // and a couple of other fields
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.