gpt4 book ai didi

redis - Redis 如何在内部将 String 表示为位?

转载 作者:可可西里 更新时间:2023-11-01 11:44:38 27 4
gpt4 key购买 nike

我试图理解字符串的位表示(尤其是在 Redis 中)

我试过这个:

redis> SET mykey3 hello
OK
redis> SETBIT mykey3 7 0
(integer) 0
redis> SETBIT mykey3 7 1
(integer) 0
redis> GET mykey3
"iello"
redis> SET mykey4 5
OK
redis> SETBIT mykey4 7 0
(integer) 1
redis> GET mykey4
"4"

那么在这种情况下“hello”和“5”的位表示是什么?

  • 另外,其他 Redis 类型,List、Set、Sorted Set 如何表示为二进制位?这样的位操作可以工作吗?或者事实并非如此?
  • 从什么方面看,一切似乎都存储为二进制安全的字符串?如果是这样,List、Set、Sorted Set 如何表示为安全字符串?

最佳答案

如果你看bitops.c你会看到位命令确实只适用于 string key type .

来自 redis.io :

All the following data types are supported as values:

  • Binary-safe strings.
  • Lists of binary-safe strings.
  • Sets of binary-safestrings, that are collection of unique unsorted elements. You canthink at this as a Ruby hash where all the keys are set to the 'true'value.
  • Sorted sets, similar to Sets but where every element isassociated to a floating number score. The elements are taken sortedby score. You can think of this as Ruby hashes where the key is theelement and the value is the score, but where elements are alwaystaken in order without requiring a sorting operation.

因此只有列表和集合 存储在二进制安全字符串中。对于键和散列以及排序集成员也是如此。

关于redis - Redis 如何在内部将 String 表示为位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16133448/

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