forked from redis/ioredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.ts
39 lines (34 loc) · 767 Bytes
/
scripts.ts
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
import Redis, { Result, Callback } from "ioredis";
const redis = new Redis();
/**
* Define our command
*/
redis.defineCommand("myecho", {
numberOfKeys: 1,
lua: "return KEYS[1] .. ARGV[1]",
});
// Add declarations
declare module "ioredis" {
interface RedisCommander<Context> {
myecho(
key: string,
argv: string,
callback?: Callback<string>
): Result<string, Context>;
}
}
// Works with callbacks
redis.myecho("key", "argv", (err, result) => {
console.log("callback", result);
});
// Works with Promises
(async () => {
console.log("promise", await redis.myecho("key", "argv"));
})();
// Works with pipelining
redis
.pipeline()
.myecho("key", "argv")
.exec((err, result) => {
console.log("pipeline", result);
});