I want to store a JSON payload into redis. There's really 2 ways I can do this:

  1. 一个使用简单的字符串键和值

    SET user:1 payload

  2. Using hashes

    HSET user:1 username "someone"
    HSET user:1 location "NY"
    HSET user:1 bio "STRING WITH OVER 100 lines"

Keep in mind that if I use a hash, the value length isn't predictable. They're not all short such as the bio example above.

Which is more memory efficient? Using string keys and values, or using a hash?

推荐答案

这取决于您访问数据的方式:

Go for Option 1:

  • If you use most of the fields on most of your accesses.
  • 如果可能的键有差异

Select 选项2:

  • 如果您在大多数访问中只使用单个字段.
  • 如果您总是知道哪些字段可用

P.S.: As a rule of the thumb, go for the option which requires fewer queries on most of your use cases.

Json相关问答推荐

最新版本的Deneb在数据溢出时不支持滚动

抓取低于w jolt的对象级别

如何在VegaLite中应用Times New Roman,CaliBiri字体

为什么JQ筛选器不将原始输入打印为$var|.';文档?

ArcGIS json到Geojson的变换

如何在Vega中使标记的符号在鼠标指针悬停时可点击

需要有关在Ffltter应用程序中解码JSON的帮助;未处理的异常:类型不是类型转换中类型的子类型

从Postgres表中的JSON中提取值

无法使用Jolt变换在嵌套的JSON中提取值

将 REST API - json 输出转换为表 Power BI

使用 serde 和 csv crates 将嵌套的 json 对象序列化为 csv

如何找出实际安装了哪个版本的 bower 包?

如何使用 json.net 将数据表转换为 json 字符串?

在 JSON 对象中强制执行非空字段

如何向(JSON)对象的原型添加方法?

jQuery JSON 响应总是触发 ParseError

Spring restTemplate 获取原始 json 字符串

如何在spark 上将json字符串转换为数据帧

如何使用 Json.NET 反序列化可以是两种不同数据类型的 JSON 属性

来自 Gson 的 JSON 字符串:删除双引号