Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试发现Key不能够相同 #18

Open
kong9527 opened this issue May 26, 2023 · 1 comment
Open

测试发现Key不能够相同 #18

kong9527 opened this issue May 26, 2023 · 1 comment
Labels

Comments

@kong9527
Copy link

比如我们指定Key为分数,当相同分数插入的时候会被覆盖

@huandu
Copy link
Owner

huandu commented Jul 11, 2023

对,Key 是唯一的,跟 map 类似。可以通过指定自定义的 Comparable 来实现你的需求,甚至模拟 Redis ZSET 的效果,可以参考 GreaterThanFunc 的例子

具体做法:Key 不再是一个简单的数字,而是一个 struct { Name string; Value int },自己实现一个 Comparable,仅当 Name 相同的时候才算相等,其他时候比较 Value 大小来排序。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants