如果您使用排序集、列表和散列,则没有特定含义。
您可以将 uuid 存储为字符串,例如:
110E8400-E29B-11D4-A716-446655440000
在这种情况下,每个值将占用 38 个字节。如果您不关心存储人类可读的值,您可能更喜欢利用 Redis 存储二进制数据(键和值)的能力,并将 uuid 仅存储为 16 个字节。
您的短列表、排序集和哈希将按照 Redis 文档中的说明进行序列化。您可能需要调整以下参数以根据您的工作负载调整 Redis 行为:
# Hashes are encoded using a memory efficient data structure when they have a
# small number of entries, and the biggest entry does not exceed a given
# threshold. These thresholds can be configured using the following directives.
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
# you are under the following limits:
list-max-ziplist-entries 512
list-max-ziplist-value 64
# Sets have a special encoding in just one case: when a set is composed
# of just strings that happens to be integers in radix 10 in the range
# of 64 bit signed integers.
# The following configuration setting sets the limit in the size of the
# set in order to use this special memory saving encoding.
set-max-intset-entries 512
# Similarly to hashes and lists, sorted sets are also specially encoded in
# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
现在,如果您打算使用集合(简单集合,而不是排序集合),则有一个称为 intset 的特定优化,如果您使用 UUID 作为键,您将无法从中受益。一个 intset 只能用于编码 64 位数字,因此 16 字节 UUID 不适合。如果您计划存储大量集合,则添加间接寻址可能会有好处,并使用整数作为主键而不是 UUID。否则毫无意义。