gpt4 book ai didi

redis - Redis 键的命名约定和有效字符

转载 作者:IT王子 更新时间:2023-10-29 05:54:14 24 4
gpt4 key购买 nike

我想知道在 Redis key 中哪些字符被认为是有效的。我用谷歌搜索了一段时间,找不到任何有用的信息。

像在 Python 中一样,有效的变量名应该属于 [a-zA-Z0-9_] 类。 Redis key 的要求和约定是什么?

最佳答案

部分已回答here ,但这并不完全重复,因为您询问的是允许的字符和约定。

关于Redis 键中的有效字符the manual explains this completely :

Redis keys are binary safe, this means that you can use any binary sequence as a key, from a string like "foo" to the content of a JPEG file. The empty string is also a valid key.

A few other rules about keys:

Very long keys are not a good idea, for instance a key of 1024 bytes is a bad idea not only memory-wise, but also because the lookup of the key in the dataset may require several costly key-comparisons. Even when the task at hand is to match the existence of a large value, to resort to hashing it (for example with SHA1) is a better idea, especially from the point of view of memory and bandwidth.

Very short keys are often not a good idea. There is little point in writing "u1000flw" as a key if you can instead write "user:1000:followers". The latter is more readable and the added space is minor compared to the space used by the key object itself and the value object. While short keys will obviously consume a bit less memory, your job is to find the right balance.

Try to stick with a schema. For instance "object-type:id" is a good idea, as in "user:1000". Dots or dashes are often used for multi-word fields, as in "comment:1234:reply.to" or "comment:1234:reply-to".

The maximum allowed key size is 512 MB.

关于redis - Redis 键的命名约定和有效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30271808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com