当前位置:网站首页>.net operation redis list list
.net operation redis list list
2022-07-26 10:33:00 【Miners learn programming】
One 、List List Overview
Redis List is a simple list of strings , Sort by insertion order . A list can contain at most 232 - 1 Elements (4294967295, Each list exceeds 40 100 million elements ).
Two 、 Use scenarios
Linked lists are widely used , There are many scenarios to obtain the latest data , Such as the following list of fans 、 My collection list 、 Latest news list 、 Ranking List 、 There is time axis data 、 Comment system of Weibo 、 The messaging 、 Parallel to serial 、 Message queue 、 Keep a log, etc .
3、 ... and 、.NET operation
1、 Add in sequence
string listid = "kgxk_list";
var litaibai = new UserInfo() { Id = 1, Name = " Li Taibai " };
client.AddItemToList(listid, JsonConvert.SerializeObject(litaibai));
var jiaxu = new UserInfo() { Id = 2, Name = " Jia Xu " };
client.AddItemToList(listid, JsonConvert.SerializeObject(jiaxu));
2、 stay list The last additional value
var liubei = new UserInfo() { Id = 1, Name = " Liu bei " };
client.PushItemToList(listid, JsonConvert.SerializeObject(liubei));
3、 Set expiration time
string listid = "kgxk_list";
var litaibai = new UserInfo() { Id = 1, Name = " Li Taibai " };
client.AddItemToList(listid, JsonConvert.SerializeObject(litaibai));
var liubei = new UserInfo() { Id = 2, Name = " Liu bei " };
client.PushItemToList(listid, JsonConvert.SerializeObject(liubei));
// Only store one second in memory
client.ExpireEntryAt(listid, DateTime.Now.AddSeconds(1));
Console.WriteLine(client.GetListCount(listid));
Task.Delay(1 * 1000).Wait();
Console.WriteLine("1 Seconds later ");
Console.WriteLine(client.GetListCount(listid));
// An avalanche problem : Instantly a large amount of data disappears -》 A lot of data should not disappear all at once
4、 Set expiration time Jump the queue ( Rank first )
var litaibai = new UserInfo() { Id = 1, Name = " Li Taibai " };
client.AddItemToList(listid, JsonConvert.SerializeObject(litaibai));
var jiaxu = new UserInfo() { Id = 2, Name = " Jia Xu " };
client.AddItemToList(listid, JsonConvert.SerializeObject(jiaxu));
var gaunyu = new UserInfo() { Id = 3, Name = " Guan yu " };
// Adding to the right is jumping in line
client.PrependItemToList(listid, JsonConvert.SerializeObject(gaunyu));
Console.WriteLine(" Jump the queue ");
var caomegndeng = new UserInfo() { Id = 4, Name = " Cao mengde " };
client.PrependItemToList(listid, JsonConvert.SerializeObject(caomegndeng));
5、 Batch addition
client.AddRangeToList(listid, new List<string>() { "001", "002", "003", "004" });
// Read in batches list The elements in
var lists = client.GetAllItemsFromList(listid);
foreach (var item in lists)
{
Console.WriteLine(item);
}
6、 obtain key Subscript is star To end Set of values for
client.AddRangeToList(listid, new List<string>() { "001", "002", "003", "004" });
var lists = client.GetRangeFromList(listid, 0, 1);// From the subscript 0 To 1 Value
foreach (var item in lists)
{
Console.WriteLine(item);
}
7、list Queue and set operations mq
var litaibai = new UserInfo() { Id = 1, Name = " Li Taibai " };
client.AddItemToList(listid, JsonConvert.SerializeObject(litaibai));
var jiaxu = new UserInfo() { Id = 2, Name = " Jia Xu " };
client.AddItemToList(listid, JsonConvert.SerializeObject(jiaxu));
var gaunyu = new UserInfo() { Id = 3, Name = " Guan yu " };
client.AddItemToList(listid, JsonConvert.SerializeObject(gaunyu));
var caomegndeng = new UserInfo() { Id = 3, Name = " Cao mengde " };
client.PrependItemToList(listid, JsonConvert.SerializeObject(caomegndeng));
// Remove the tail And return the removed data Delete first and then give the data
Console.WriteLine(client.RemoveEndFromList(listid));
foreach (var item in client.GetAllItemsFromList(listid))
{
Console.WriteLine(JsonConvert.DeserializeObject<UserInfo>(item).Name);
}
// Remove the header and return the removed data
Console.WriteLine(client.RemoveStartFromList(listid));
foreach (var item in client.GetAllItemsFromList(listid))
{
Console.WriteLine(JsonConvert.DeserializeObject<UserInfo>(item).Name);
}
// From a list Remove a piece of data at the end of , Add to another list The head of , And return the value of the move
Console.WriteLine(client.PopAndPushItemBetweenLists(listid, "newlist"));
Console.WriteLine(" The element result of the new queue after the move ");
Console.WriteLine(client.GetItemFromList("newlist", 0));
// Get the desired set element according to the subscript , Do not remove
var userstr = client.GetItemFromList(listid, 0);
Console.WriteLine(JsonConvert.DeserializeObject<UserInfo>(userstr).Name);
// Modify the result of the current subscript
client.SetItemInList(listid, 0, "new value");
边栏推荐
- Introduction to Phoenix (Level 1: Phoenix installation, level 2: Phoenix basic grammar)
- MLX90640 红外热成像仪测温传感器模块开发笔记(六)
- 【Halcon视觉】形态学腐蚀
- The reason why go language is particularly slow to develop run and build commands
- 卸载魅族应用商店
- PLC概述
- [C language] named type and anonymous type
- 少了个分号
- [leetcode每日一题2021/2/14]765. 情侣牵手
- Perfect / buffer motion framework in sentence parsing JS (for beginners)
猜你喜欢
随机推荐
Review of database -- 3. SQL language
canvas上传图片base64-有裁剪功能-Jcrop.js
js翻页、kkpager.js翻页
String null to empty string (what does empty string mean)
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
[socket] the three handshakes are completed in listen, and accept only takes out one connection from the queue that completes the connection
modelsim 安装教程(应用未安装)
PTA class a 1001
【socket】三次握手是在listen中完成,accept只从完成连接的队列中拿出一个连接
PLC overview
[Halcon vision] software programming ideas
Application of crosstab in SQL Server
[Halcon vision] image gray change
2022/07/25------字符串的排列
Use of Android grendao database
Interview questions and answers of the first company (I)
链式方法调用的事务问题剖析
Analyze the hybrid construction objects in JS in detail (construction plus attributes, prototype plus methods)
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
上传图片获取宽高