gpt4 book ai didi

redis - 成员 : How is insertion order decided?

转载 作者:IT王子 更新时间:2023-10-29 06:01:32 24 4
gpt4 key购买 nike

当我们使用 sadd 在集合中插入一个成员时,是否有一种确定的方式来插入数据?例如,

127.0.0.1:6380> smembers test
1) "hello world"
2) "hello"
3) "hello world 1234212"
4) "hello world 123"

127.0.0.1:6380> sadd test "aman"
(integer) 1

127.0.0.1:6380> smembers test
1) "hello world"
2) "hello"
3) "hello world 1234212"
4) "hello world 123"
5) "aman"

127.0.0.1:6380> sadd test "stack overflow"
(integer) 1
127.0.0.1:6380> smembers test
1) "hello world 1234212"
2) "hello world 123"
3) "hello world"
4) "aman"
5) "stack overflow"
6) "hello"

看起来,当我插入“stack overflow”时,“hello”显示在最后一个索引中,而不是前面查询中的索引 2。对这种行为有解释吗?

最佳答案

集合是使用哈希表实现的,并且是确定性的。然而,这并不意味着您从 SMEMBERS 获得的订单就是您所期望的。

如果您需要字典顺序,请使用所有成员都具有相同分数(例如零)的有序集合。

关于redis - 成员 : How is insertion order decided?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36933633/

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