Skip to content

Commit f8c81ea

Browse files
committed
DEV: add TCEs to EXISTS command
1 parent 0e496ad commit f8c81ea

File tree

9 files changed

+1232
-0
lines changed

9 files changed

+1232
-0
lines changed

content/commands/exists.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ The user should be aware that if the same existing key is mentioned in the argum
5858

5959
## Examples
6060

61+
{{< clients-example set="cmds_generic" step="exists" >}}
62+
SET key1 "Hello"
63+
EXISTS key1
64+
EXISTS nosuchkey
65+
SET key2 "World"
66+
EXISTS key1 key2 nosuchkey
67+
{{< /clients-example >}}
68+
69+
Give these commands a try in the interactive console:
70+
6171
{{% redis-cli %}}
6272
SET key1 "Hello"
6373
EXISTS key1
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// EXAMPLE: cmds_generic
2+
// HIDE_START
3+
using NRedisStack.Tests;
4+
using StackExchange.Redis;
5+
6+
public class CmdsGenericExample
7+
{
8+
public void Run()
9+
{
10+
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
11+
var db = muxer.GetDatabase();
12+
// HIDE_END
13+
14+
// Tests for 'copy' step.
15+
16+
// STEP_START del
17+
bool delResult1 = db.StringSet("key1", "Hello");
18+
Console.WriteLine(delResult1); // >>> true
19+
20+
bool delResult2 = db.StringSet("key2", "World");
21+
Console.WriteLine(delResult2); // >>> true
22+
23+
long delResult3 = db.KeyDelete(["key1", "key2", "key3"]);
24+
Console.WriteLine(delResult3); // >>> 2
25+
26+
// Tests for 'del' step.
27+
// STEP_END
28+
29+
// Tests for 'dump' step.
30+
31+
// STEP_START exists
32+
bool existsResult1 = db.StringSet("key1", "Hello");
33+
Console.WriteLine(existsResult1); // >>> true
34+
35+
bool existsResult2 = db.KeyExists("key1");
36+
Console.WriteLine(existsResult2); // >>> true
37+
38+
bool existsResult3 = db.KeyExists("nosuchkey");
39+
Console.WriteLine(existsResult3); // >>> false
40+
41+
bool existsResult4 = db.StringSet("key2", "World");
42+
Console.WriteLine(existsResult4); // >>> true
43+
44+
long existsResult5 = db.KeyExists(["key1", "key2", "nosuchkey"]);
45+
Console.WriteLine(existsResult5); // >>> 2
46+
47+
// Tests for 'exists' step.
48+
// STEP_END
49+
50+
// STEP_START expire
51+
bool expireResult1 = db.StringSet("mykey", "Hello");
52+
Console.WriteLine(expireResult1); // >>> true
53+
54+
bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
55+
Console.WriteLine(expireResult2); // >>> true
56+
57+
TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
58+
Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10
59+
60+
bool expireResult4 = db.StringSet("mykey", "Hello World");
61+
Console.WriteLine(expireResult4); // >>> true
62+
63+
TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
64+
Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0
65+
66+
bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry);
67+
Console.WriteLine(expireResult6); // >>> false
68+
69+
TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
70+
Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0
71+
72+
bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry);
73+
Console.WriteLine(expireResult8); // >>> true
74+
75+
TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
76+
Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10
77+
78+
// Tests for 'expire' step.
79+
// STEP_END
80+
81+
// Tests for 'expireat' step.
82+
83+
// Tests for 'expiretime' step.
84+
85+
// Tests for 'keys' step.
86+
87+
// Tests for 'migrate' step.
88+
89+
// Tests for 'move' step.
90+
91+
// Tests for 'object_encoding' step.
92+
93+
// Tests for 'object_freq' step.
94+
95+
// Tests for 'object_idletime' step.
96+
97+
// Tests for 'object_refcount' step.
98+
99+
// Tests for 'persist' step.
100+
101+
// Tests for 'pexpire' step.
102+
103+
// Tests for 'pexpireat' step.
104+
105+
// Tests for 'pexpiretime' step.
106+
107+
// Tests for 'pttl' step.
108+
109+
// Tests for 'randomkey' step.
110+
111+
// Tests for 'rename' step.
112+
113+
// Tests for 'renamenx' step.
114+
115+
// Tests for 'restore' step.
116+
117+
// Tests for 'scan1' step.
118+
119+
// Tests for 'scan2' step.
120+
121+
// Tests for 'scan3' step.
122+
123+
// Tests for 'scan4' step.
124+
125+
// Tests for 'sort' step.
126+
127+
// Tests for 'sort_ro' step.
128+
129+
// Tests for 'touch' step.
130+
131+
// STEP_START ttl
132+
bool ttlResult1 = db.StringSet("mykey", "Hello");
133+
Console.WriteLine(ttlResult1); // >>> true
134+
135+
bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
136+
Console.WriteLine(ttlResult2);
137+
138+
TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
139+
string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString();
140+
Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10
141+
142+
// Tests for 'ttl' step.
143+
// STEP_END
144+
145+
// Tests for 'type' step.
146+
147+
// Tests for 'unlink' step.
148+
149+
// Tests for 'wait' step.
150+
151+
// Tests for 'waitaof' step.
152+
153+
// HIDE_START
154+
}
155+
}
156+
// HIDE_END

0 commit comments

Comments
 (0)