@upstash/redis 0.2.1 → 1.0.0-alpha.2
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/.eslintrc.js +49 -0
- package/.prettierrc.js +7 -0
- package/dist/chunk-7YUZYRJS.mjs +29 -0
- package/dist/chunk-FJSI5EBJ.mjs +38 -0
- package/dist/chunk-U7OXAQMQ.mjs +37 -0
- package/dist/chunk-Y5TC4HX2.mjs +798 -0
- package/dist/chunk-ZIB6XPPC.mjs +1061 -0
- package/dist/cloudflare.d.ts +38 -0
- package/dist/cloudflare.js +1738 -0
- package/dist/cloudflare.mjs +35 -0
- package/dist/commands.d.ts +206 -0
- package/dist/commands.js +1201 -0
- package/dist/commands.mjs +219 -0
- package/dist/fastly.d.ts +44 -0
- package/dist/fastly.js +1728 -0
- package/dist/fastly.mjs +25 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.js +84 -0
- package/dist/http.mjs +7 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1744 -0
- package/dist/index.mjs +13 -0
- package/dist/nodejs.d.ts +47 -0
- package/dist/nodejs.js +1742 -0
- package/dist/nodejs.mjs +10 -0
- package/dist/package.json +1 -0
- package/dist/redis-dd052782.d.ts +962 -0
- package/dist/zunionstore-dffa797d.d.ts +670 -0
- package/jest.config.js +194 -4
- package/package.json +1 -75
- package/pkg/cloudflare.ts +77 -0
- package/pkg/command.ts +40 -0
- package/pkg/commands/append.test.ts +28 -0
- package/pkg/commands/append.ts +10 -0
- package/pkg/commands/bitcount.test.ts +36 -0
- package/pkg/commands/bitcount.ts +19 -0
- package/pkg/commands/bitop.test.ts +44 -0
- package/pkg/commands/bitop.ts +22 -0
- package/pkg/commands/bitpos.test.ts +26 -0
- package/pkg/commands/bitpos.ts +10 -0
- package/pkg/commands/dbsize.test.ts +17 -0
- package/pkg/commands/dbsize.ts +10 -0
- package/pkg/commands/decr.test.ts +22 -0
- package/pkg/commands/decr.ts +10 -0
- package/pkg/commands/decrby.test.ts +23 -0
- package/pkg/commands/decrby.ts +10 -0
- package/pkg/commands/del.test.ts +38 -0
- package/pkg/commands/del.ts +11 -0
- package/pkg/commands/echo.test.ts +11 -0
- package/pkg/commands/echo.ts +10 -0
- package/pkg/commands/exists.test.ts +37 -0
- package/pkg/commands/exists.ts +11 -0
- package/pkg/commands/expire.test.ts +22 -0
- package/pkg/commands/expire.ts +10 -0
- package/pkg/commands/expireat.test.ts +24 -0
- package/pkg/commands/expireat.ts +10 -0
- package/pkg/commands/flushall.test.ts +17 -0
- package/pkg/commands/flushall.ts +13 -0
- package/pkg/commands/flushdb.test.ts +17 -0
- package/pkg/commands/flushdb.ts +13 -0
- package/pkg/commands/get.test.ts +34 -0
- package/pkg/commands/get.ts +10 -0
- package/pkg/commands/getbit.test.ts +16 -0
- package/pkg/commands/getbit.ts +10 -0
- package/pkg/commands/getrange.test.ts +25 -0
- package/pkg/commands/getrange.ts +10 -0
- package/pkg/commands/getset.test.ts +33 -0
- package/pkg/commands/getset.ts +10 -0
- package/pkg/commands/hdel.test.ts +30 -0
- package/pkg/commands/hdel.ts +10 -0
- package/pkg/commands/hexists.test.ts +31 -0
- package/pkg/commands/hexists.ts +10 -0
- package/pkg/commands/hget.test.ts +47 -0
- package/pkg/commands/hget.ts +10 -0
- package/pkg/commands/hgetall.test.ts +32 -0
- package/pkg/commands/hgetall.ts +35 -0
- package/pkg/commands/hincrby.test.ts +27 -0
- package/pkg/commands/hincrby.ts +10 -0
- package/pkg/commands/hincrbyfloat.test.ts +25 -0
- package/pkg/commands/hincrbyfloat.ts +10 -0
- package/pkg/commands/hkeys.test.ts +22 -0
- package/pkg/commands/hkeys.ts +10 -0
- package/pkg/commands/hlen.test.ts +24 -0
- package/pkg/commands/hlen.ts +10 -0
- package/pkg/commands/hmget.test.ts +48 -0
- package/pkg/commands/hmget.ts +41 -0
- package/pkg/commands/hmset.test.ts +24 -0
- package/pkg/commands/hmset.ts +10 -0
- package/pkg/commands/hscan.test.ts +46 -0
- package/pkg/commands/hscan.ts +22 -0
- package/pkg/commands/hset.test.ts +21 -0
- package/pkg/commands/hset.ts +10 -0
- package/pkg/commands/hsetnx.test.ts +37 -0
- package/pkg/commands/hsetnx.ts +10 -0
- package/pkg/commands/hstrlen.test.ts +24 -0
- package/pkg/commands/hstrlen.ts +10 -0
- package/pkg/commands/hvals.test.ts +23 -0
- package/pkg/commands/hvals.ts +10 -0
- package/pkg/commands/incr.test.ts +23 -0
- package/pkg/commands/incr.ts +10 -0
- package/pkg/commands/incrby.test.ts +23 -0
- package/pkg/commands/incrby.ts +10 -0
- package/pkg/commands/incrbyfloat.test.ts +24 -0
- package/pkg/commands/incrbyfloat.ts +10 -0
- package/pkg/commands/index.ts +107 -0
- package/pkg/commands/keys.test.ts +17 -0
- package/pkg/commands/keys.ts +10 -0
- package/pkg/commands/lindex.test.ts +33 -0
- package/pkg/commands/lindex.ts +7 -0
- package/pkg/commands/linsert.test.ts +19 -0
- package/pkg/commands/linsert.ts +6 -0
- package/pkg/commands/llen.test.ts +26 -0
- package/pkg/commands/llen.ts +10 -0
- package/pkg/commands/lpop.test.ts +27 -0
- package/pkg/commands/lpop.ts +10 -0
- package/pkg/commands/lpush.test.ts +17 -0
- package/pkg/commands/lpush.ts +11 -0
- package/pkg/commands/lpushx.test.ts +29 -0
- package/pkg/commands/lpushx.ts +11 -0
- package/pkg/commands/lrange.test.ts +22 -0
- package/pkg/commands/lrange.ts +7 -0
- package/pkg/commands/lrem.test.ts +19 -0
- package/pkg/commands/lrem.ts +6 -0
- package/pkg/commands/lset.test.ts +40 -0
- package/pkg/commands/lset.ts +7 -0
- package/pkg/commands/ltrim.test.ts +29 -0
- package/pkg/commands/ltrim.ts +7 -0
- package/pkg/commands/mget.test.ts +44 -0
- package/pkg/commands/mget.ts +9 -0
- package/pkg/commands/mset.test.ts +24 -0
- package/pkg/commands/mset.ts +10 -0
- package/pkg/commands/msetnx.test.ts +46 -0
- package/pkg/commands/msetnx.ts +10 -0
- package/pkg/commands/persist.test.ts +22 -0
- package/pkg/commands/persist.ts +10 -0
- package/pkg/commands/pexpire.test.ts +24 -0
- package/pkg/commands/pexpire.ts +10 -0
- package/pkg/commands/pexpireat.test.ts +24 -0
- package/pkg/commands/pexpireat.ts +10 -0
- package/pkg/commands/ping.test.ts +19 -0
- package/pkg/commands/ping.ts +13 -0
- package/pkg/commands/psetex.test.ts +23 -0
- package/pkg/commands/psetex.ts +10 -0
- package/pkg/commands/pttl.test.ts +17 -0
- package/pkg/commands/pttl.ts +10 -0
- package/pkg/commands/randomkey.test.ts +17 -0
- package/pkg/commands/randomkey.ts +10 -0
- package/pkg/commands/rename.test.ts +18 -0
- package/pkg/commands/rename.ts +10 -0
- package/pkg/commands/renamenx.test.ts +32 -0
- package/pkg/commands/renamenx.ts +10 -0
- package/pkg/commands/rpop.test.ts +27 -0
- package/pkg/commands/rpop.ts +10 -0
- package/pkg/commands/rpush.test.ts +17 -0
- package/pkg/commands/rpush.ts +11 -0
- package/pkg/commands/rpushx.test.ts +29 -0
- package/pkg/commands/rpushx.ts +11 -0
- package/pkg/commands/sadd.test.ts +16 -0
- package/pkg/commands/sadd.ts +11 -0
- package/pkg/commands/scan.test.ts +50 -0
- package/pkg/commands/scan.ts +21 -0
- package/pkg/commands/scard.test.ts +15 -0
- package/pkg/commands/scard.ts +9 -0
- package/pkg/commands/sdiff.test.ts +20 -0
- package/pkg/commands/sdiff.ts +9 -0
- package/pkg/commands/sdiffstore.test.ts +21 -0
- package/pkg/commands/sdiffstore.ts +10 -0
- package/pkg/commands/set.test.ts +112 -0
- package/pkg/commands/set.ts +53 -0
- package/pkg/commands/setbit.test.ts +16 -0
- package/pkg/commands/setbit.ts +10 -0
- package/pkg/commands/setex.test.ts +22 -0
- package/pkg/commands/setex.ts +10 -0
- package/pkg/commands/setnx.test.ts +27 -0
- package/pkg/commands/setnx.ts +10 -0
- package/pkg/commands/setrange.test.ts +25 -0
- package/pkg/commands/setrange.ts +10 -0
- package/pkg/commands/sinter.test.ts +36 -0
- package/pkg/commands/sinter.ts +9 -0
- package/pkg/commands/sinterstore.test.ts +21 -0
- package/pkg/commands/sinterstore.ts +9 -0
- package/pkg/commands/sismember.test.ts +30 -0
- package/pkg/commands/sismember.ts +9 -0
- package/pkg/commands/smembers.test.ts +22 -0
- package/pkg/commands/smembers.ts +10 -0
- package/pkg/commands/smove.test.ts +18 -0
- package/pkg/commands/smove.ts +9 -0
- package/pkg/commands/spop.test.ts +35 -0
- package/pkg/commands/spop.ts +13 -0
- package/pkg/commands/srandmember.test.ts +32 -0
- package/pkg/commands/srandmember.ts +13 -0
- package/pkg/commands/srem.test.ts +18 -0
- package/pkg/commands/srem.ts +10 -0
- package/pkg/commands/sscan.test.ts +50 -0
- package/pkg/commands/sscan.ts +22 -0
- package/pkg/commands/strlen.test.ts +16 -0
- package/pkg/commands/strlen.ts +10 -0
- package/pkg/commands/sunion.test.ts +22 -0
- package/pkg/commands/sunion.ts +10 -0
- package/pkg/commands/sunionstore.test.ts +29 -0
- package/pkg/commands/sunionstore.ts +10 -0
- package/pkg/commands/time.test.ts +11 -0
- package/pkg/commands/time.ts +9 -0
- package/pkg/commands/touch.test.ts +20 -0
- package/pkg/commands/touch.ts +10 -0
- package/pkg/commands/ttl.test.ts +17 -0
- package/pkg/commands/ttl.ts +10 -0
- package/pkg/commands/type.test.ts +72 -0
- package/pkg/commands/type.ts +11 -0
- package/pkg/commands/unlink.test.ts +21 -0
- package/pkg/commands/unlink.ts +10 -0
- package/pkg/commands/zadd.test.ts +177 -0
- package/pkg/commands/zadd.ts +64 -0
- package/pkg/commands/zcard.test.ts +15 -0
- package/pkg/commands/zcard.ts +10 -0
- package/pkg/commands/zcount.test.ts +15 -0
- package/pkg/commands/zcount.ts +9 -0
- package/pkg/commands/zincrby.test.ts +20 -0
- package/pkg/commands/zincrby.ts +9 -0
- package/pkg/commands/zinterstore.test.ts +239 -0
- package/pkg/commands/zinterstore.ts +55 -0
- package/pkg/commands/zlexcount.test.ts +22 -0
- package/pkg/commands/zlexcount.ts +9 -0
- package/pkg/commands/zpopmax.test.ts +45 -0
- package/pkg/commands/zpopmax.ts +13 -0
- package/pkg/commands/zpopmin.test.ts +49 -0
- package/pkg/commands/zpopmin.ts +13 -0
- package/pkg/commands/zrange.test.ts +52 -0
- package/pkg/commands/zrange.ts +22 -0
- package/pkg/commands/zrank.test.ts +22 -0
- package/pkg/commands/zrank.ts +10 -0
- package/pkg/commands/zrem.test.ts +20 -0
- package/pkg/commands/zrem.ts +10 -0
- package/pkg/commands/zremrangebylex.test.ts +26 -0
- package/pkg/commands/zremrangebylex.ts +9 -0
- package/pkg/commands/zremrangebyrank.test.ts +27 -0
- package/pkg/commands/zremrangebyrank.ts +9 -0
- package/pkg/commands/zremrangebyscore.test.ts +24 -0
- package/pkg/commands/zremrangebyscore.ts +9 -0
- package/pkg/commands/zrevrank.test.ts +22 -0
- package/pkg/commands/zrevrank.ts +10 -0
- package/pkg/commands/zscan.test.ts +50 -0
- package/pkg/commands/zscan.ts +22 -0
- package/pkg/commands/zscore.test.ts +18 -0
- package/pkg/commands/zscore.ts +10 -0
- package/pkg/commands/zunionstore.test.ts +215 -0
- package/pkg/commands/zunionstore.ts +55 -0
- package/pkg/commands/zz.ts +1 -0
- package/pkg/error.ts +9 -0
- package/pkg/fastly.ts +54 -0
- package/pkg/http.test.ts +34 -0
- package/pkg/http.ts +62 -0
- package/pkg/index.ts +2 -0
- package/pkg/nodejs.ts +83 -0
- package/pkg/pipeline.test.ts +177 -0
- package/pkg/pipeline.ts +999 -0
- package/pkg/redis.ts +930 -0
- package/pkg/test-utils.ts +41 -0
- package/pkg/types.ts +4 -0
- package/pkg/util.ts +22 -0
- package/pnpm-lock.yaml +3940 -0
- package/tsconfig.json +96 -16
- package/tsup.config.ts +16 -0
- package/README.md +0 -63
- package/dist/main/client.d.ts +0 -21
- package/dist/main/client.js +0 -564
- package/dist/main/index-cjs.d.ts +0 -1
- package/dist/main/index-cjs.js +0 -120
- package/dist/main/types.d.ts +0 -179
- package/dist/main/types.js +0 -2
- package/dist/module/client.d.ts +0 -21
- package/dist/module/client.js +0 -559
- package/dist/module/index.d.ts +0 -3
- package/dist/module/index.js +0 -3
- package/dist/module/types.d.ts +0 -179
- package/dist/module/types.js +0 -1
- package/src/client.ts +0 -626
- package/src/index-cjs.ts +0 -117
- package/src/index.ts +0 -118
- package/src/types.ts +0 -410
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export * from "./append"
|
|
2
|
+
export * from "./bitcount"
|
|
3
|
+
export * from "./bitop"
|
|
4
|
+
export * from "./bitpos"
|
|
5
|
+
export * from "./dbsize"
|
|
6
|
+
export * from "./decr"
|
|
7
|
+
export * from "./decrby"
|
|
8
|
+
export * from "./del"
|
|
9
|
+
export * from "./echo"
|
|
10
|
+
export * from "./exists"
|
|
11
|
+
export * from "./expire"
|
|
12
|
+
export * from "./expireat"
|
|
13
|
+
export * from "./flushall"
|
|
14
|
+
export * from "./flushdb"
|
|
15
|
+
export * from "./get"
|
|
16
|
+
export * from "./getbit"
|
|
17
|
+
export * from "./getrange"
|
|
18
|
+
export * from "./getset"
|
|
19
|
+
export * from "./hdel"
|
|
20
|
+
export * from "./hexists"
|
|
21
|
+
export * from "./hget"
|
|
22
|
+
export * from "./hgetall"
|
|
23
|
+
export * from "./hincrby"
|
|
24
|
+
export * from "./hincrbyfloat"
|
|
25
|
+
export * from "./hkeys"
|
|
26
|
+
export * from "./hlen"
|
|
27
|
+
export * from "./hmget"
|
|
28
|
+
export * from "./hmset"
|
|
29
|
+
export * from "./hscan"
|
|
30
|
+
export * from "./hset"
|
|
31
|
+
export * from "./hsetnx"
|
|
32
|
+
export * from "./hstrlen"
|
|
33
|
+
export * from "./hvals"
|
|
34
|
+
export * from "./incr"
|
|
35
|
+
export * from "./incrby"
|
|
36
|
+
export * from "./incrbyfloat"
|
|
37
|
+
export * from "./keys"
|
|
38
|
+
export * from "./lindex"
|
|
39
|
+
export * from "./linsert"
|
|
40
|
+
export * from "./llen"
|
|
41
|
+
export * from "./lpop"
|
|
42
|
+
export * from "./lpush"
|
|
43
|
+
export * from "./lpushx"
|
|
44
|
+
export * from "./lrange"
|
|
45
|
+
export * from "./lrem"
|
|
46
|
+
export * from "./lset"
|
|
47
|
+
export * from "./ltrim"
|
|
48
|
+
export * from "./mget"
|
|
49
|
+
export * from "./mset"
|
|
50
|
+
export * from "./msetnx"
|
|
51
|
+
export * from "./persist"
|
|
52
|
+
export * from "./pexpire"
|
|
53
|
+
export * from "./pexpireat"
|
|
54
|
+
export * from "./ping"
|
|
55
|
+
export * from "./psetex"
|
|
56
|
+
export * from "./pttl"
|
|
57
|
+
export * from "./randomkey"
|
|
58
|
+
export * from "./rename"
|
|
59
|
+
export * from "./renamenx"
|
|
60
|
+
export * from "./rpop"
|
|
61
|
+
export * from "./rpush"
|
|
62
|
+
export * from "./rpushx"
|
|
63
|
+
export * from "./sadd"
|
|
64
|
+
export * from "./scan"
|
|
65
|
+
export * from "./scard"
|
|
66
|
+
export * from "./sdiff"
|
|
67
|
+
export * from "./sdiffstore"
|
|
68
|
+
export * from "./set"
|
|
69
|
+
export * from "./setbit"
|
|
70
|
+
export * from "./setex"
|
|
71
|
+
export * from "./setnx"
|
|
72
|
+
export * from "./setrange"
|
|
73
|
+
export * from "./sinter"
|
|
74
|
+
export * from "./sinterstore"
|
|
75
|
+
export * from "./sismember"
|
|
76
|
+
export * from "./smembers"
|
|
77
|
+
export * from "./smove"
|
|
78
|
+
export * from "./spop"
|
|
79
|
+
export * from "./srandmember"
|
|
80
|
+
export * from "./srem"
|
|
81
|
+
export * from "./sscan"
|
|
82
|
+
export * from "./strlen"
|
|
83
|
+
export * from "./sunion"
|
|
84
|
+
export * from "./sunionstore"
|
|
85
|
+
export * from "./time"
|
|
86
|
+
export * from "./touch"
|
|
87
|
+
export * from "./ttl"
|
|
88
|
+
export * from "./type"
|
|
89
|
+
export * from "./unlink"
|
|
90
|
+
export * from "./zadd"
|
|
91
|
+
export * from "./zcard"
|
|
92
|
+
export * from "./zcount"
|
|
93
|
+
export * from "./zincrby"
|
|
94
|
+
export * from "./zinterstore"
|
|
95
|
+
export * from "./zlexcount"
|
|
96
|
+
export * from "./zpopmax"
|
|
97
|
+
export * from "./zpopmin"
|
|
98
|
+
export * from "./zrange"
|
|
99
|
+
export * from "./zrank"
|
|
100
|
+
export * from "./zrem"
|
|
101
|
+
export * from "./zremrangebylex"
|
|
102
|
+
export * from "./zremrangebyrank"
|
|
103
|
+
export * from "./zremrangebyscore"
|
|
104
|
+
export * from "./zrevrank"
|
|
105
|
+
export * from "./zscan"
|
|
106
|
+
export * from "./zscore"
|
|
107
|
+
export * from "./zunionstore"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
3
|
+
import { SetCommand } from "./set"
|
|
4
|
+
import { KeysCommand } from "./keys"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
const { newKey, cleanup } = keygen()
|
|
8
|
+
afterAll(cleanup)
|
|
9
|
+
|
|
10
|
+
describe("when keys are found", () => {
|
|
11
|
+
it("returns keys", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
await new SetCommand(key, "value").exec(client)
|
|
14
|
+
const res = await new KeysCommand(key).exec(client)
|
|
15
|
+
expect(res).toEqual([key])
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPushCommand } from "./lpush"
|
|
5
|
+
import { LIndexCommand } from "./lindex"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
describe("when list exists", () => {
|
|
13
|
+
describe("when the index is in range", () => {
|
|
14
|
+
it("returns the element at index", async () => {
|
|
15
|
+
const key = newKey()
|
|
16
|
+
|
|
17
|
+
const value = randomUUID()
|
|
18
|
+
await new LPushCommand(key, value).exec(client)
|
|
19
|
+
const res = await new LIndexCommand(key, 0).exec(client)
|
|
20
|
+
expect(res).toEqual(value)
|
|
21
|
+
})
|
|
22
|
+
describe("when the index is out of bounds", () => {
|
|
23
|
+
it("returns null", async () => {
|
|
24
|
+
const key = newKey()
|
|
25
|
+
|
|
26
|
+
const value = randomUUID()
|
|
27
|
+
await new LPushCommand(key, value).exec(client)
|
|
28
|
+
const res = await new LIndexCommand(key, 1).exec(client)
|
|
29
|
+
expect(res).toBeNull()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LInsertCommand } from "./linsert"
|
|
5
|
+
import { LPushCommand } from "./lpush"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
it("adds the element", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
const value1 = randomUUID()
|
|
14
|
+
const value2 = randomUUID()
|
|
15
|
+
|
|
16
|
+
await new LPushCommand(key, value1).exec(client)
|
|
17
|
+
const res = await new LInsertCommand(key, "before", value1, value2).exec(client)
|
|
18
|
+
expect(res).toBe(2)
|
|
19
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LLenCommand } from "./llen"
|
|
5
|
+
import { LPushCommand } from "./lpush"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
describe("when list exists", () => {
|
|
12
|
+
it("returns the length of the list", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
await new LPushCommand(key, randomUUID()).exec(client)
|
|
15
|
+
const res = await new LLenCommand(key).exec(client)
|
|
16
|
+
expect(res).toEqual(1)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("when list does not exist", () => {
|
|
21
|
+
it("returns 0", async () => {
|
|
22
|
+
const key = newKey()
|
|
23
|
+
const res = await new LLenCommand(key).exec(client)
|
|
24
|
+
expect(res).toEqual(0)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPopCommand } from "./lpop"
|
|
5
|
+
import { LPushCommand } from "./lpush"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
describe("when list exists", () => {
|
|
12
|
+
it("returns the first element", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const value = randomUUID()
|
|
15
|
+
await new LPushCommand(key, value).exec(client)
|
|
16
|
+
const res = await new LPopCommand(key).exec(client)
|
|
17
|
+
expect(res).toEqual(value)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe("when list does not exist", () => {
|
|
22
|
+
it("returns null", async () => {
|
|
23
|
+
const key = newKey()
|
|
24
|
+
const res = await new LPopCommand(key).exec(client)
|
|
25
|
+
expect(res).toBeNull()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPushCommand } from "./lpush"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
const { newKey, cleanup } = keygen()
|
|
8
|
+
afterAll(cleanup)
|
|
9
|
+
|
|
10
|
+
it("returns the length after command", async () => {
|
|
11
|
+
const key = newKey()
|
|
12
|
+
const res = await new LPushCommand(key, randomUUID()).exec(client)
|
|
13
|
+
expect(res).toEqual(1)
|
|
14
|
+
const res2 = await new LPushCommand(key, randomUUID(), randomUUID()).exec(client)
|
|
15
|
+
|
|
16
|
+
expect(res2).toEqual(3)
|
|
17
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NonEmptyArray } from "../types"
|
|
2
|
+
import { Command } from "../command"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://redis.io/commands/lpush
|
|
6
|
+
*/
|
|
7
|
+
export class LPushCommand<TData = string> extends Command<number, number> {
|
|
8
|
+
constructor(key: string, ...elements: NonEmptyArray<TData>) {
|
|
9
|
+
super(["lpush", key, ...elements])
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPushXCommand } from "./lpushx"
|
|
5
|
+
import { LPushCommand } from "./lpush"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
describe("when list exists", () => {
|
|
12
|
+
it("returns the length after command", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
await new LPushCommand(key, randomUUID()).exec(client)
|
|
15
|
+
const res = await new LPushXCommand(key, randomUUID()).exec(client)
|
|
16
|
+
expect(res).toEqual(2)
|
|
17
|
+
const res2 = await new LPushXCommand(key, randomUUID(), randomUUID()).exec(client)
|
|
18
|
+
|
|
19
|
+
expect(res2).toEqual(4)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe("when list does not exist", () => {
|
|
24
|
+
it("does nothing", async () => {
|
|
25
|
+
const key = newKey()
|
|
26
|
+
const res = await new LPushXCommand(key, randomUUID()).exec(client)
|
|
27
|
+
expect(res).toEqual(0)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NonEmptyArray } from "../types"
|
|
2
|
+
import { Command } from "../command"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://redis.io/commands/lpushx
|
|
6
|
+
*/
|
|
7
|
+
export class LPushXCommand<TData> extends Command<number, number> {
|
|
8
|
+
constructor(key: string, ...elements: NonEmptyArray<TData>) {
|
|
9
|
+
super(["lpushx", key, ...elements])
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { RPushCommand } from "./rpush"
|
|
5
|
+
import { LRangeCommand } from "./lrange"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
it("returns the correct range", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
const value1 = randomUUID()
|
|
14
|
+
const value2 = randomUUID()
|
|
15
|
+
const value3 = randomUUID()
|
|
16
|
+
await new RPushCommand(key, value1, value2, value3).exec(client)
|
|
17
|
+
const res = await new LRangeCommand(key, 1, 2).exec(client)
|
|
18
|
+
expect(res).toBeDefined()
|
|
19
|
+
expect(res!.length).toEqual(2)
|
|
20
|
+
expect(res![0]).toEqual(value2)
|
|
21
|
+
expect(res![1]).toEqual(value3)
|
|
22
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
+
|
|
4
|
+
import { LPushCommand } from "./lpush"
|
|
5
|
+
import { LRemCommand } from "./lrem"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
it("returns the number of deleted elements", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
await new LPushCommand(key, "element").exec(client)
|
|
14
|
+
await new LPushCommand(key, "element").exec(client)
|
|
15
|
+
await new LPushCommand(key, "something else").exec(client)
|
|
16
|
+
|
|
17
|
+
const res = await new LRemCommand(key, 2, "element").exec(client)
|
|
18
|
+
expect(res).toBe(2)
|
|
19
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPushCommand } from "./lpush"
|
|
5
|
+
import { LSetCommand } from "./lset"
|
|
6
|
+
import { LPopCommand } from "./lpop"
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
describe("when list exists", () => {
|
|
13
|
+
describe("when the index is in range", () => {
|
|
14
|
+
it("replaces the element at index", async () => {
|
|
15
|
+
const key = newKey()
|
|
16
|
+
|
|
17
|
+
const value = randomUUID()
|
|
18
|
+
const newValue = randomUUID()
|
|
19
|
+
await new LPushCommand(key, value).exec(client)
|
|
20
|
+
const res = await new LSetCommand(key, newValue, 0).exec(client)
|
|
21
|
+
expect(res).toEqual("OK")
|
|
22
|
+
|
|
23
|
+
const res2 = await new LPopCommand(key).exec(client)
|
|
24
|
+
|
|
25
|
+
expect(res2).toEqual(newValue)
|
|
26
|
+
})
|
|
27
|
+
describe("when the index is out of bounds", () => {
|
|
28
|
+
it("returns null", async () => {
|
|
29
|
+
const key = newKey()
|
|
30
|
+
|
|
31
|
+
const value = randomUUID()
|
|
32
|
+
const newValue = randomUUID()
|
|
33
|
+
await new LPushCommand(key, value).exec(client)
|
|
34
|
+
expect(
|
|
35
|
+
async () => await new LSetCommand(key, newValue, 1).exec(client),
|
|
36
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`"ERR index out of range"`)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { LPushCommand } from "./lpush"
|
|
5
|
+
import { LTrimCommand } from "./ltrim"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
describe("when the list exists", () => {
|
|
12
|
+
it("returns ok", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
await new LPushCommand(key, randomUUID()).exec(client)
|
|
15
|
+
await new LPushCommand(key, randomUUID()).exec(client)
|
|
16
|
+
await new LPushCommand(key, randomUUID()).exec(client)
|
|
17
|
+
const res = await new LTrimCommand(key, 1, 2).exec(client)
|
|
18
|
+
expect(res).toEqual("OK")
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe("when the list does not exist", () => {
|
|
23
|
+
it("returns ok", async () => {
|
|
24
|
+
const key = newKey()
|
|
25
|
+
|
|
26
|
+
const res = await new LTrimCommand(key, 1, 2).exec(client)
|
|
27
|
+
expect(res).toEqual("OK")
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { MSetCommand } from "./mset"
|
|
5
|
+
import { MGetCommand } from "./mget"
|
|
6
|
+
|
|
7
|
+
import { SetCommand } from "./set"
|
|
8
|
+
const client = newHttpClient()
|
|
9
|
+
|
|
10
|
+
const { newKey, cleanup } = keygen()
|
|
11
|
+
afterAll(cleanup)
|
|
12
|
+
|
|
13
|
+
it("gets exiting values", async () => {
|
|
14
|
+
const key1 = newKey()
|
|
15
|
+
const value1 = randomUUID()
|
|
16
|
+
const key2 = newKey()
|
|
17
|
+
const value2 = randomUUID()
|
|
18
|
+
|
|
19
|
+
const kv: Record<string, string> = {}
|
|
20
|
+
kv[key1] = value1
|
|
21
|
+
kv[key2] = value2
|
|
22
|
+
const res = await new MSetCommand(kv).exec(client)
|
|
23
|
+
|
|
24
|
+
expect(res).toEqual("OK")
|
|
25
|
+
const res2 = await new MGetCommand<[string, string]>(key1, key2).exec(client)
|
|
26
|
+
|
|
27
|
+
expect(res2).toEqual([value1, value2])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("gets a non-existing value", async () => {
|
|
31
|
+
const key = newKey()
|
|
32
|
+
const res = await new MGetCommand<[null]>(key).exec(client)
|
|
33
|
+
|
|
34
|
+
expect(res).toEqual([null])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("gets an object", async () => {
|
|
38
|
+
const key = newKey()
|
|
39
|
+
const value = { v: randomUUID() }
|
|
40
|
+
await new SetCommand(key, value).exec(client)
|
|
41
|
+
const res = await new MGetCommand<[{ v: string }]>(key).exec(client)
|
|
42
|
+
|
|
43
|
+
expect(res).toEqual([value])
|
|
44
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/mget
|
|
4
|
+
*/
|
|
5
|
+
export class MGetCommand<TData extends unknown[]> extends Command<TData, (string | null)[]> {
|
|
6
|
+
constructor(...keys: [string, ...string[]]) {
|
|
7
|
+
super(["mget", ...keys])
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { MSetCommand } from "./mset"
|
|
5
|
+
import { MGetCommand } from "./mget"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("gets exiting values", async () => {
|
|
13
|
+
const key1 = newKey()
|
|
14
|
+
const key2 = newKey()
|
|
15
|
+
const kv = {
|
|
16
|
+
[key1]: randomUUID(),
|
|
17
|
+
[key2]: randomUUID(),
|
|
18
|
+
}
|
|
19
|
+
const res = await new MSetCommand(kv).exec(client)
|
|
20
|
+
|
|
21
|
+
expect(res).toEqual("OK")
|
|
22
|
+
const res2 = await new MGetCommand(key1, key2).exec(client)
|
|
23
|
+
expect(res2).toEqual(Object.values(kv))
|
|
24
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://redis.io/commands/mset
|
|
5
|
+
*/
|
|
6
|
+
export class MSetCommand<TData> extends Command<"OK", "OK"> {
|
|
7
|
+
constructor(kv: { [key: string]: TData }) {
|
|
8
|
+
super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])])
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { MGetCommand } from "./mget"
|
|
5
|
+
import { SetCommand } from "./set"
|
|
6
|
+
import { GetCommand } from "./get"
|
|
7
|
+
import { MSetNXCommand } from "./msetnx"
|
|
8
|
+
const client = newHttpClient()
|
|
9
|
+
|
|
10
|
+
const { newKey, cleanup } = keygen()
|
|
11
|
+
afterAll(cleanup)
|
|
12
|
+
|
|
13
|
+
it("sets values", async () => {
|
|
14
|
+
const key1 = newKey()
|
|
15
|
+
const value1 = randomUUID()
|
|
16
|
+
const key2 = newKey()
|
|
17
|
+
const value2 = randomUUID()
|
|
18
|
+
|
|
19
|
+
const kv: Record<string, string> = {}
|
|
20
|
+
kv[key1] = value1
|
|
21
|
+
kv[key2] = value2
|
|
22
|
+
const res = await new MSetNXCommand(kv).exec(client)
|
|
23
|
+
|
|
24
|
+
expect(res).toEqual(1)
|
|
25
|
+
const res2 = await new MGetCommand<[string, string]>(key1, key2).exec(client)
|
|
26
|
+
|
|
27
|
+
expect(res2).toEqual([value1, value2])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("does not set values if one key already exists", async () => {
|
|
31
|
+
const key1 = newKey()
|
|
32
|
+
const value1 = randomUUID()
|
|
33
|
+
const key2 = newKey()
|
|
34
|
+
const value2 = randomUUID()
|
|
35
|
+
await new SetCommand(key1, value1).exec(client)
|
|
36
|
+
const kv: Record<string, string> = {}
|
|
37
|
+
kv[key1] = value1
|
|
38
|
+
kv[key2] = value2
|
|
39
|
+
const res = await new MSetNXCommand(kv).exec(client)
|
|
40
|
+
|
|
41
|
+
expect(res).toEqual(0)
|
|
42
|
+
|
|
43
|
+
const res2 = await new GetCommand(key2).exec(client)
|
|
44
|
+
|
|
45
|
+
expect(res2).toBeNull()
|
|
46
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://redis.io/commands/msetnx
|
|
5
|
+
*/
|
|
6
|
+
export class MSetNXCommand<TData = string> extends Command<number, number> {
|
|
7
|
+
constructor(kv: { [key: string]: TData }) {
|
|
8
|
+
super(["msetnx", ...Object.entries(kv).flatMap((_) => _)])
|
|
9
|
+
}
|
|
10
|
+
}
|