@@ -33,11 +33,11 @@ import TabItem from '@theme/TabItem';
3333 <td >
3434 <pre >
3535 <code >{ `
36- KEYS *name
36+ KEYS my*
3737` } </code >
3838 </pre >
3939 </td >
40- <td >[ "firstname", "lastname" ] </td >
40+ <td >1) "myKey" 2) "myCounter" </td >
4141 </tr >
4242 <tr >
4343 <td colspan = " 4" >
@@ -51,7 +51,7 @@ KEYS *name
5151 <td >
5252 <pre >
5353 <code >{ `
54- EXISTS mykey
54+ EXISTS myKey
5555` } </code >
5656 </pre >
5757 </td >
@@ -69,7 +69,7 @@ EXISTS mykey
6969 <td >
7070 <pre >
7171 <code >{ `
72- EXPIRE mykey 120
72+ EXPIRE myKey 120
7373` } </code >
7474 </pre >
7575 </td >
@@ -83,40 +83,40 @@ EXPIRE mykey 120
8383 </td >
8484 </tr >
8585 <tr >
86- <td >PERSIST </td >
87- <td >PERSIST key</td >
86+ <td >TTL </td >
87+ <td >TTL key</td >
8888 <td >
8989 <pre >
9090 <code >{ `
91- PERSIST mykey
91+ TTL myKey
9292` } </code >
9393 </pre >
9494 </td >
95- <td >(integer) 1 </td >
95+ <td >(integer) 113 </td >
9696 </tr >
9797 <tr >
9898 <td colspan = " 4" >
99- <em >Description:</em > Removes the expiration from a key.
100- <em >Time Complexity:</em >
101- O(1)
99+ <em >Description:</em > Returns the remaining time to live of a key that
100+ has a timeout.<em >Time Complexity:</em > O(1)
102101 </td >
103102 </tr >
104103 <tr >
105- <td >TTL </td >
106- <td >TTL key</td >
104+ <td >PERSIST </td >
105+ <td >PERSIST key</td >
107106 <td >
108107 <pre >
109108 <code >{ `
110- TTL mykey
109+ PERSIST myKey
111110` } </code >
112111 </pre >
113112 </td >
114- <td >(integer) 113 </td >
113+ <td >(integer) 1 </td >
115114 </tr >
116115 <tr >
117116 <td colspan = " 4" >
118- <em >Description:</em > Returns the remaining time to live of a key that
119- has a timeout.<em >Time Complexity:</em > O(1)
117+ <em >Description:</em > Removes the expiration from a key.
118+ <em >Time Complexity:</em >
119+ O(1)
120120 </td >
121121 </tr >
122122 <tr >
@@ -129,15 +129,22 @@ SCAN 0 MATCH my* COUNT 2
129129` } </code >
130130 </pre >
131131 </td >
132- <td >1) "0" 2) 1) "mykey" 2) "myotherkey"</td >
132+ <td >1) "3" 2) 1) "myCounter" 2) "myKey"</td >
133+ </tr >
134+ <tr >
135+ <td colspan = " 4" >
136+ <em >Description:</em > Iterates the set of keys in the currently selected
137+ Redis database.<em >Time Complexity:</em > O(1) for every call. O(N) for a
138+ complete iteration.
139+ </td >
133140 </tr >
134141 <tr >
135142 <td >DEL</td >
136143 <td >DEL key [ key ...] </td >
137144 <td >
138145 <pre >
139146 <code >{ `
140- DEL mykey
147+ DEL myKey
141148` } </code >
142149 </pre >
143150 </td >
@@ -149,13 +156,6 @@ DEL mykey
149156 <em >Time Complexity:</em > O(N)
150157 </td >
151158 </tr >
152- <tr >
153- <td colspan = " 4" >
154- <em >Description:</em > Iterates the set of keys in the currently selected
155- Redis database.<em >Time Complexity:</em > O(1) for every call. O(N) for a
156- complete iteration.
157- </td >
158- </tr >
159159 <tr >
160160 <td >INFO</td >
161161 <td >INFO [ section] </td >
@@ -188,8 +188,8 @@ INFO keyspace
188188 <tr >
189189 <td colspan = " 4" >
190190 <em >Description:</em >
191- Returns information and statistics about the server, with the following sections:
192- server, clients, memory, persistence, stats, replication, cpu, commandstats,
191+ Returns information and statistics about the server, with the different sections
192+ like - server, clients, memory, persistence, stats, replication, cpu, commandstats,
193193 latencystats, sentinel, cluster, modules, keyspace, errorstats.<em >
194194 Time Complexity:
195195 </em > O(1)
@@ -202,6 +202,97 @@ INFO keyspace
202202
203203<TabItem value = " NODE_JS" >
204204
205+ ``` js
206+ /*
207+ KEYS pattern
208+ Returns all keys matching pattern.
209+ Time Complexity: O(N)
210+ */
211+ const keysResult = await client .keys (' my*' );
212+ console .log (keysResult); // ["myKey", "myCounter"]
213+
214+ /*
215+ EXISTS key [key ...]
216+ Checks if one or more keys exist.
217+ Time Complexity: O(N)
218+ */
219+ const existsResult = await client .exists (' myKey' );
220+ console .log (existsResult); // 1
221+
222+ /*
223+ EXPIRE key seconds
224+ Set a timeout on a key. After the timeout has expired, the key will automatically be deleted.
225+ Time Complexity: O(1)
226+ */
227+ const expireResult = await client .expire (' myKey' , 120 );
228+ console .log (expireResult); // true
229+
230+ /*
231+ TTL key
232+ Returns the remaining time to live of a key that has a timeout.
233+ Time Complexity: O(1)
234+ */
235+ const ttlResult = await client .ttl (' myKey' );
236+ console .log (ttlResult); // 113
237+
238+ /*
239+ PERSIST key
240+ Removes the expiration from a key.
241+ Time Complexity: O(1)
242+ */
243+ const persistResult = await client .persist (' myKey' );
244+ console .log (persistResult); // true
245+
246+ /*
247+ SCAN cursor [MATCH pattern] [COUNT count]
248+ Iterates the set of keys in the currently selected Redis database.
249+ Time Complexity: O(1) for every call. O(N) for a complete iteration.
250+ */
251+ const scanOptions = {
252+ TYPE : ' string' ,
253+ MATCH : ' my*' ,
254+ COUNT : 2 ,
255+ };
256+ let cursor = 0 ;
257+
258+ // scan 1
259+ let scanResult = await client .scan (cursor, scanOptions);
260+ console .log (scanResult); // { cursor: 4, keys: [ 'myCounter', 'myKey' ] }
261+
262+ // scan 2
263+ cursor = scanResult .cursor ;
264+ scanResult = await client .scan (cursor, scanOptions);
265+ console .log (scanResult); // { cursor: 12, keys: [ 'myOtherkey' ] }
266+
267+ // ... scan n
268+
269+ console .log (' OR use any loop to continue the scan by cursor value' );
270+ cursor = 0 ;
271+ do {
272+ scanResult = await client .scan (cursor, scanOptions);
273+ console .log (scanResult);
274+ cursor = scanResult .cursor ;
275+ } while (cursor != 0 );
276+
277+ /*
278+ DEL key [key ...]
279+ Removes the specified keys.
280+ Time Complexity: O(N)
281+ */
282+ const delResult = await client .del (' myKey' );
283+ console .log (delResult); // 1
284+
285+ /*
286+ INFO [section]
287+ Returns information and statistics about the server, with the different sections
288+ like - server, clients, memory, persistence, stats, replication, cpu, commandstats,
289+ latencystats, sentinel, cluster, modules, keyspace, errorstats.
290+ Time Complexity: O(1)
291+ */
292+ let infoResult = await client .info (' keyspace' );
293+ console .log (infoResult); // # Keyspace \n db0:keys=2,expires=0,avg_ttl=0"
294+ ```
295+
205296</TabItem >
206297
207298</Tabs >
0 commit comments