/
Program.cs
106 lines (81 loc) · 3.16 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Redis MGET command examples in C#
using StackExchange.Redis;
namespace Mget
{
internal class Program
{
static void Main(string[] args)
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase rdb = redis.GetDatabase();
/**
* Set some values
*
* Command: set firstkey "my first value"
* Result: OK
*/
var setCommandResult = rdb.StringSet("firstkey", "my first value");
Console.WriteLine("Command: set firstkey \"my first value\" | Result: " + setCommandResult);
/**
* Command: set secondkey "bigboxcode"
* Result: OK
*/
setCommandResult = rdb.StringSet("secondkey", "bigboxcode");
Console.WriteLine("Command: set secondkey \"bigboxcode\" | Result: " + setCommandResult);
/**
* Command: set user:100 "john"
* Result: OK
*/
setCommandResult = rdb.StringSet("user:100", "john");
Console.WriteLine("Command: set user:100 \"john\" | Result: " + setCommandResult);
/**
* Try to get values for 3 keys
*
* Command: mget firstkey secondkey user:100
* Result:
* 1) "my first value"
* 2) "bigboxcode"
* 3) "john"
*/
var resultList = rdb.StringGet(new RedisKey[] { "firstkey", "secondkey", "user:100" });
Console.WriteLine("Command: mget firstkey secondkey user:100 | Result: ");
foreach (var item in resultList)
{
Console.WriteLine(item);
}
/**
* We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
*
* Command: mget firstkey secondkey wrongkey
* Result:
* 1) "my first value"
* 2) "bigboxcode"
* 3) (nil)
*/
resultList = rdb.StringGet(new RedisKey[] { "firstkey", "secondkey", "wrongkey" });
Console.WriteLine("Command: mget firstkey secondkey wrongkey | Result: ");
foreach (var item in resultList)
{
Console.WriteLine(item);
}
/**
* Here we are provideing "firstkey" multiple times
*
* Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
* Result:
* 1) "my first value"
* 2) "my first value"
* 3) "bigboxcode"
* 4) (nil)
* 5) "john"
* 6) "my first value"
*/
resultList = rdb.StringGet(new RedisKey[] { "firstkey", "firstkey", "secondkey", "wrongkey", "user:100", "firstkey" });
Console.WriteLine("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkeymget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: ");
foreach (var item in resultList)
{
Console.WriteLine(item);
}
}
}
}