forked from redis/ioredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.test-d.ts
118 lines (96 loc) 路 3.77 KB
/
commands.test-d.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
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
107
108
109
110
111
112
113
114
115
116
117
118
import { expectError, expectType } from "tsd";
import Redis from "../../built";
const redis = new Redis();
// call
expectType<Promise<unknown>>(redis.call("info"));
expectType<Promise<unknown>>(redis.call("set", "foo", "bar"));
expectType<Promise<unknown>>(redis.call("set", ["foo", "bar"]));
expectType<Promise<unknown>>(redis.callBuffer("set", ["foo", "bar"]));
expectType<Promise<unknown>>(
redis.call("set", ["foo", "bar"], (err, value) => {
expectType<Error | undefined | null>(err);
expectType<unknown | undefined>(value);
})
);
expectType<Promise<unknown>>(
redis.call("get", "foo", (err, value) => {
expectType<Error | undefined | null>(err);
expectType<unknown | undefined>(value);
})
);
expectType<Promise<unknown>>(
redis.call("info", (err, value) => {
expectType<Error | undefined | null>(err);
expectType<unknown | undefined>(value);
})
);
// GET
expectType<Promise<string | null>>(redis.get("key"));
expectType<Promise<Buffer | null>>(redis.getBuffer("key"));
expectError(redis.get("key", "bar"));
// SET
expectType<Promise<"OK">>(redis.set("key", "bar"));
expectType<Promise<"OK">>(redis.set("key", "bar", "EX", 100));
expectType<Promise<"OK" | null>>(redis.set("key", "bar", "EX", 100, "NX")); // NX can fail thus `null` is returned
expectType<Promise<string | null>>(redis.set("key", "bar", "GET"));
// DEL
expectType<Promise<number>>(redis.del("key"));
expectType<Promise<number>>(redis.del(["key1", "key2"]));
expectType<Promise<number>>(redis.del("key1", "key2"));
// INCR
expectType<Promise<number>>(redis.incr("key"));
expectType<Promise<number>>(redis.incrby("key", 42));
expectType<Promise<number>>(redis.incrby("key", "42"));
expectType<Promise<string>>(redis.incrbyfloat("key", "42"));
// MGET
expectType<Promise<(string | null)[]>>(redis.mget("key", "bar"));
expectType<Promise<(string | null)[]>>(redis.mget(["key", "bar"]));
// HGETALL
expectType<Promise<Record<string, string>>>(redis.hgetall("key"));
expectType<Promise<Record<string, Buffer>>>(redis.hgetallBuffer("key"));
// LPOP
expectType<Promise<string | null>>(redis.lpop("key"));
expectType<Promise<Buffer | null>>(redis.lpopBuffer("key"));
expectType<Promise<string[] | null>>(redis.lpop("key", 17));
expectType<Promise<Buffer[] | null>>(redis.lpopBuffer("key", 17));
// LPOS
expectType<Promise<number | null>>(redis.lpos("key", "element"));
expectType<Promise<number[]>>(
redis.lpos("key", "element", "RANK", -1, "COUNT", 2)
);
// SRANDMEMBER
expectType<Promise<string | null>>(redis.srandmember("key"));
expectType<Promise<Buffer | null>>(redis.srandmemberBuffer("key"));
expectType<Promise<string[]>>(redis.srandmember("key", 10));
expectType<Promise<Buffer[]>>(redis.srandmemberBuffer("key", 10));
// LMISMEMBER
expectType<Promise<number[]>>(redis.smismember("key", "e1", "e2"));
// ZADD
expectType<Promise<number>>(redis.zadd("key", 1, "member"));
expectType<Promise<number>>(redis.zadd("key", "CH", 1, "member"));
// ZRANDMEMBER
expectType<Promise<string | null>>(redis.zrandmember("key"));
expectType<Promise<string[]>>(redis.zrandmember("key", 20));
// GETRANGE
expectType<Promise<Buffer>>(redis.getrangeBuffer("foo", 0, 1));
// Callbacks
redis.getBuffer("foo", (err, res) => {
expectType<Error | null | undefined>(err);
expectType<Buffer | null | undefined>(res);
});
redis.set("foo", "bar", (err, res) => {
expectType<Error | null | undefined>(err);
expectType<"OK" | undefined>(res);
});
redis.set("foo", "bar", "GET", (err, res) => {
expectType<Error | null | undefined>(err);
expectType<string | null | undefined>(res);
});
redis.del("key1", "key2", (err, res) => {
expectType<Error | null | undefined>(err);
expectType<number | undefined>(res);
});
redis.del(["key1", "key2"], (err, res) => {
expectType<Error | null | undefined>(err);
expectType<number | undefined>(res);
});