C#操作Redis Set無秩序集合
11234 ワード
1 ///
2 /// redis
3 ///
4 public static void Redis_Set()
5 {
6 RedisClient client = new RedisClient("127.0.0.1", 6379);
7 // ,
8 client.FlushAll();
9 #region Set
10 /*
11 string 。set hash table , , , , ,
12 */
13 client.AddItemToSet("Set1", "lily");
14 client.AddItemToSet("Set1", "lucy");
15 client.AddItemToSet("Set1", "hanmeimei");
16 client.AddItemToSet("Set1", "lilei");
17 HashSet<string> hastsetA = client.GetAllItemsFromSet("Set1");
18 foreach (string item in hastsetA)
19 {
20 Console.WriteLine("Set ValueA:{0}", item); //
21 }
22
23 client.AddItemToSet("Set2", "lilei");
24 client.AddItemToSet("Set2", "liming");
25 client.AddItemToSet("Set2", "lucy");
26 client.AddItemToSet("Set2", "mr wang");
27 HashSet<string> hastsetB = client.GetAllItemsFromSet("Set2");
28 foreach (string item in hastsetB)
29 {
30 Console.WriteLine("Set ValueB:{0}", item); //
31 }
32 //
33 HashSet<string> hashUnion = client.GetUnionFromSets(new string[] { "Set1", "Set2" });
34 //
35 foreach (string item in hashUnion)
36 {
37 Console.WriteLine(" Set1 Set2 :{0}", item); //
38 }
39 //
40 HashSet<string> hashG = client.GetIntersectFromSets(new string[] { "Set1", "Set2" });
41 //
42 foreach (string item in hashG)
43 {
44 Console.WriteLine(" Set1 Set2 :{0}", item); //
45 }
46 //[ , 。 ]
47 HashSet<string> hashD = client.GetDifferencesFromSet("Set1", new string[] { "Set2" });
48 foreach (string item in hashD)
49 {
50 Console.WriteLine(" Set1 Set2 :{0}", item); //
51 }
52
53 #endregion
54 }
転載先:https://www.cnblogs.com/happygx/p/8416634.html