当前位置:网站首页>.NET操作Redis sorted set有序集合
.NET操作Redis sorted set有序集合
2022-07-26 10:29:00 【矿工学编程】
一、sorted set有序集合概述
Redis 有序集合和集合一样也是 string 类型元素的集合,且不允许重复的成员。
不同的是每个元素都会关联一个 double 类型的分数。redis 正是通过分数来为集合中的成员进行从小到大的排序。
有序集合的成员是唯一的,但分数(score)却可以重复。
集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是 O(1)。 集合中最大的成员数为 232 - 1 (4294967295, 每个集合可存储40多亿个成员)。
二、使用场景
使用场景,做服务注册于发现,抽奖,限流,排行榜等
三、.NET 操作
1、基本操作
string zsett_key = "kgxk_zset";
//添加一个kye 如果有相同的值,则会替换(覆盖)进去,不会因为分数保留
client.AddItemToSortedSet(zsett_key, "cc", 33);
client.AddItemToSortedSet(zsett_key, "cc", 44);
client.AddItemToSortedSet(zsett_key, "cc", 22);
Console.WriteLine("ok");
//获取当前value的结果
Console.WriteLine(client.GetItemIndexInSortedSet(zsett_key, "cc"));
//批量操作多个key ,给多个key 赋值1
client.AddRangeToSortedSet(zsett_key, new List<string>() { "a", "b" }, 1);
foreach (var item in client.GetAllItemsFromSortedSet(zsett_key))
{
Console.WriteLine(item);
}2、根据下标范围获取值
client.AddItemToSortedSet("蜀国", "刘备", 5);
client.AddItemToSortedSet("蜀国", "关羽", 2);
client.AddItemToSortedSet("蜀国", "张飞", 3);
client.AddItemToSortedSet("魏国", "刘备", 5);
client.AddItemToSortedSet("魏国", "关羽", 2);
client.AddItemToSortedSet("蜀国", "张飞", 3);
//获取 key为蜀国的下标0,到2
IDictionary<String, double> Dic = client.GetRangeWithScoresFromSortedSet("蜀国", 0, 2);
foreach (var r in Dic)
{
Console.WriteLine(r.Key + ":" + r.Value);
}var DicString = client.StoreIntersectFromSortedSets("2", "蜀国", "魏国");
var ss = client.GetAllItemsFromSortedSet("2");
边栏推荐
- Use spiel expressions in custom annotations to dynamically obtain method parameters or execute methods
- Replay the snake game with C language (II) end
- 404页面和路由钩子
- C language course design Tetris (Part 2)
- Interview questions and answers for the second company (2)
- PTA class a 1001
- Mlx90640 infrared thermal imager temperature sensor module development notes (6)
- 2022pta平时训练题(1~10题字符串处理问题)
- 将json文件中数组转换为struct
- 如何写一篇百万阅读量的文章
猜你喜欢
![[Halcon vision] morphological corrosion](/img/f9/f01dd3340824ff28c84cf7bb52882e.png)
[Halcon vision] morphological corrosion

INSTALL_ FAILED_ SHARED_ USER_ Incompatible error resolution

如何写一篇百万阅读量的文章

Learning about tensorflow (II)

Learning about opencv (4)
![[Halcon vision] affine transformation](/img/f1/32284c71e78e6eea390fdb6058ba0f.png)
[Halcon vision] affine transformation

Okaleido ecological core equity Oka, all in fusion mining mode

Basics of data communication - basic knowledge of network

抓包工具fiddler和wireshark对比

我们的Web3创业项目,黄了
随机推荐
About automatic operation on Web pages
How to write a million reading article
Some descriptions of DS V2 push down in spark
单元测试,到底什么是单元测试,为什么单测这么难写
Function templates and non template functions with the same name cannot be overloaded (definition of overloads)
Controller返回JSON数据
PLC overview
Use spiel expressions in custom annotations to dynamically obtain method parameters or execute methods
【Halcon视觉】极坐标变换
【socket】三次握手是在listen中完成,accept只从完成连接的队列中拿出一个连接
string null转空字符串(空字符串是什么意思)
Use of pclint in vs2013
js下载文件,FileSaver.js导出txt、excel文件
Redis realizes the correct posture of token bucket
Li Kou daily question 917
移动端双指缩放事件(原生),e.originalEvent.touches
Learning about opencv (1)
码云,正式支持 Pages 功能,可以部署静态页面
关于函数模板描述错误的是(链接格式错误怎么解决)
INSTALL_ FAILED_ SHARED_ USER_ Incompatible error resolution