gpt4 book ai didi

redis - 消除Redis中的魔数(Magic Number)

转载 作者:IT王子 更新时间:2023-10-29 06:12:03 26 4
gpt4 key购买 nike

我正在使用排序集通过 Redis 创建索引。我想要匹配结果的以下顺序(首先是较小的字符串):

a
ar
art
artu
artur
arturo

来自Redis documentation我使用分数来存储数据:

The elements are considered to be ordered from the highest to the lowest score.

我为实现这一点而编写的代码有一个神奇的数字 1000,但这是一个任意数字,足以让它比我必须存储的最大字符串大(而且我不知道确切的最大字符串长度是多少,但我确定它少于 1000)

Hash[
'elem' => string
'score' => 1000 - string.size
]

如何用sense删除这个魔数(Magic Number)?

最佳答案

分数必须是正数吗?如果不是:

'score' => -string.size

本质上,这是将 1000 替换为 0。0 是您可以使用的数字之一,但不会被视为魔法!

关于redis - 消除Redis中的魔数(Magic Number),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17568167/

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