@devvit/redis 0.11.16-next-2025-05-21-9df7afc74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +5 -0
- package/RedisClient.d.ts +108 -0
- package/RedisClient.d.ts.map +1 -0
- package/RedisClient.js +615 -0
- package/RedisClient.test.d.ts.map +1 -0
- package/getRedis.d.ts +4 -0
- package/getRedis.d.ts.map +1 -0
- package/getRedis.js +10 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -0
- package/package.json +44 -0
- package/types/redis.d.ts +1514 -0
- package/types/redis.d.ts.map +1 -0
- package/types/redis.js +1 -0
package/types/redis.d.ts
ADDED
|
@@ -0,0 +1,1514 @@
|
|
|
1
|
+
import type { HScanResponse, ZScanResponse } from '@devvit/protos';
|
|
2
|
+
export type TxClientLike = {
|
|
3
|
+
/**
|
|
4
|
+
* Executes all previously queued commands in a transaction and
|
|
5
|
+
* restores the connection state to normal. https://redis.io/commands/exec/
|
|
6
|
+
* @returns array, each element being the reply to each of the commands in the atomic transaction.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* async function execExample(context: Devvit.Context) {
|
|
10
|
+
* await context.redis.set("karma", "32");
|
|
11
|
+
*
|
|
12
|
+
* const txn = await context.redis.watch("quantity");
|
|
13
|
+
*
|
|
14
|
+
* await txn.multi(); // Begin a transaction
|
|
15
|
+
* await txn.incrby("karma", 10);
|
|
16
|
+
* await txn.exec(); // Execute the commands in the transaction
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
exec(): Promise<any[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Marks the start of a transaction block. Subsequent commands will be
|
|
23
|
+
* queued for atomic execution using EXEC. https://redis.io/commands/multi/
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* async function multiExample(context: Devvit.Context) {
|
|
27
|
+
* await context.redis.set("karma", "32");
|
|
28
|
+
*
|
|
29
|
+
* const txn = await context.redis.watch("quantity");
|
|
30
|
+
*
|
|
31
|
+
* await txn.multi(); // Begin a transaction
|
|
32
|
+
* await txn.incrby("karma", 10);
|
|
33
|
+
* await txn.exec(); // Execute the commands in the transaction
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
multi(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Flushes all previously queued commands in a transaction and restores the connection state to normal.
|
|
40
|
+
* If WATCH was used, DISCARD unwatches all keys watched by the connection. https://redis.io/docs/latest/commands/discard/
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* async function discardExample(context: Devvit.Context) {
|
|
44
|
+
* await context.redis.set("price", "25");
|
|
45
|
+
*
|
|
46
|
+
* const txn = await context.redis.watch("price");
|
|
47
|
+
*
|
|
48
|
+
* await txn.multi(); // Begin a transaction
|
|
49
|
+
* await txn.incrby("price", 5);
|
|
50
|
+
* await txn.discard(); // Discard the commands in the transaction
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
discard(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Marks the given keys to be watched for conditional execution of a transaction.
|
|
57
|
+
* https://redis.io/commands/watch/
|
|
58
|
+
* @arg {} keys - given keys to be watched
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* async function watchExample(context: Devvit.Context) {
|
|
62
|
+
* await context.redis.set("karma", "32");
|
|
63
|
+
*
|
|
64
|
+
* const txn = await context.redis.watch("quantity");
|
|
65
|
+
*
|
|
66
|
+
* await txn.multi(); // Begin a transaction
|
|
67
|
+
* await txn.incrby("karma", 10);
|
|
68
|
+
* await txn.exec(); // Execute the commands in the transaction
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
watch(...keys: string[]): Promise<TxClientLike>;
|
|
73
|
+
/**
|
|
74
|
+
* Flushes all the previously watched keys for a transaction.
|
|
75
|
+
* If you call EXEC or DISCARD, there's no need to manually call UNWATCH.
|
|
76
|
+
* https://redis.io/commands/unwatch/
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* async function unwatchExample(context: Devvit.Context) {
|
|
80
|
+
* await context.redis.set("gold", "50");
|
|
81
|
+
*
|
|
82
|
+
* const txn = await context.redis.watch("gold");
|
|
83
|
+
*
|
|
84
|
+
* await txn.multi(); // Begin a transaction
|
|
85
|
+
* await txn.incrby("gold", 30);
|
|
86
|
+
* await txn.unwatch(); // Unwatch "gold"
|
|
87
|
+
*
|
|
88
|
+
* // Now that "gold" has been unwatched, we can increment its value
|
|
89
|
+
* // outside the transaction without canceling the transaction
|
|
90
|
+
* await context.redis.incrby("gold", -20);
|
|
91
|
+
*
|
|
92
|
+
* await txn.exec(); // Execute the commands in the transaction
|
|
93
|
+
*
|
|
94
|
+
* console.log("Gold value: " + await context.redis.get("gold")); // The value of 'gold' should be 50 + 30 - 20 = 60
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
unwatch(): Promise<TxClientLike>;
|
|
99
|
+
/**
|
|
100
|
+
* Get the value of key. If the key does not exist the special value nil is returned.
|
|
101
|
+
* https://redis.io/commands/get/
|
|
102
|
+
* @arg {} key
|
|
103
|
+
* @returns value of key or null when key does not exist.
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* async function getExample(context: Devvit.Context) {
|
|
107
|
+
* await context.redis.set("quantity", "5");
|
|
108
|
+
* const quantity : string | undefined = await context.redis.get("quantity");
|
|
109
|
+
* console.log("Quantity: " + quantity);
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
get(key: string): Promise<TxClientLike>;
|
|
114
|
+
/**
|
|
115
|
+
* Set key to hold the string value. If key already holds a value, it is overwritten
|
|
116
|
+
* https://redis.io/commands/set/
|
|
117
|
+
* @arg {} key
|
|
118
|
+
* @arg {} value
|
|
119
|
+
* @arg {} options
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* async function setExample(context: Devvit.Context) {
|
|
123
|
+
* await context.redis.set("quantity", "5");
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
set(key: string, value: string, options?: SetOptions): Promise<TxClientLike>;
|
|
128
|
+
/**
|
|
129
|
+
* Removes the specified keys. A key is ignored if it does not exist.
|
|
130
|
+
* https://redis.io/commands/del/
|
|
131
|
+
* @arg {} keys
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* async function delExample(context: Devvit.Context) {
|
|
135
|
+
* await context.redis.set("quantity", "5");
|
|
136
|
+
* await context.redis.del("quantity");
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
del(...keys: string[]): Promise<TxClientLike>;
|
|
141
|
+
/**
|
|
142
|
+
* Increments the number stored at key by increment.
|
|
143
|
+
* https://redis.io/commands/incrby/
|
|
144
|
+
* @arg {} key
|
|
145
|
+
* @arg {} value
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* async function incrByExample(context: Devvit.Context) {
|
|
149
|
+
* await context.redis.set("totalPoints", "53")
|
|
150
|
+
* const updatedPoints : number = await context.redis.incrby("totalPoints", 100);
|
|
151
|
+
* console.log("Updated points: " + updatedPoints);
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
incrby(key: string, value: number): Promise<TxClientLike>;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the string representation of the type of the value stored at key
|
|
158
|
+
* https://redis.io/commands/type/
|
|
159
|
+
* @arg {} key
|
|
160
|
+
* @returns string representation of the type
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* async function typeExample(context: Devvit.Context) {
|
|
164
|
+
* await context.redis.set("quantity", "5");
|
|
165
|
+
* const type : string = await context.redis.type("quantity");
|
|
166
|
+
* console.log("Key type: " + type);
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
type(key: string): Promise<TxClientLike>;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the substring of the string value stored at key, determined by
|
|
173
|
+
* the offsets start and end (both are inclusive).
|
|
174
|
+
* https://redis.io/commands/getrange/
|
|
175
|
+
* @arg {} key
|
|
176
|
+
* @arg {} start
|
|
177
|
+
* @arg {} end
|
|
178
|
+
* @returns substring determined by offsets [start, end]
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* async function getRangeExample(context: Devvit.Context) {
|
|
182
|
+
* await context.redis.set("word", "tacocat");
|
|
183
|
+
* const range : string = await context.redis.getrange("word", 0, 3)
|
|
184
|
+
* console.log("Range from index 0 to 3: " + range);
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
getrange(key: string, start: number, end: number): Promise<TxClientLike>;
|
|
189
|
+
/**
|
|
190
|
+
* Overwrites part of the string stored at key, starting at the
|
|
191
|
+
* specified offset, for the entire length of value.
|
|
192
|
+
* https://redis.io/commands/setrange/
|
|
193
|
+
* @arg {} key
|
|
194
|
+
* @arg {} offset
|
|
195
|
+
* @arg {} value
|
|
196
|
+
* @returns length of the string after it was modified by the command
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* async function setRangeExample(context: Devvit.Context) {
|
|
200
|
+
* await context.redis.set("word", "tacocat");
|
|
201
|
+
* await context.redis.setrange("word", 0, "blue");
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
setrange(key: string, offset: number, value: string): Promise<TxClientLike>;
|
|
206
|
+
/**
|
|
207
|
+
* Returns the length of the string value stored at key.
|
|
208
|
+
* An error is returned when key holds a non-string value.
|
|
209
|
+
* https://redis.io/commands/strlen/
|
|
210
|
+
* @arg {} key
|
|
211
|
+
* @returns length of the string stored at key
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* async function strLenExample(context: Devvit.Context) {
|
|
215
|
+
* await context.redis.set("word", "tacocat");
|
|
216
|
+
* const length : number = await context.redis.strlen("word");
|
|
217
|
+
* console.log("Length of word: " + length);
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
strlen(key: string): Promise<TxClientLike>;
|
|
222
|
+
/**
|
|
223
|
+
* Returns the values of all specified keys.
|
|
224
|
+
* https://redis.io/commands/mget/
|
|
225
|
+
* @arg {} keys
|
|
226
|
+
* @returns list of values at the specified keys
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* async function mGetExample(context: Devvit.Context) {
|
|
230
|
+
* await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
|
|
231
|
+
* const result : (string | null)[] = await context.redis.mget(["name", "occupation"]);
|
|
232
|
+
* result.forEach(x => {
|
|
233
|
+
* console.log(x);
|
|
234
|
+
* });
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
mget(keys: string[]): Promise<TxClientLike>;
|
|
239
|
+
/**
|
|
240
|
+
* Sets the given keys to their respective values.
|
|
241
|
+
* https://redis.io/commands/mset/
|
|
242
|
+
* @arg {} keyValues
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* async function mGetExample(context: Devvit.Context) {
|
|
246
|
+
* await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
|
|
247
|
+
* const result : (string | null)[] = await context.redis.mget(["name", "occupation"]);
|
|
248
|
+
* result.forEach(x => {
|
|
249
|
+
* console.log(x);
|
|
250
|
+
* });
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
mset(keyValues: {
|
|
255
|
+
[key: string]: string;
|
|
256
|
+
}): Promise<TxClientLike>;
|
|
257
|
+
/**
|
|
258
|
+
* Set a timeout on key.
|
|
259
|
+
* https://redis.io/commands/expire/
|
|
260
|
+
* @arg {} key
|
|
261
|
+
* @arg {} seconds
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* async function expireExample(context: Devvit.Context) {
|
|
265
|
+
* await context.redis.set("product", "milk");
|
|
266
|
+
* await context.redis.expire("product", 60); // Set the product to expire in 60 seconds
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
expire(key: string, seconds: number): Promise<TxClientLike>;
|
|
271
|
+
/**
|
|
272
|
+
* Returns the absolute Unix timestamp in seconds at which the given key will expire
|
|
273
|
+
* https://redis.io/commands/expiretime/
|
|
274
|
+
* @arg {} key
|
|
275
|
+
* @returns expiration Unix timestamp in seconds, or a negative value in order to signal an error
|
|
276
|
+
* @example
|
|
277
|
+
* async function expireTimeExample(context: Devvit.Context) {
|
|
278
|
+
* await context.redis.set("product", "milk");
|
|
279
|
+
* const expireTime : number = await context.redis.expiretime("product");
|
|
280
|
+
* console.log("Expire time: " + expireTime);
|
|
281
|
+
* }
|
|
282
|
+
*/
|
|
283
|
+
expiretime(key: string): Promise<TxClientLike>;
|
|
284
|
+
/**
|
|
285
|
+
* Adds all the specified members with the specified scores to the sorted set stored at key.
|
|
286
|
+
* https://redis.io/commands/zadd/
|
|
287
|
+
* @arg {} key
|
|
288
|
+
* @arg {} members
|
|
289
|
+
* @returns number of elements added to the sorted set
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* async function zAddExample(context: Devvit.Context) {
|
|
293
|
+
* const numMembersAdded : number = await context.redis.zadd("leaderboard",
|
|
294
|
+
* {member: "louis", score: 37},
|
|
295
|
+
* {member: "fernando", score: 10},
|
|
296
|
+
* {member: "caesar", score: 20},
|
|
297
|
+
* {member: "alexander", score: 25},
|
|
298
|
+
* );
|
|
299
|
+
* console.log("Number of members added: " + numMembersAdded);
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
zadd(key: string, ...members: ZMember[]): Promise<TxClientLike>;
|
|
304
|
+
/**
|
|
305
|
+
* Returns the cardinality (number of elements) of the sorted set stored at key.
|
|
306
|
+
* https://redis.io/commands/zcard/
|
|
307
|
+
* @arg {} key
|
|
308
|
+
* @returns cardinality of the sorted set
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* async function zCardExample(context: Devvit.Context) {
|
|
312
|
+
* await context.redis.zadd("leaderboard",
|
|
313
|
+
* {member: "louis", score: 37},
|
|
314
|
+
* {member: "fernando", score: 10},
|
|
315
|
+
* {member: "caesar", score: 20},
|
|
316
|
+
* {member: "alexander", score: 25},
|
|
317
|
+
* );
|
|
318
|
+
* const cardinality : number = await context.redis.zcard("leaderboard");
|
|
319
|
+
* console.log("Cardinality: " + cardinality);
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
zcard(key: string): Promise<TxClientLike>;
|
|
324
|
+
/**
|
|
325
|
+
* Increments the score of member in the sorted set stored at key by value
|
|
326
|
+
* https://redis.io/commands/zincrby/
|
|
327
|
+
* @arg {} key
|
|
328
|
+
* @arg {} member
|
|
329
|
+
* @arg {} value
|
|
330
|
+
* @returns the new score of member as a double precision floating point number
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* async function zIncrByExample(context: Devvit.Context) {
|
|
334
|
+
* await context.redis.zadd("animals",
|
|
335
|
+
* {member: "zebra", score: 92},
|
|
336
|
+
* {member: "cat", score: 100},
|
|
337
|
+
* {member: "dog", score: 95},
|
|
338
|
+
* {member: "elephant", score: 97}
|
|
339
|
+
* );
|
|
340
|
+
* const updatedScore : number = await context.redis.zincrby("animals", "dog", 10);
|
|
341
|
+
* console.log("Dog's updated score: " + updatedScore);
|
|
342
|
+
* }
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
zincrby(key: string, member: string, value: number): Promise<TxClientLike>;
|
|
346
|
+
/**
|
|
347
|
+
* Returns the rank of member in the sorted set stored at key
|
|
348
|
+
* https://redis.io/commands/zrank/
|
|
349
|
+
* @arg {} key
|
|
350
|
+
* @arg {} member
|
|
351
|
+
* @returns rank of the member. The rank (or index) is 0-based
|
|
352
|
+
* which means that the member with the lowest score has rank 0
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* async function zRankExample(context: Devvit.Context) {
|
|
356
|
+
* await context.redis.zadd("animals",
|
|
357
|
+
* {member: "zebra", score: 92},
|
|
358
|
+
* {member: "cat", score: 100},
|
|
359
|
+
* {member: "dog", score: 95},
|
|
360
|
+
* {member: "elephant", score: 97}
|
|
361
|
+
* );
|
|
362
|
+
* const rank : number = await context.redis.zrank("animals", "dog");
|
|
363
|
+
* console.log("Dog's rank: " + rank);
|
|
364
|
+
* }
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
zrank(key: string, member: string): Promise<TxClientLike>;
|
|
368
|
+
/**
|
|
369
|
+
* Returns the score of member in the sorted set at key.
|
|
370
|
+
* https://redis.io/commands/zscore/
|
|
371
|
+
* @arg {} key
|
|
372
|
+
* @arg {} member
|
|
373
|
+
* @returns the score of the member (a double-precision floating point number).
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* async function zScoreExample(context: Devvit.Context) {
|
|
377
|
+
* await context.redis.zadd("leaderboard",
|
|
378
|
+
* {member: "louis", score: 37},
|
|
379
|
+
* {member: "fernando", score: 10},
|
|
380
|
+
* {member: "caesar", score: 20},
|
|
381
|
+
* {member: "alexander", score: 25},
|
|
382
|
+
* );
|
|
383
|
+
* const score : number | undefined = await context.redis.zscore("leaderboard", "caesar");
|
|
384
|
+
* if(score !== undefined) {
|
|
385
|
+
* console.log("Caesar's score: " + score);
|
|
386
|
+
* }
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
zscore(key: string, member: string): Promise<TxClientLike>;
|
|
391
|
+
/**
|
|
392
|
+
* Iterates elements of Sorted Set types and their associated scores.
|
|
393
|
+
* @arg {} key
|
|
394
|
+
* @arg {} cursor
|
|
395
|
+
* @arg {} pattern
|
|
396
|
+
* @arg {} count
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* async function zScanExample(context: Devvit.Context) {
|
|
400
|
+
* await context.redis.zadd("fruits",
|
|
401
|
+
* {member: "kiwi", score: 0},
|
|
402
|
+
* {member: "mango", score: 0},
|
|
403
|
+
* {member: "banana", score: 0},
|
|
404
|
+
* {member: "orange", score: 0},
|
|
405
|
+
* {member: "apple", score: 0},
|
|
406
|
+
* );
|
|
407
|
+
* const zScanResponse = await context.redis.zscan("fruits", 0);
|
|
408
|
+
* console.log("zScanResponse: " + JSON.stringify(zScanResponse));
|
|
409
|
+
* }
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
zscan(key: string, cursor: number, pattern?: string | undefined, count?: number | undefined): Promise<TxClientLike>;
|
|
413
|
+
/**
|
|
414
|
+
* Returns the specified range of elements in the sorted set stored at key.
|
|
415
|
+
* https://redis.io/commands/zrange/
|
|
416
|
+
*
|
|
417
|
+
* When using `by: 'lex'`, the start and stop inputs will be prepended with `[` by default, unless they already begin with `[`, `(` or are one of the special values `+` or `-`.
|
|
418
|
+
* @arg {} key
|
|
419
|
+
* @arg {} start
|
|
420
|
+
* @arg {} stop
|
|
421
|
+
* @arg {} options
|
|
422
|
+
* @returns list of elements in the specified range
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* async function zRangeExample(context: Devvit.Context) {
|
|
426
|
+
* await context.redis.zadd("leaderboard",
|
|
427
|
+
* {member: "louis", score: 37},
|
|
428
|
+
* {member: "fernando", score: 10},
|
|
429
|
+
* {member: "caesar", score: 20},
|
|
430
|
+
* {member: "alexander", score: 25},
|
|
431
|
+
* );
|
|
432
|
+
*
|
|
433
|
+
* // View elements with scores between 0 and 30 inclusive, sorted by score
|
|
434
|
+
* const scores : {member : string, score : number}[] = await context.redis.zrange("leaderboard", 0, 30, { by: "score" });
|
|
435
|
+
*
|
|
436
|
+
* scores.forEach(x => {
|
|
437
|
+
* console.log("Member: " + x.member, ", Score: " + x.score);
|
|
438
|
+
* });
|
|
439
|
+
* }
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
zrange(key: string, start: number | string, stop: number | string, options?: ZRangeOptions): Promise<TxClientLike>;
|
|
443
|
+
/**
|
|
444
|
+
* Removes the specified members from the sorted set stored at key.
|
|
445
|
+
* https://redis.io/commands/zrem/
|
|
446
|
+
* @arg {} key
|
|
447
|
+
* @arg {} members
|
|
448
|
+
* @returns number of members removed from the sorted set
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* async function zRemExample(context: Devvit.Context) {
|
|
452
|
+
* await context.redis.zadd("leaderboard",
|
|
453
|
+
* {member: "louis", score: 37},
|
|
454
|
+
* {member: "fernando", score: 10},
|
|
455
|
+
* {member: "caesar", score: 20},
|
|
456
|
+
* {member: "alexander", score: 25},
|
|
457
|
+
* );
|
|
458
|
+
* const numberOfMembersRemoved : number = await context.redis.zrem("leaderboard", ["fernando", "alexander"]);
|
|
459
|
+
* console.log("Number of members removed: " + numberOfMembersRemoved);
|
|
460
|
+
* }
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
zrem(key: string, members: string[]): Promise<TxClientLike>;
|
|
464
|
+
/**
|
|
465
|
+
* removes all elements in the sorted set stored at key between the
|
|
466
|
+
* lexicographical range specified by min and max
|
|
467
|
+
* https://redis.io/commands/zremrangebylex/
|
|
468
|
+
* @arg {} key
|
|
469
|
+
* @arg {} min
|
|
470
|
+
* @arg {} max
|
|
471
|
+
* @returns number of members removed from the sorted set
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts
|
|
474
|
+
* async function zRemRangeByLexExample(context: Devvit.Context) {
|
|
475
|
+
* await context.redis.zadd("fruits",
|
|
476
|
+
* {member: "kiwi", score: 0},
|
|
477
|
+
* {member: "mango", score: 0},
|
|
478
|
+
* {member: "banana", score: 0},
|
|
479
|
+
* {member: "orange", score: 0},
|
|
480
|
+
* {member: "apple", score: 0},
|
|
481
|
+
* );
|
|
482
|
+
*
|
|
483
|
+
* // Remove fruits alphabetically ordered between 'kiwi' inclusive and 'orange' exclusive
|
|
484
|
+
* // Note: The symbols '[' and '(' indicate inclusive or exclusive, respectively. These must be included in the call to zremrangebylex().
|
|
485
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebylex("fruits", "[kiwi", "(orange");
|
|
486
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
487
|
+
* }
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
zremrangebylex(key: string, min: string, max: string): Promise<TxClientLike>;
|
|
491
|
+
/**
|
|
492
|
+
* Removes all elements in the sorted set stored at key with rank between start and stop.
|
|
493
|
+
* https://redis.io/commands/zremrangebyrank/
|
|
494
|
+
* @arg {} key
|
|
495
|
+
* @arg {} start
|
|
496
|
+
* @arg {} stop
|
|
497
|
+
* @returns number of members removed from the sorted set
|
|
498
|
+
* @example
|
|
499
|
+
* ```
|
|
500
|
+
* async function zRemRangeByRankExample(context: Devvit.Context) {
|
|
501
|
+
* await context.redis.zadd("fruits",
|
|
502
|
+
* {member: "kiwi", score: 10},
|
|
503
|
+
* {member: "mango", score: 20},
|
|
504
|
+
* {member: "banana", score: 30},
|
|
505
|
+
* {member: "orange", score: 40},
|
|
506
|
+
* {member: "apple", score: 50},
|
|
507
|
+
* );
|
|
508
|
+
|
|
509
|
+
* // Remove fruits ranked 1 through 3 inclusive
|
|
510
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebyrank("fruits", 1, 3);
|
|
511
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
512
|
+
* }
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
zremrangebyrank(key: string, start: number, stop: number): Promise<TxClientLike>;
|
|
516
|
+
/**
|
|
517
|
+
* Removes all elements in the sorted set stored at key with a score between min and max
|
|
518
|
+
* https://redis.io/commands/zremrangebyscore/
|
|
519
|
+
* @arg {} key
|
|
520
|
+
* @arg {} min
|
|
521
|
+
* @arg {} max
|
|
522
|
+
* @returns number of members removed from the sorted set
|
|
523
|
+
* @example
|
|
524
|
+
* ```ts
|
|
525
|
+
* async function zRemRangeByScoreExample(context: Devvit.Context) {
|
|
526
|
+
* await context.redis.zadd("fruits",
|
|
527
|
+
* {member: "kiwi", score: 10},
|
|
528
|
+
* {member: "mango", score: 20},
|
|
529
|
+
* {member: "banana", score: 30},
|
|
530
|
+
* {member: "orange", score: 40},
|
|
531
|
+
* {member: "apple", score: 50},
|
|
532
|
+
* );
|
|
533
|
+
* // Remove fruits scored between 30 and 50 inclusive
|
|
534
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebyscore("fruits", 30, 50);
|
|
535
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
zremrangebyscore(key: string, min: number, max: number): Promise<TxClientLike>;
|
|
540
|
+
/**
|
|
541
|
+
* Sets the specified fields to their respective values in the hash stored at key.
|
|
542
|
+
* https://redis.io/commands/hset
|
|
543
|
+
* @arg {} key
|
|
544
|
+
* @arg {} fieldValues
|
|
545
|
+
* @returns number of fields that were added
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* async function hSetExample(context: Devvit.Context) {
|
|
549
|
+
* const numFieldsAdded = await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
550
|
+
* console.log("Number of fields added: " + numFieldsAdded);
|
|
551
|
+
* }
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
hset(key: string, fieldValues: {
|
|
555
|
+
[field: string]: string;
|
|
556
|
+
}): Promise<TxClientLike>;
|
|
557
|
+
/**
|
|
558
|
+
* Returns the value associated with field in the hash stored at key.
|
|
559
|
+
* https://redis.io/commands/hget
|
|
560
|
+
* @arg {} key
|
|
561
|
+
* @arg {} field
|
|
562
|
+
* @returns value associated with field
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* async function hGetExample(context: Devvit.Context) {
|
|
566
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
567
|
+
* const result : string | undefined = await context.redis.hget("fruits", "orange");
|
|
568
|
+
* console.log("Value of orange: " + result);
|
|
569
|
+
* }
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
hget(key: string, field: string): Promise<TxClientLike>;
|
|
573
|
+
/**
|
|
574
|
+
* Returns the values associated with fields in the hash stored at key.
|
|
575
|
+
* https://redis.io/commands/hmget
|
|
576
|
+
* @arg {} key
|
|
577
|
+
* @arg {} fields
|
|
578
|
+
* @returns values associated with each field in the order they appear in fields
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* async function hMGetExample(context: Devvit.Context) {
|
|
582
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
583
|
+
* const result : string[] | undefined = await context.redis.hmget("fruits", ["orange", "grape", "apple"]);
|
|
584
|
+
* console.log("Value of fields: " + result); // "Value of fields: ["7", undefined, "5"]
|
|
585
|
+
* }
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
hmget(key: string, fields: string[]): Promise<TxClientLike>;
|
|
589
|
+
/**
|
|
590
|
+
* Returns all fields and values of the hash stored at key
|
|
591
|
+
* https://redis.io/commands/hgetall
|
|
592
|
+
* @arg {} key
|
|
593
|
+
* @returns a map of fields and their values stored in the hash,
|
|
594
|
+
* @example
|
|
595
|
+
* ```
|
|
596
|
+
* async function hGetAllExample(context: Devvit.Context) {
|
|
597
|
+
* await context.redis.hset("groceryList", {
|
|
598
|
+
* "eggs": "12",
|
|
599
|
+
* "apples": "3",
|
|
600
|
+
* "milk": "1"
|
|
601
|
+
* });
|
|
602
|
+
*
|
|
603
|
+
* const record : Record<string, string> | undefined = await context.redis.hgetall("groceryList");
|
|
604
|
+
*
|
|
605
|
+
* if (record != undefined) {
|
|
606
|
+
* console.log("Eggs: " + record.eggs + ", Apples: " + record.apples + ", Milk: " + record.milk);
|
|
607
|
+
* }
|
|
608
|
+
* }
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
hgetall(key: string): Promise<TxClientLike>;
|
|
612
|
+
/**
|
|
613
|
+
* Removes the specified fields from the hash stored at key.
|
|
614
|
+
* https://redis.io/commands/hdel/
|
|
615
|
+
* @arg {} key
|
|
616
|
+
* @arg {} fields
|
|
617
|
+
* @returns number of fields that were removed from the hash
|
|
618
|
+
* ```ts
|
|
619
|
+
* async function hDelExample(context: Devvit.Context) {
|
|
620
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
621
|
+
* const numFieldsRemoved = await context.redis.hdel("fruits", ["apple", "kiwi"]);
|
|
622
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
hdel(key: string, fields: string[]): Promise<TxClientLike>;
|
|
627
|
+
/**
|
|
628
|
+
* Iterates fields of Hash types and their associated values.
|
|
629
|
+
* @arg {} key
|
|
630
|
+
* @arg {} cursor
|
|
631
|
+
* @arg {} pattern
|
|
632
|
+
* @arg {} count
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* async function hScanExample(context: Devvit.Context) {
|
|
636
|
+
* await context.redis.hset("userInfo", {
|
|
637
|
+
* "name": "Bob",
|
|
638
|
+
* "startDate": "01-05-20",
|
|
639
|
+
* "totalAwards": "12"
|
|
640
|
+
* });
|
|
641
|
+
*
|
|
642
|
+
* const hScanResponse = await context.redis.hscan("userInfo", 0);
|
|
643
|
+
*
|
|
644
|
+
* hScanResponse.fieldValues.forEach(x => {
|
|
645
|
+
* console.log("Field: '" + x.field + "', Value: '" + x.value + "'");
|
|
646
|
+
* });
|
|
647
|
+
* }
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
hscan(key: string, cursor: number, pattern?: string | undefined, count?: number | undefined): Promise<TxClientLike>;
|
|
651
|
+
/**
|
|
652
|
+
* Returns all field names in the hash stored at key.
|
|
653
|
+
* @arg {} key
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* async function hKeysExample(context: Devvit.Context) {
|
|
657
|
+
* await context.redis.hset("prices", {
|
|
658
|
+
* "chair": "48",
|
|
659
|
+
* "desk": "95",
|
|
660
|
+
* "whiteboard": "23"
|
|
661
|
+
* });
|
|
662
|
+
* const keys : string[] = await context.redis.hkeys("prices");
|
|
663
|
+
* console.log("Keys: " + keys);
|
|
664
|
+
* }
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
hkeys(key: string): Promise<TxClientLike>;
|
|
668
|
+
/**
|
|
669
|
+
* Increments the number stored at field in the hash stored at key by increment.
|
|
670
|
+
* https://redis.io/commands/hincrby/
|
|
671
|
+
* @arg {} key
|
|
672
|
+
* @arg {} field
|
|
673
|
+
* @arg {} value
|
|
674
|
+
* @returns value of key after the increment
|
|
675
|
+
* @example
|
|
676
|
+
* ```ts
|
|
677
|
+
* async function hIncrByExample(context: Devvit.Context) {
|
|
678
|
+
* await context.redis.hset("user123", { "karma": "100" });
|
|
679
|
+
* await context.redis.hincrby("user123", "karma", 5);
|
|
680
|
+
* }
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
hincrby(key: string, field: string, value: number): Promise<TxClientLike>;
|
|
684
|
+
/**
|
|
685
|
+
* Returns the number of fields contained in the hash stored at key.
|
|
686
|
+
* @arg {} key
|
|
687
|
+
* @returns the number of fields in the hash, or 0 when the key does not exist.
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* async function hLenExample(context: Devvit.Context) {
|
|
691
|
+
* await context.redis.hset("supplies", {
|
|
692
|
+
* "paperclips": "25",
|
|
693
|
+
* "pencils": "10",
|
|
694
|
+
* "erasers": "5",
|
|
695
|
+
* "pens": "7"
|
|
696
|
+
* });
|
|
697
|
+
* const numberOfFields : number = await context.redis.hlen("supplies");
|
|
698
|
+
* console.log("Number of fields: " + numberOfFields);
|
|
699
|
+
* }
|
|
700
|
+
* ```
|
|
701
|
+
*/
|
|
702
|
+
hlen(key: string): Promise<TxClientLike>;
|
|
703
|
+
};
|
|
704
|
+
export type RedisClient = {
|
|
705
|
+
/**
|
|
706
|
+
* Marks the given keys to be watched for conditional execution of a transaction.
|
|
707
|
+
* https://redis.io/commands/watch/
|
|
708
|
+
* @arg {} keys - given keys to be watched
|
|
709
|
+
* @example
|
|
710
|
+
* ```ts
|
|
711
|
+
* async function watchExample(context: Devvit.Context) {
|
|
712
|
+
* await context.redis.set("karma", "32");
|
|
713
|
+
*
|
|
714
|
+
* const txn = await context.redis.watch("quantity");
|
|
715
|
+
*
|
|
716
|
+
* await txn.multi(); // Begin a transaction
|
|
717
|
+
* await txn.incrBy("karma", 10);
|
|
718
|
+
* await txn.exec(); // Execute the commands in the transaction
|
|
719
|
+
* }
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
watch(...keys: string[]): Promise<TxClientLike>;
|
|
723
|
+
/**
|
|
724
|
+
* Get the value of key. If the key does not exist the special value nil is returned.
|
|
725
|
+
* An exception will be raised if the value of key is not a valid utf-8 encoding.
|
|
726
|
+
* https://redis.io/commands/get/
|
|
727
|
+
* @arg {} key
|
|
728
|
+
* @returns value of key or null when key does not exist.
|
|
729
|
+
* @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* async function getExample(context: Devvit.Context) {
|
|
732
|
+
* await context.redis.set("quantity", "5");
|
|
733
|
+
* const quantity : string | undefined = await context.redis.get("quantity");
|
|
734
|
+
* console.log("Quantity: " + quantity);
|
|
735
|
+
* }
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
get(key: string): Promise<string | undefined>;
|
|
739
|
+
/**
|
|
740
|
+
* Get the value of key and return it as a buffer.
|
|
741
|
+
* Use getBytes instead of get if you need to tolerate values that are not valid utf-8.
|
|
742
|
+
* If the key does not exist the special value nil is returned.
|
|
743
|
+
* https://redis.io/commands/get/
|
|
744
|
+
* @arg {} key
|
|
745
|
+
* @returns value of key or null when key does not exist.
|
|
746
|
+
* @example
|
|
747
|
+
* ```ts
|
|
748
|
+
* async function getExample(context: Devvit.Context) {
|
|
749
|
+
* await context.redis.bitfield("nonutf8", "set", "u8", "0", "192");
|
|
750
|
+
* const buf : string | undefined = await context.redis.getbuffer("nonutf8");
|
|
751
|
+
* console.log("Bytes: " + JSON.stringify(buf));
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
getbuffer(key: string): Promise<Buffer | undefined>;
|
|
756
|
+
/**
|
|
757
|
+
* Set key to hold the string value. If key already holds a value, it is overwritten
|
|
758
|
+
* https://redis.io/commands/set/
|
|
759
|
+
* @arg {} key
|
|
760
|
+
* @arg {} value
|
|
761
|
+
* @arg {} options
|
|
762
|
+
* @example
|
|
763
|
+
* ```ts
|
|
764
|
+
* async function setExample(context: Devvit.Context) {
|
|
765
|
+
* await context.redis.set("quantity", "5");
|
|
766
|
+
* }
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
set(key: string, value: string, options?: SetOptions): Promise<string>;
|
|
770
|
+
/**
|
|
771
|
+
* Returns number of given keys that exists
|
|
772
|
+
* https://redis.io/commands/exists/
|
|
773
|
+
* @arg {} keys Keys to check for existence
|
|
774
|
+
* @returns number of keys in the list of keys that exist (note: double counts if an existing key is passed twice)
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* async function existsExample(context: Devvit.Context) {
|
|
778
|
+
* const exists : number = await context.redis.exists("someKey");
|
|
779
|
+
* console.log("Exists: " + exists); // 0
|
|
780
|
+
*
|
|
781
|
+
* await context.redis.set("someKey", "someValue");
|
|
782
|
+
* const exists2 : number = await context.redis.exists("someKey", "someOtherKey");
|
|
783
|
+
* console.log("Exists2: " + exists2); // 1
|
|
784
|
+
*
|
|
785
|
+
* await context.redis.set("someOtherKey", "someOtherValue");
|
|
786
|
+
* const exists3 : number = await context.redis.exists("someKey", "someKey", "someOtherKey");
|
|
787
|
+
* console.log("Exists3: " + exists3); // 3, since "someKey" is counted twice
|
|
788
|
+
* }
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
exists(...keys: string[]): Promise<number>;
|
|
792
|
+
/**
|
|
793
|
+
* Removes the specified keys. A key is ignored if it does not exist.
|
|
794
|
+
* https://redis.io/commands/del/
|
|
795
|
+
* @arg {} keys
|
|
796
|
+
* @example
|
|
797
|
+
* ```ts
|
|
798
|
+
* async function delExample(context: Devvit.Context) {
|
|
799
|
+
* await context.redis.set("quantity", "5");
|
|
800
|
+
* await context.redis.del("quantity");
|
|
801
|
+
* }
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
del(...keys: string[]): Promise<void>;
|
|
805
|
+
/**
|
|
806
|
+
* Returns the string representation of the type of the value stored at key
|
|
807
|
+
* https://redis.io/commands/type/
|
|
808
|
+
* @arg {} key
|
|
809
|
+
* @returns string representation of the type
|
|
810
|
+
* @example
|
|
811
|
+
* ```ts
|
|
812
|
+
* async function typeExample(context: Devvit.Context) {
|
|
813
|
+
* await context.redis.set("quantity", "5");
|
|
814
|
+
* const type : string = await context.redis.type("quantity");
|
|
815
|
+
* console.log("Key type: " + type);
|
|
816
|
+
* }
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
type(key: string): Promise<string>;
|
|
820
|
+
/**
|
|
821
|
+
* Renames key to newKey. It returns an error when key does not exist.
|
|
822
|
+
* https://redis.io/commands/rename/
|
|
823
|
+
* @arg {} key key to be renamed
|
|
824
|
+
* @arg {} newKey new key name
|
|
825
|
+
* @returns string returns "OK" if the key was renamed successfully
|
|
826
|
+
* @example
|
|
827
|
+
* ```ts
|
|
828
|
+
* async function renameExample(context: Devvit.Context) {
|
|
829
|
+
* await context.redis.set("quantity", "5");
|
|
830
|
+
* await context.redis.rename("quantity", "amount");
|
|
831
|
+
* const value : string = await context.redis.get("amount");
|
|
832
|
+
* console.log("Value: " + value);
|
|
833
|
+
* }
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
rename(key: string, newKey: string): Promise<string>;
|
|
837
|
+
/**
|
|
838
|
+
* Returns the substring of the string value stored at key, determined by
|
|
839
|
+
* the offsets start and end (both are inclusive).
|
|
840
|
+
* https://redis.io/commands/getrange/
|
|
841
|
+
* @arg {} key
|
|
842
|
+
* @arg {} start
|
|
843
|
+
* @arg {} end
|
|
844
|
+
* @returns substring determined by offsets [start, end]
|
|
845
|
+
* @example
|
|
846
|
+
* ```ts
|
|
847
|
+
* async function getRangeExample(context: Devvit.Context) {
|
|
848
|
+
* await context.redis.set("word", "tacocat");
|
|
849
|
+
* const range : string = await context.redis.getrange("word", 0, 3)
|
|
850
|
+
* console.log("Range from index 0 to 3: " + range);
|
|
851
|
+
* }
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
getrange(key: string, start: number, end: number): Promise<string>;
|
|
855
|
+
/**
|
|
856
|
+
* Overwrites part of the string stored at key, starting at the
|
|
857
|
+
* specified offset, for the entire length of value.
|
|
858
|
+
* https://redis.io/commands/setrange/
|
|
859
|
+
* @arg {} key
|
|
860
|
+
* @arg {} offset
|
|
861
|
+
* @arg {} value
|
|
862
|
+
* @returns length of the string after it was modified by the command
|
|
863
|
+
* @example
|
|
864
|
+
* ```ts
|
|
865
|
+
* async function setRangeExample(context: Devvit.Context) {
|
|
866
|
+
* await context.redis.set("word", "tacocat");
|
|
867
|
+
* await context.redis.setrange("word", 0, "blue");
|
|
868
|
+
* }
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
setrange(key: string, offset: number, value: string): Promise<number>;
|
|
872
|
+
/**
|
|
873
|
+
* Returns the length of the string value stored at key.
|
|
874
|
+
* An error is returned when key holds a non-string value.
|
|
875
|
+
* https://redis.io/commands/strlen/
|
|
876
|
+
* @arg {} key
|
|
877
|
+
* @returns length of the string stored at key
|
|
878
|
+
* @example
|
|
879
|
+
* ```ts
|
|
880
|
+
* async function strLenExample(context: Devvit.Context) {
|
|
881
|
+
* await context.redis.set("word", "tacocat");
|
|
882
|
+
* const length : number = await context.redis.strlen("word");
|
|
883
|
+
* console.log("Length of word: " + length);
|
|
884
|
+
* }
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
strlen(key: string): Promise<number>;
|
|
888
|
+
/**
|
|
889
|
+
* Increments the number stored at key by increment.
|
|
890
|
+
* https://redis.io/commands/incrby/
|
|
891
|
+
* @arg {} key
|
|
892
|
+
* @arg {} value
|
|
893
|
+
* @returns value of key after the increment
|
|
894
|
+
* @example
|
|
895
|
+
* ```ts
|
|
896
|
+
* async function incrByExample(context: Devvit.Context) {
|
|
897
|
+
* await context.redis.set("totalPoints", "53")
|
|
898
|
+
* const updatedPoints : number = await context.redis.incrby("totalPoints", 100);
|
|
899
|
+
* console.log("Updated points: " + updatedPoints);
|
|
900
|
+
* }
|
|
901
|
+
* ```
|
|
902
|
+
*/
|
|
903
|
+
incrby(key: string, value: number): Promise<number>;
|
|
904
|
+
/**
|
|
905
|
+
* Returns the values of all specified keys.
|
|
906
|
+
* https://redis.io/commands/mget/
|
|
907
|
+
* @arg {} keys
|
|
908
|
+
* @returns list of values at the specified keys
|
|
909
|
+
* @example
|
|
910
|
+
* ```ts
|
|
911
|
+
* async function mGetExample(context: Devvit.Context) {
|
|
912
|
+
* await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
|
|
913
|
+
* const result : (string | null)[] = await context.redis.mget(["name", "occupation"]);
|
|
914
|
+
* result.forEach(x => {
|
|
915
|
+
* console.log(x);
|
|
916
|
+
* });
|
|
917
|
+
* }
|
|
918
|
+
* ```
|
|
919
|
+
*/
|
|
920
|
+
mget(keys: string[]): Promise<(string | null)[]>;
|
|
921
|
+
/**
|
|
922
|
+
* Sets the given keys to their respective values.
|
|
923
|
+
* https://redis.io/commands/mset/
|
|
924
|
+
* @arg {} keyValues
|
|
925
|
+
* @example
|
|
926
|
+
* ```ts
|
|
927
|
+
* async function mSetExample(context: Devvit.Context) {
|
|
928
|
+
* await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
|
|
929
|
+
* }
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
mset(keyValues: {
|
|
933
|
+
[key: string]: string;
|
|
934
|
+
}): Promise<void>;
|
|
935
|
+
/**
|
|
936
|
+
* Set a timeout on key.
|
|
937
|
+
* https://redis.io/commands/expire/
|
|
938
|
+
* @arg {} key
|
|
939
|
+
* @arg {} seconds
|
|
940
|
+
* @example
|
|
941
|
+
* ```ts
|
|
942
|
+
* async function expireExample(context: Devvit.Context) {
|
|
943
|
+
* await context.redis.set("product", "milk");
|
|
944
|
+
* await context.redis.expire("product", 60); // Set the product to expire in 60 seconds
|
|
945
|
+
* }
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
expire(key: string, seconds: number): Promise<void>;
|
|
949
|
+
/**
|
|
950
|
+
* Returns the absolute Unix timestamp in seconds at which the given key will expire
|
|
951
|
+
* https://redis.io/commands/expiretime/
|
|
952
|
+
* @arg {} key
|
|
953
|
+
* @returns expiration Unix timestamp in seconds, or a negative value in order to signal an error
|
|
954
|
+
* @example
|
|
955
|
+
* async function expireTimeExample(context: Devvit.Context) {
|
|
956
|
+
* await context.redis.set("product", "milk");
|
|
957
|
+
* const expireTime : number = await context.redis.expiretime("product");
|
|
958
|
+
* console.log("Expire time: " + expireTime);
|
|
959
|
+
* }
|
|
960
|
+
*/
|
|
961
|
+
expiretime(key: string): Promise<number>;
|
|
962
|
+
/**
|
|
963
|
+
* Adds all the specified members with the specified scores to the sorted set stored at key.
|
|
964
|
+
* https://redis.io/commands/zadd/
|
|
965
|
+
* @arg {} key
|
|
966
|
+
* @arg {} members
|
|
967
|
+
* @returns number of elements added to the sorted set
|
|
968
|
+
* @example
|
|
969
|
+
* ```ts
|
|
970
|
+
* async function zAddExample(context: Devvit.Context) {
|
|
971
|
+
* const numMembersAdded : number = await context.redis.zadd("leaderboard",
|
|
972
|
+
* {member: "louis", score: 37},
|
|
973
|
+
* {member: "fernando", score: 10},
|
|
974
|
+
* {member: "caesar", score: 20},
|
|
975
|
+
* {member: "alexander", score: 25},
|
|
976
|
+
* );
|
|
977
|
+
* console.log("Number of members added: " + numMembersAdded);
|
|
978
|
+
* }
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
zadd(key: string, ...members: ZMember[]): Promise<number>;
|
|
982
|
+
/**
|
|
983
|
+
* Returns the cardinality (number of elements) of the sorted set stored at key.
|
|
984
|
+
* https://redis.io/commands/zcard/
|
|
985
|
+
* @arg {} key
|
|
986
|
+
* @returns cardinality of the sorted set
|
|
987
|
+
* @example
|
|
988
|
+
* ```ts
|
|
989
|
+
* async function zCardExample(context: Devvit.Context) {
|
|
990
|
+
* await context.redis.zadd("leaderboard",
|
|
991
|
+
* {member: "louis", score: 37},
|
|
992
|
+
* {member: "fernando", score: 10},
|
|
993
|
+
* {member: "caesar", score: 20},
|
|
994
|
+
* {member: "alexander", score: 25},
|
|
995
|
+
* );
|
|
996
|
+
* const cardinality : number = await context.redis.zcard("leaderboard");
|
|
997
|
+
* console.log("Cardinality: " + cardinality);
|
|
998
|
+
* }
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
zcard(key: string): Promise<number>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Returns the score of member in the sorted set at key.
|
|
1004
|
+
* https://redis.io/commands/zscore/
|
|
1005
|
+
* @arg {} key
|
|
1006
|
+
* @arg {} member
|
|
1007
|
+
* @returns the score of the member (a double-precision floating point number).
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* async function zScoreExample(context: Devvit.Context) {
|
|
1011
|
+
* await context.redis.zadd("leaderboard",
|
|
1012
|
+
* {member: "louis", score: 37},
|
|
1013
|
+
* {member: "fernando", score: 10},
|
|
1014
|
+
* {member: "caesar", score: 20},
|
|
1015
|
+
* {member: "alexander", score: 25},
|
|
1016
|
+
* );
|
|
1017
|
+
* const score : number = await context.redis.zscore("leaderboard", "caesar");
|
|
1018
|
+
* console.log("Caesar's score: " + score);
|
|
1019
|
+
* }
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
zscore(key: string, member: string): Promise<number | undefined>;
|
|
1023
|
+
/**
|
|
1024
|
+
* Returns the rank of member in the sorted set stored at key
|
|
1025
|
+
* https://redis.io/commands/zrank/
|
|
1026
|
+
* @arg {} key
|
|
1027
|
+
* @arg {} member
|
|
1028
|
+
* @returns rank of the member if opts is undefined or opts.withScore = false,
|
|
1029
|
+
* or returns { rank, score } of the member if opts.withScore = true. The rank (or index)
|
|
1030
|
+
* is 0-based which means that the member with the lowest score has rank 0
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* async function zRankExample(context: Devvit.Context) {
|
|
1034
|
+
* await context.redis.zadd("animals",
|
|
1035
|
+
* {member: "zebra", score: 92},
|
|
1036
|
+
* {member: "cat", score: 100},
|
|
1037
|
+
* {member: "dog", score: 95},
|
|
1038
|
+
* {member: "elephant", score: 97}
|
|
1039
|
+
* );
|
|
1040
|
+
* const rank : number | undefined = await context.redis.zrank("animals", "dog");
|
|
1041
|
+
* if(rank !== undefined) {
|
|
1042
|
+
* console.log("Dog's rank: " + rank);
|
|
1043
|
+
* }
|
|
1044
|
+
* }
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
zrank(key: string, member: string): Promise<number | undefined>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Increments the score of member in the sorted set stored at key by value
|
|
1050
|
+
* https://redis.io/commands/zincrby/
|
|
1051
|
+
* @arg {} key
|
|
1052
|
+
* @arg {} member
|
|
1053
|
+
* @arg {} value
|
|
1054
|
+
* @returns the new score of member as a double precision floating point number
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* async function zIncrByExample(context: Devvit.Context) {
|
|
1058
|
+
* await context.redis.zadd("animals",
|
|
1059
|
+
* {member: "zebra", score: 92},
|
|
1060
|
+
* {member: "cat", score: 100},
|
|
1061
|
+
* {member: "dog", score: 95},
|
|
1062
|
+
* {member: "elephant", score: 97}
|
|
1063
|
+
* );
|
|
1064
|
+
* const updatedScore : number = await context.redis.zincrby("animals", "dog", 10);
|
|
1065
|
+
* console.log("Dog's updated score: " + updatedScore);
|
|
1066
|
+
* }
|
|
1067
|
+
* ```
|
|
1068
|
+
*/
|
|
1069
|
+
zincrby(key: string, member: string, value: number): Promise<number>;
|
|
1070
|
+
/**
|
|
1071
|
+
* Returns the specified range of elements in the sorted set stored at key.
|
|
1072
|
+
* https://redis.io/commands/zrange/
|
|
1073
|
+
*
|
|
1074
|
+
* When using `by: 'lex'`, the start and stop inputs will be prepended with `[` by default, unless they already begin with `[`, `(` or are one of the special values `+` or `-`.
|
|
1075
|
+
* @arg {} key
|
|
1076
|
+
* @arg {} start
|
|
1077
|
+
* @arg {} stop
|
|
1078
|
+
* @arg {} options
|
|
1079
|
+
* @returns list of elements in the specified range
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```ts
|
|
1082
|
+
* async function zRangeExample(context: Devvit.Context) {
|
|
1083
|
+
* await context.redis.zadd("leaderboard",
|
|
1084
|
+
* {member: "louis", score: 37},
|
|
1085
|
+
* {member: "fernando", score: 10},
|
|
1086
|
+
* {member: "caesar", score: 20},
|
|
1087
|
+
* {member: "alexander", score: 25},
|
|
1088
|
+
* );
|
|
1089
|
+
*
|
|
1090
|
+
* // View elements with scores between 0 and 30 inclusive, sorted by score
|
|
1091
|
+
* const scores : {member : string, score : number}[] = await context.redis.zrange("leaderboard", 0, 30, { by: "score" });
|
|
1092
|
+
*
|
|
1093
|
+
* scores.forEach(x => {
|
|
1094
|
+
* console.log("Member: " + x.member, ", Score: " + x.score);
|
|
1095
|
+
* });
|
|
1096
|
+
* }
|
|
1097
|
+
* ```
|
|
1098
|
+
*/
|
|
1099
|
+
zrange(key: string, start: number | string, stop: number | string, options?: ZRangeOptions): Promise<{
|
|
1100
|
+
member: string;
|
|
1101
|
+
score: number;
|
|
1102
|
+
}[]>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Removes the specified members from the sorted set stored at key.
|
|
1105
|
+
* https://redis.io/commands/zrem/
|
|
1106
|
+
* @arg {} key
|
|
1107
|
+
* @arg {} members
|
|
1108
|
+
* @returns number of members removed from the sorted set
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```ts
|
|
1111
|
+
* async function zRemExample(context: Devvit.Context) {
|
|
1112
|
+
* await context.redis.zadd("leaderboard",
|
|
1113
|
+
* {member: "louis", score: 37},
|
|
1114
|
+
* {member: "fernando", score: 10},
|
|
1115
|
+
* {member: "caesar", score: 20},
|
|
1116
|
+
* {member: "alexander", score: 25},
|
|
1117
|
+
* );
|
|
1118
|
+
* const numberOfMembersRemoved : number = await context.redis.zrem("leaderboard", ["fernando", "alexander"]);
|
|
1119
|
+
* console.log("Number of members removed: " + numberOfMembersRemoved);
|
|
1120
|
+
* }
|
|
1121
|
+
* ```
|
|
1122
|
+
*/
|
|
1123
|
+
zrem(key: string, members: string[]): Promise<number>;
|
|
1124
|
+
/**
|
|
1125
|
+
* removes all elements in the sorted set stored at key between the
|
|
1126
|
+
* lexicographical range specified by min and max
|
|
1127
|
+
* https://redis.io/commands/zremrangebylex/
|
|
1128
|
+
* @arg {} key
|
|
1129
|
+
* @arg {} min
|
|
1130
|
+
* @arg {} max
|
|
1131
|
+
* @returns number of members removed from the sorted set
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```ts
|
|
1134
|
+
* async function zRemRangeByLexExample(context: Devvit.Context) {
|
|
1135
|
+
* await context.redis.zadd("fruits",
|
|
1136
|
+
* {member: "kiwi", score: 0},
|
|
1137
|
+
* {member: "mango", score: 0},
|
|
1138
|
+
* {member: "banana", score: 0},
|
|
1139
|
+
* {member: "orange", score: 0},
|
|
1140
|
+
* {member: "apple", score: 0},
|
|
1141
|
+
* );
|
|
1142
|
+
*
|
|
1143
|
+
* // Remove fruits alphabetically ordered between 'kiwi' inclusive and 'orange' exclusive
|
|
1144
|
+
* // Note: The symbols '[' and '(' indicate inclusive or exclusive, respectively. These must be included in the call to zRemRangeByLex().
|
|
1145
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebylex("fruits", "[kiwi", "(orange");
|
|
1146
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
1147
|
+
* }
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
zremrangebylex(key: string, min: string, max: string): Promise<number>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Removes all elements in the sorted set stored at key with rank between start and stop.
|
|
1153
|
+
* https://redis.io/commands/zremrangebyrank/
|
|
1154
|
+
* @arg {} key
|
|
1155
|
+
* @arg {} start
|
|
1156
|
+
* @arg {} stop
|
|
1157
|
+
* @returns number of members removed from the sorted set
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```
|
|
1160
|
+
* async function zRemRangeByRankExample(context: Devvit.Context) {
|
|
1161
|
+
* await context.redis.zadd("fruits",
|
|
1162
|
+
* {member: "kiwi", score: 10},
|
|
1163
|
+
* {member: "mango", score: 20},
|
|
1164
|
+
* {member: "banana", score: 30},
|
|
1165
|
+
* {member: "orange", score: 40},
|
|
1166
|
+
* {member: "apple", score: 50},
|
|
1167
|
+
* );
|
|
1168
|
+
|
|
1169
|
+
* // Remove fruits ranked 1 through 3 inclusive
|
|
1170
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebyrank("fruits", 1, 3);
|
|
1171
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
1172
|
+
* }
|
|
1173
|
+
* ```
|
|
1174
|
+
*/
|
|
1175
|
+
zremrangebyrank(key: string, start: number, stop: number): Promise<number>;
|
|
1176
|
+
/**
|
|
1177
|
+
* Removes all elements in the sorted set stored at key with a score between min and max
|
|
1178
|
+
* https://redis.io/commands/zremrangebyscore/
|
|
1179
|
+
* @arg {} key
|
|
1180
|
+
* @arg {} min
|
|
1181
|
+
* @arg {} max
|
|
1182
|
+
* @returns number of members removed from the sorted set
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```ts
|
|
1185
|
+
* async function zRemRangeByScoreExample(context: Devvit.Context) {
|
|
1186
|
+
* await context.redis.zadd("fruits",
|
|
1187
|
+
* {member: "kiwi", score: 10},
|
|
1188
|
+
* {member: "mango", score: 20},
|
|
1189
|
+
* {member: "banana", score: 30},
|
|
1190
|
+
* {member: "orange", score: 40},
|
|
1191
|
+
* {member: "apple", score: 50},
|
|
1192
|
+
* );
|
|
1193
|
+
* // Remove fruits scored between 30 and 50 inclusive
|
|
1194
|
+
* const numFieldsRemoved : number = await context.redis.zremrangebyscore("fruits", 30, 50);
|
|
1195
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
1196
|
+
* }
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
1199
|
+
zremrangebyscore(key: string, min: number, max: number): Promise<number>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Iterates elements of Sorted Set types and their associated scores.
|
|
1202
|
+
* @arg {} key
|
|
1203
|
+
* @arg {} cursor
|
|
1204
|
+
* @arg {} pattern
|
|
1205
|
+
* @arg {} count
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* async function zScanExample(context: Devvit.Context) {
|
|
1209
|
+
* await context.redis.zadd("fruits",
|
|
1210
|
+
* {member: "kiwi", score: 0},
|
|
1211
|
+
* {member: "mango", score: 0},
|
|
1212
|
+
* {member: "banana", score: 0},
|
|
1213
|
+
* {member: "orange", score: 0},
|
|
1214
|
+
* {member: "apple", score: 0},
|
|
1215
|
+
* );
|
|
1216
|
+
* const zScanResponse = await context.redis.zscan("fruits", 0);
|
|
1217
|
+
* console.log("zScanResponse: " + JSON.stringify(zScanResponse));
|
|
1218
|
+
* }
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
zscan(key: string, cursor: number, pattern?: string | undefined, count?: number | undefined): Promise<ZScanResponse>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Sets the specified fields to their respective values in the hash stored at key.
|
|
1224
|
+
* https://redis.io/commands/hset
|
|
1225
|
+
* @arg {} key
|
|
1226
|
+
* @arg {} fieldValues
|
|
1227
|
+
* @returns number of fields that were added
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```ts
|
|
1230
|
+
* async function hSetExample(context: Devvit.Context) {
|
|
1231
|
+
* const numFieldsAdded = await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
1232
|
+
* console.log("Number of fields added: " + numFieldsAdded);
|
|
1233
|
+
* }
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
hset(key: string, fieldValues: {
|
|
1237
|
+
[field: string]: string;
|
|
1238
|
+
}): Promise<number>;
|
|
1239
|
+
/**
|
|
1240
|
+
* Sets field in the hash stored at key to value, only if field does not yet exist.
|
|
1241
|
+
* https://redis.io/commands/hsetnx/
|
|
1242
|
+
* @returns 1 if field is a new field in the hash and value was set, 0 if field already exists in the hash and no operation was performed.
|
|
1243
|
+
* @example
|
|
1244
|
+
* ```ts
|
|
1245
|
+
* async function hSetNXExample(context: Devvit.Context) {
|
|
1246
|
+
* const result : number = await context.redis.hsetnx("myhash", "field1", "value1");
|
|
1247
|
+
* console.log("HSETNX result: " + result);
|
|
1248
|
+
* }
|
|
1249
|
+
* ```
|
|
1250
|
+
*/
|
|
1251
|
+
hsetnx(key: string, field: string, value: string): Promise<number>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Returns the value associated with field in the hash stored at key.
|
|
1254
|
+
* https://redis.io/commands/hget
|
|
1255
|
+
* @arg {} key
|
|
1256
|
+
* @arg {} field
|
|
1257
|
+
* @returns value associated with field
|
|
1258
|
+
* @example
|
|
1259
|
+
* ```ts
|
|
1260
|
+
* async function hGetExample(context: Devvit.Context) {
|
|
1261
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
1262
|
+
* const result : string | undefined = await context.redis.hget("fruits", "orange");
|
|
1263
|
+
* console.log("Value of orange: " + result);
|
|
1264
|
+
* }
|
|
1265
|
+
* ```
|
|
1266
|
+
*/
|
|
1267
|
+
hget(key: string, field: string): Promise<string | undefined>;
|
|
1268
|
+
/**
|
|
1269
|
+
* Returns the values associated with fields in the hash stored at key.
|
|
1270
|
+
* https://redis.io/commands/hmget
|
|
1271
|
+
* @arg {} key
|
|
1272
|
+
* @arg {} fields
|
|
1273
|
+
* @returns values associated with each field in the order they appear in fields
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```ts
|
|
1276
|
+
* async function hMGetExample(context: Devvit.Context) {
|
|
1277
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
1278
|
+
* const result : string[] | undefined = await context.redis.hmget("fruits", ["orange", "grape", "apple"]);
|
|
1279
|
+
* console.log("Value of fields: " + result); // "Value of fields: ["7", undefined, "5"]
|
|
1280
|
+
* }
|
|
1281
|
+
* ```
|
|
1282
|
+
*/
|
|
1283
|
+
hmget(key: string, fields: string[]): Promise<(string | null)[]>;
|
|
1284
|
+
/**
|
|
1285
|
+
* Returns all fields and values of the hash stored at key
|
|
1286
|
+
* https://redis.io/commands/hgetall
|
|
1287
|
+
* @arg {} key
|
|
1288
|
+
* @returns a map of fields and their values stored in the hash,
|
|
1289
|
+
* @example
|
|
1290
|
+
* ```
|
|
1291
|
+
* async function hGetAllExample(context: Devvit.Context) {
|
|
1292
|
+
* await context.redis.hset("groceryList", {
|
|
1293
|
+
* "eggs": "12",
|
|
1294
|
+
* "apples": "3",
|
|
1295
|
+
* "milk": "1"
|
|
1296
|
+
* });
|
|
1297
|
+
*
|
|
1298
|
+
* const record : Record<string, string> = await context.redis.hgetall("groceryList");
|
|
1299
|
+
*
|
|
1300
|
+
* if (record.eggs !== undefined) {
|
|
1301
|
+
* console.log(`Eggs: ${record.eggs}`);
|
|
1302
|
+
* }
|
|
1303
|
+
* }
|
|
1304
|
+
* ```
|
|
1305
|
+
*/
|
|
1306
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
1307
|
+
/**
|
|
1308
|
+
* Removes the specified fields from the hash stored at key.
|
|
1309
|
+
* https://redis.io/commands/hdel/
|
|
1310
|
+
* @arg {} key
|
|
1311
|
+
* @arg {} fields
|
|
1312
|
+
* @returns number of fields that were removed from the hash
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* async function hDelExample(context: Devvit.Context) {
|
|
1316
|
+
* await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
|
|
1317
|
+
* const numFieldsRemoved = await context.redis.hdel("fruits", ["apple", "kiwi"]);
|
|
1318
|
+
* console.log("Number of fields removed: " + numFieldsRemoved);
|
|
1319
|
+
* }
|
|
1320
|
+
* ```
|
|
1321
|
+
*/
|
|
1322
|
+
hdel(key: string, fields: string[]): Promise<number>;
|
|
1323
|
+
/**
|
|
1324
|
+
* Iterates fields of Hash types and their associated values.
|
|
1325
|
+
* @arg {} key
|
|
1326
|
+
* @arg {} cursor
|
|
1327
|
+
* @arg {} pattern
|
|
1328
|
+
* @arg {} count
|
|
1329
|
+
* @example
|
|
1330
|
+
* ```ts
|
|
1331
|
+
* async function hScanExample(context: Devvit.Context) {
|
|
1332
|
+
* await context.redis.hset("userInfo", {
|
|
1333
|
+
* "name": "Bob",
|
|
1334
|
+
* "startDate": "01-05-20",
|
|
1335
|
+
* "totalAwards": "12"
|
|
1336
|
+
* });
|
|
1337
|
+
*
|
|
1338
|
+
* const hScanResponse = await context.redis.hscan("userInfo", 0);
|
|
1339
|
+
*
|
|
1340
|
+
* hScanResponse.fieldValues.forEach(x => {
|
|
1341
|
+
* console.log("Field: '" + x.field + "', Value: '" + x.value + "'");
|
|
1342
|
+
* });
|
|
1343
|
+
* }
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
hscan(key: string, cursor: number, pattern?: string | undefined, count?: number | undefined): Promise<HScanResponse>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Returns all field names in the hash stored at key.
|
|
1349
|
+
* @arg {} key
|
|
1350
|
+
* @example
|
|
1351
|
+
* ```ts
|
|
1352
|
+
* async function hKeysExample(context: Devvit.Context) {
|
|
1353
|
+
* await context.redis.hset("prices", {
|
|
1354
|
+
* "chair": "48",
|
|
1355
|
+
* "desk": "95",
|
|
1356
|
+
* "whiteboard": "23"
|
|
1357
|
+
* });
|
|
1358
|
+
* const keys : string[] = await context.redis.hkeys("prices");
|
|
1359
|
+
* console.log("Keys: " + keys);
|
|
1360
|
+
* }
|
|
1361
|
+
* ```
|
|
1362
|
+
*/
|
|
1363
|
+
hkeys(key: string): Promise<string[]>;
|
|
1364
|
+
/**
|
|
1365
|
+
* Increments the number stored at field in the hash stored at key by increment.
|
|
1366
|
+
* https://redis.io/commands/hincrby/
|
|
1367
|
+
* @arg {} key
|
|
1368
|
+
* @arg {} field
|
|
1369
|
+
* @arg {} value
|
|
1370
|
+
* @returns value of key after the increment
|
|
1371
|
+
* @example
|
|
1372
|
+
* ```ts
|
|
1373
|
+
* async function hIncrByExample(context: Devvit.Context) {
|
|
1374
|
+
* await context.redis.hset("user123", { "karma": "100" });
|
|
1375
|
+
* await context.redis.hincrby("user123", "karma", 5);
|
|
1376
|
+
* }
|
|
1377
|
+
* ```
|
|
1378
|
+
*/
|
|
1379
|
+
hincrby(key: string, field: string, value: number): Promise<number>;
|
|
1380
|
+
/**
|
|
1381
|
+
* Returns the number of fields contained in the hash stored at key.
|
|
1382
|
+
* @arg {} key
|
|
1383
|
+
* @returns the number of fields in the hash, or 0 when the key does not exist.
|
|
1384
|
+
* @example
|
|
1385
|
+
* ```ts
|
|
1386
|
+
* async function hLenExample(context: Devvit.Context) {
|
|
1387
|
+
* await context.redis.hset("supplies", {
|
|
1388
|
+
* "paperclips": "25",
|
|
1389
|
+
* "pencils": "10",
|
|
1390
|
+
* "erasers": "5",
|
|
1391
|
+
* "pens": "7"
|
|
1392
|
+
* });
|
|
1393
|
+
* const numberOfFields : number = await context.redis.hlen("supplies");
|
|
1394
|
+
* console.log("Number of fields: " + numberOfFields);
|
|
1395
|
+
* }
|
|
1396
|
+
* ```
|
|
1397
|
+
*/
|
|
1398
|
+
hlen(key: string): Promise<number>;
|
|
1399
|
+
/**
|
|
1400
|
+
* Performs operations on a redis string treating it as an array of bits.
|
|
1401
|
+
* Operations available:
|
|
1402
|
+
* - get <encoding> <offset> -- Returns the specified bit field.
|
|
1403
|
+
* - set <encoding> <offset> <value> -- Sets the specified bit field and returns its old value.
|
|
1404
|
+
* - incrBy <encoding> <offset> <increment> -- Increments or decrements (if a negative increment is given) the specified bit field and returns the new value.
|
|
1405
|
+
* - overflow [wrap|sat|fail] -- Alters the overflow behavior of subsequent set's and incrBy's until the next overflow command
|
|
1406
|
+
* https://redis.io/docs/latest/commands/bitfield/
|
|
1407
|
+
* @arg {} key the redis key containing the string to operate on
|
|
1408
|
+
* @arg {} cmds the commands to perform on the string
|
|
1409
|
+
* @returns an array with the result of each command, in order
|
|
1410
|
+
* @example
|
|
1411
|
+
* ```ts
|
|
1412
|
+
* async function bitfieldExample(context: Devvit.Context) {
|
|
1413
|
+
* const fooResults : number[] =
|
|
1414
|
+
* await context.redis.bitfield('foo', 'incrBy', 'i5', 100, 1, 'get', 'u4', 0);
|
|
1415
|
+
* console.log("fooResults: " + fooResults); // [1, 0]
|
|
1416
|
+
*
|
|
1417
|
+
* const barResults : number[] =
|
|
1418
|
+
* await context.redis.bitfield('bar',
|
|
1419
|
+
* 'set', 'u2', 0, 3,
|
|
1420
|
+
* 'get', 'u2', 0,
|
|
1421
|
+
* 'incrBy', 'u2', 0, 1,
|
|
1422
|
+
* 'overflow', 'sat',
|
|
1423
|
+
* 'get', 'u2', 0,
|
|
1424
|
+
* 'set', 'u2', 0, 3,
|
|
1425
|
+
* 'incrBy', 'u2', 0, 1);
|
|
1426
|
+
* console.log("barResults: " + barResults); // [0, 3, 0, 0, 3, 3]
|
|
1427
|
+
* }
|
|
1428
|
+
* ```
|
|
1429
|
+
*/
|
|
1430
|
+
bitfield(key: string, ...cmds: [] | BitfieldCommand | [...BitfieldCommand, ...BitfieldCommand] | [...BitfieldCommand, ...BitfieldCommand, ...BitfieldCommand, ...(number | string)[]]): Promise<number[]>;
|
|
1431
|
+
/**
|
|
1432
|
+
* Allows read/write operations to global keys in Redis
|
|
1433
|
+
* Global redis enables apps to persist and access state across subreddit installations
|
|
1434
|
+
*/
|
|
1435
|
+
global: Omit<RedisClient, 'global'>;
|
|
1436
|
+
};
|
|
1437
|
+
export type SetOptions = {
|
|
1438
|
+
/** Only set the key if it does not already exist. */
|
|
1439
|
+
nx?: boolean;
|
|
1440
|
+
/** Only set the key if it already exists. */
|
|
1441
|
+
xx?: boolean;
|
|
1442
|
+
expiration?: Date;
|
|
1443
|
+
};
|
|
1444
|
+
export type ZMember = {
|
|
1445
|
+
score: number;
|
|
1446
|
+
member: string;
|
|
1447
|
+
};
|
|
1448
|
+
export type ZRangeOptions = {
|
|
1449
|
+
/**
|
|
1450
|
+
* Reverses the sorted set, with index 0 as the element with the highest
|
|
1451
|
+
* score.
|
|
1452
|
+
*/
|
|
1453
|
+
reverse?: boolean;
|
|
1454
|
+
by: 'score' | 'lex' | 'rank';
|
|
1455
|
+
limit?: {
|
|
1456
|
+
offset: number;
|
|
1457
|
+
count: number;
|
|
1458
|
+
};
|
|
1459
|
+
};
|
|
1460
|
+
export type ZRangeByScoreOptions = {
|
|
1461
|
+
withScores?: boolean;
|
|
1462
|
+
limit?: {
|
|
1463
|
+
offset: number;
|
|
1464
|
+
count: number;
|
|
1465
|
+
};
|
|
1466
|
+
};
|
|
1467
|
+
export type BitfieldCommand = BitfieldGet | BitfieldSet | BitfieldIncrBy | BitfieldOverflow;
|
|
1468
|
+
/**
|
|
1469
|
+
* Represents a 'get' operation in a bitfield command
|
|
1470
|
+
*/
|
|
1471
|
+
type BitfieldGet = [get: 'get', encoding: BitfieldEncoding, offset: BitfieldOffset];
|
|
1472
|
+
/**
|
|
1473
|
+
* Represents a 'set' operation in a bitfield command
|
|
1474
|
+
*/
|
|
1475
|
+
type BitfieldSet = [
|
|
1476
|
+
set: 'set',
|
|
1477
|
+
encoding: BitfieldEncoding,
|
|
1478
|
+
offset: BitfieldOffset,
|
|
1479
|
+
/**
|
|
1480
|
+
* Value to set the bitfield to
|
|
1481
|
+
*/
|
|
1482
|
+
value: number | `${number}`
|
|
1483
|
+
];
|
|
1484
|
+
/**
|
|
1485
|
+
* Represents an 'incrBy' operation in a bitfield command
|
|
1486
|
+
*/
|
|
1487
|
+
type BitfieldIncrBy = [
|
|
1488
|
+
incrBy: 'incrBy',
|
|
1489
|
+
encoding: BitfieldEncoding,
|
|
1490
|
+
offset: BitfieldOffset,
|
|
1491
|
+
/**
|
|
1492
|
+
* Value to increment (or decrement if given a negative increment) the bitfield by
|
|
1493
|
+
*/
|
|
1494
|
+
increment: number | `${number}`
|
|
1495
|
+
];
|
|
1496
|
+
/**
|
|
1497
|
+
* Represents an 'overflow' operation in a bitfield command
|
|
1498
|
+
*/
|
|
1499
|
+
type BitfieldOverflow = [overflow: 'overflow', behavior: 'wrap' | 'sat' | 'fail'];
|
|
1500
|
+
/**
|
|
1501
|
+
* Encoding for operations in a bitfield command
|
|
1502
|
+
* Prefix with 'u' to encode as unsigned integers (e.g. 'u4' is a 4-bit unsigned integer)
|
|
1503
|
+
* Prefix with 'i' to encode as signed integers (e.g. 'i6' is a 6-bit signed integer)
|
|
1504
|
+
* Up to 64 bits for signed integers, and up to 63 bits for unsigned integers
|
|
1505
|
+
*/
|
|
1506
|
+
type BitfieldEncoding = `${'i' | 'u'}${number}`;
|
|
1507
|
+
/**
|
|
1508
|
+
* Offset to operate on for an operation in a bitfield command
|
|
1509
|
+
* If given a number without any prefix, it is used just as a zero based bit offset inside the string
|
|
1510
|
+
* if given a number prefixed with a # character, the specified offset is multiplied by the integer encoding's width
|
|
1511
|
+
*/
|
|
1512
|
+
type BitfieldOffset = number | string | `#${number}`;
|
|
1513
|
+
export {};
|
|
1514
|
+
//# sourceMappingURL=redis.d.ts.map
|