@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,23 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { SetCommand } from "./set"
|
|
3
|
+
import { DecrByCommand } from "./decrby"
|
|
4
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
const { newKey, cleanup } = keygen()
|
|
8
|
+
afterAll(cleanup)
|
|
9
|
+
|
|
10
|
+
it("decrements a non-existing value", async () => {
|
|
11
|
+
const key = newKey()
|
|
12
|
+
const res = await new DecrByCommand(key, 2).exec(client)
|
|
13
|
+
|
|
14
|
+
expect(res).toEqual(-2)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it("decrements and existing value", async () => {
|
|
18
|
+
const key = newKey()
|
|
19
|
+
await new SetCommand(key, 5).exec(client)
|
|
20
|
+
const res = await new DecrByCommand(key, 2).exec(client)
|
|
21
|
+
|
|
22
|
+
expect(res).toEqual(3)
|
|
23
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
|
|
3
|
+
import { DelCommand } from "./del"
|
|
4
|
+
import { SetCommand } from "./set"
|
|
5
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
describe("when key does not exist", () => {
|
|
13
|
+
it("does nothing", async () => {
|
|
14
|
+
const key = newKey()
|
|
15
|
+
|
|
16
|
+
const res = await new DelCommand(key).exec(client)
|
|
17
|
+
expect(res).toEqual(0)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
describe("when key does exist", () => {
|
|
21
|
+
it("deletes the key", async () => {
|
|
22
|
+
const key = newKey()
|
|
23
|
+
await new SetCommand(key, "value").exec(client)
|
|
24
|
+
const res = await new DelCommand(key).exec(client)
|
|
25
|
+
expect(res).toEqual(1)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
describe("with multiple keys", () => {
|
|
29
|
+
describe("when one does not exist", () => {
|
|
30
|
+
it("deletes all keys", async () => {
|
|
31
|
+
const key1 = newKey()
|
|
32
|
+
const key2 = newKey()
|
|
33
|
+
await new SetCommand(key1, "value").exec(client)
|
|
34
|
+
const res = await new DelCommand(key1, key2).exec(client)
|
|
35
|
+
expect(res).toEqual(1)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NonEmptyArray } from "../types"
|
|
2
|
+
import { Command } from "../command"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://redis.io/commands/del
|
|
6
|
+
*/
|
|
7
|
+
export class DelCommand extends Command<number, number> {
|
|
8
|
+
constructor(...keys: NonEmptyArray<string>) {
|
|
9
|
+
super(["del", ...keys])
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect } from "@jest/globals"
|
|
4
|
+
import { EchoCommand } from "./echo"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
it("returns the message", async () => {
|
|
8
|
+
const message = randomUUID()
|
|
9
|
+
const res = await new EchoCommand(message).exec(client)
|
|
10
|
+
expect(res).toBe(message)
|
|
11
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { ExistsCommand } from "./exists"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { SetCommand } from "./set"
|
|
5
|
+
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
describe("when the key does not eist", () => {
|
|
12
|
+
it("it returns 1", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
|
|
15
|
+
const res = await new ExistsCommand(key).exec(client)
|
|
16
|
+
expect(res).toEqual(0)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
describe("when the key exists", () => {
|
|
20
|
+
it("it returns 1", async () => {
|
|
21
|
+
const key = newKey()
|
|
22
|
+
await new SetCommand(key, "value").exec(client)
|
|
23
|
+
const res = await new ExistsCommand(key).exec(client)
|
|
24
|
+
expect(res).toEqual(1)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
describe("with multiple keys", () => {
|
|
28
|
+
it("it returns the number of found keys", async () => {
|
|
29
|
+
const key1 = newKey()
|
|
30
|
+
const key2 = newKey()
|
|
31
|
+
const key3 = newKey()
|
|
32
|
+
await new SetCommand(key1, "value").exec(client)
|
|
33
|
+
await new SetCommand(key2, "value").exec(client)
|
|
34
|
+
const res = await new ExistsCommand(key1, key2, key3).exec(client)
|
|
35
|
+
expect(res).toEqual(2)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NonEmptyArray } from "../types"
|
|
2
|
+
import { Command } from "../command"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://redis.io/commands/exists
|
|
6
|
+
*/
|
|
7
|
+
export class ExistsCommand extends Command<0 | 1, "0" | "1"> {
|
|
8
|
+
constructor(...keys: NonEmptyArray<string>) {
|
|
9
|
+
super(["exists", ...keys])
|
|
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 { SetCommand } from "./set"
|
|
5
|
+
import { ExpireCommand } from "./expire"
|
|
6
|
+
import { GetCommand } from "./get"
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("expires a key correctly", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const value = randomUUID()
|
|
15
|
+
await new SetCommand(key, value).exec(client)
|
|
16
|
+
const res = await new ExpireCommand(key, 1).exec(client)
|
|
17
|
+
expect(res).toEqual(1)
|
|
18
|
+
await new Promise((res) => setTimeout(res, 2000))
|
|
19
|
+
const res2 = await new GetCommand(key).exec(client)
|
|
20
|
+
|
|
21
|
+
expect(res2).toBeNull()
|
|
22
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { SetCommand } from "./set"
|
|
5
|
+
import { GetCommand } from "./get"
|
|
6
|
+
import { ExpireAtCommand } from "./expireat"
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
describe("without options", () => {
|
|
13
|
+
it("expires the key", async () => {
|
|
14
|
+
const key = newKey()
|
|
15
|
+
const value = randomUUID()
|
|
16
|
+
await new SetCommand(key, value).exec(client)
|
|
17
|
+
|
|
18
|
+
const res = await new ExpireAtCommand(key, 1).exec(client)
|
|
19
|
+
expect(res).toEqual(1)
|
|
20
|
+
await new Promise((res) => setTimeout(res, 2000))
|
|
21
|
+
const res2 = await new GetCommand(key).exec(client)
|
|
22
|
+
expect(res2).toBeNull
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { newHttpClient } from "../test-utils"
|
|
2
|
+
import { describe, it, expect } from "@jest/globals"
|
|
3
|
+
import { FlushAllCommand } from "./flushall"
|
|
4
|
+
const client = newHttpClient()
|
|
5
|
+
|
|
6
|
+
describe("without options", () => {
|
|
7
|
+
it("flushes the db", async () => {
|
|
8
|
+
const res = await new FlushAllCommand().exec(client)
|
|
9
|
+
expect(res).toBe("OK")
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
describe("async", () => {
|
|
13
|
+
it("flushes the db", async () => {
|
|
14
|
+
const res = await new FlushAllCommand({ async: true }).exec(client)
|
|
15
|
+
expect(res).toBe("OK")
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/flushall
|
|
4
|
+
*/
|
|
5
|
+
export class FlushAllCommand extends Command<"OK", "OK"> {
|
|
6
|
+
constructor(opts?: { async?: boolean }) {
|
|
7
|
+
const command = ["flushall"]
|
|
8
|
+
if (opts?.async) {
|
|
9
|
+
command.push("async")
|
|
10
|
+
}
|
|
11
|
+
super(command)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { newHttpClient } from "../test-utils"
|
|
2
|
+
import { describe, it, expect } from "@jest/globals"
|
|
3
|
+
import { FlushDBCommand } from "./flushdb"
|
|
4
|
+
const client = newHttpClient()
|
|
5
|
+
|
|
6
|
+
describe("without options", () => {
|
|
7
|
+
it("flushes the db", async () => {
|
|
8
|
+
const res = await new FlushDBCommand().exec(client)
|
|
9
|
+
expect(res).toBe("OK")
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
describe("async", () => {
|
|
13
|
+
it("flushes the db", async () => {
|
|
14
|
+
const res = await new FlushDBCommand({ async: true }).exec(client)
|
|
15
|
+
expect(res).toBe("OK")
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/flushdb
|
|
4
|
+
*/
|
|
5
|
+
export class FlushDBCommand extends Command<"OK", "OK"> {
|
|
6
|
+
constructor(opts?: { async?: boolean }) {
|
|
7
|
+
const command = ["flushdb"]
|
|
8
|
+
if (opts?.async) {
|
|
9
|
+
command.push("async")
|
|
10
|
+
}
|
|
11
|
+
super(command)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { SetCommand } from "./set"
|
|
5
|
+
import { GetCommand } from "./get"
|
|
6
|
+
const client = newHttpClient()
|
|
7
|
+
|
|
8
|
+
const { newKey, cleanup } = keygen()
|
|
9
|
+
afterAll(cleanup)
|
|
10
|
+
|
|
11
|
+
it("gets an exiting value", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
const value = randomUUID()
|
|
14
|
+
await new SetCommand(key, value).exec(client)
|
|
15
|
+
const res = await new GetCommand(key).exec(client)
|
|
16
|
+
|
|
17
|
+
expect(res).toEqual(value)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("gets a non-existing value", async () => {
|
|
21
|
+
const key = newKey()
|
|
22
|
+
const res = await new GetCommand(key).exec(client)
|
|
23
|
+
|
|
24
|
+
expect(res).toBeNull()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("gets an object", async () => {
|
|
28
|
+
const key = newKey()
|
|
29
|
+
const value = { v: randomUUID() }
|
|
30
|
+
await new SetCommand(key, value).exec(client)
|
|
31
|
+
const res = await new GetCommand(key).exec(client)
|
|
32
|
+
|
|
33
|
+
expect(res).toEqual(value)
|
|
34
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
+
import { SetBitCommand } from "./setbit"
|
|
4
|
+
import { GetBitCommand } from "./getbit"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
const { newKey, cleanup } = keygen()
|
|
8
|
+
afterAll(cleanup)
|
|
9
|
+
|
|
10
|
+
it("returns the bit at offset", async () => {
|
|
11
|
+
const key = newKey()
|
|
12
|
+
|
|
13
|
+
await new SetBitCommand(key, 0, 1).exec(client)
|
|
14
|
+
const res = await new GetBitCommand(key, 0).exec(client)
|
|
15
|
+
expect(res).toBe(1)
|
|
16
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
+
import { GetRangeCommand } from "./getrange"
|
|
4
|
+
import { SetCommand } from "./set"
|
|
5
|
+
const client = newHttpClient()
|
|
6
|
+
|
|
7
|
+
const { newKey, cleanup } = keygen()
|
|
8
|
+
afterAll(cleanup)
|
|
9
|
+
|
|
10
|
+
it("gets an exiting value", async () => {
|
|
11
|
+
const key = newKey()
|
|
12
|
+
const value = "Hello World"
|
|
13
|
+
await new SetCommand(key, value).exec(client)
|
|
14
|
+
const res = await new GetRangeCommand(key, 2, 4).exec(client)
|
|
15
|
+
|
|
16
|
+
expect(res).toBeDefined()
|
|
17
|
+
expect(res!).toEqual(value.slice(2, 5))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("gets a non-existing value", async () => {
|
|
21
|
+
const key = newKey()
|
|
22
|
+
const res = await new GetRangeCommand(key, 10, 24).exec(client)
|
|
23
|
+
|
|
24
|
+
expect(res).toEqual("")
|
|
25
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://redis.io/commands/getrange
|
|
5
|
+
*/
|
|
6
|
+
export class GetRangeCommand extends Command<string, string> {
|
|
7
|
+
constructor(key: string, start: number, end: number) {
|
|
8
|
+
super(["getrange", key, start, end])
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { GetSetCommand } from "./getset"
|
|
5
|
+
import { SetCommand } from "./set"
|
|
6
|
+
import { GetCommand } from "./get"
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("overwrites the original value", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const value = randomUUID()
|
|
15
|
+
const newValue = randomUUID()
|
|
16
|
+
await new SetCommand(key, value).exec(client)
|
|
17
|
+
const res = await new GetSetCommand(key, newValue).exec(client)
|
|
18
|
+
|
|
19
|
+
expect(res).toEqual(value)
|
|
20
|
+
const res2 = await new GetCommand(key).exec(client)
|
|
21
|
+
|
|
22
|
+
expect(res2).toEqual(newValue)
|
|
23
|
+
})
|
|
24
|
+
it("sets a new value if empty", async () => {
|
|
25
|
+
const key = newKey()
|
|
26
|
+
const newValue = randomUUID()
|
|
27
|
+
const res = await new GetSetCommand(key, newValue).exec(client)
|
|
28
|
+
|
|
29
|
+
expect(res).toBeNull()
|
|
30
|
+
const res2 = await new GetCommand(key).exec(client)
|
|
31
|
+
|
|
32
|
+
expect(res2).toEqual(newValue)
|
|
33
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "../command"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://redis.io/commands/getset
|
|
5
|
+
*/
|
|
6
|
+
export class GetSetCommand<TData = string> extends Command<TData | null, unknown | null> {
|
|
7
|
+
constructor(key: string, value: TData) {
|
|
8
|
+
super(["getset", key, value])
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { HDelCommand } from "./hdel"
|
|
5
|
+
import { HSetCommand } from "./hset"
|
|
6
|
+
import { HGetCommand } from "./hget"
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("deletes a hash that does not exist", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const field = randomUUID()
|
|
15
|
+
const res = await new HDelCommand(key, field).exec(client)
|
|
16
|
+
|
|
17
|
+
expect(res).toEqual(0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("deletes a field that exists", async () => {
|
|
21
|
+
const key = newKey()
|
|
22
|
+
const field = randomUUID()
|
|
23
|
+
await new HSetCommand(key, field, randomUUID()).exec(client)
|
|
24
|
+
const res = await new HDelCommand(key, field).exec(client)
|
|
25
|
+
|
|
26
|
+
expect(res).toEqual(1)
|
|
27
|
+
const res2 = await new HGetCommand(key, field).exec(client)
|
|
28
|
+
|
|
29
|
+
expect(res2).toEqual(null)
|
|
30
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { HSetCommand } from "./hset"
|
|
5
|
+
import { HExistsCommand } from "./hexists"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("returns 1 for an existing field", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const field = randomUUID()
|
|
15
|
+
await new HSetCommand(key, field, randomUUID()).exec(client)
|
|
16
|
+
const res = await new HExistsCommand(key, field).exec(client)
|
|
17
|
+
expect(res).toEqual(1)
|
|
18
|
+
})
|
|
19
|
+
it("returns 0 if field does not exist", async () => {
|
|
20
|
+
const key = newKey()
|
|
21
|
+
await new HSetCommand(key, randomUUID(), randomUUID()).exec(client)
|
|
22
|
+
|
|
23
|
+
const res = await new HExistsCommand(key, "not-existing-field").exec(client)
|
|
24
|
+
expect(res).toEqual(0)
|
|
25
|
+
})
|
|
26
|
+
it("returns 0 if hash does not exist", async () => {
|
|
27
|
+
const key = newKey()
|
|
28
|
+
const field = randomUUID()
|
|
29
|
+
const res = await new HExistsCommand(key, field).exec(client)
|
|
30
|
+
expect(res).toEqual(0)
|
|
31
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { HSetCommand } from "./hset"
|
|
5
|
+
import { HGetCommand } from "./hget"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
|
|
12
|
+
it("gets an exiting value", async () => {
|
|
13
|
+
const key = newKey()
|
|
14
|
+
const field = randomUUID()
|
|
15
|
+
const value = randomUUID()
|
|
16
|
+
await new HSetCommand(key, field, value).exec(client)
|
|
17
|
+
const res = await new HGetCommand(key, field).exec(client)
|
|
18
|
+
|
|
19
|
+
expect(res).toEqual(value)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it("gets a non-existing hash", async () => {
|
|
23
|
+
const key = newKey()
|
|
24
|
+
const field = randomUUID()
|
|
25
|
+
const res = await new HGetCommand(key, field).exec(client)
|
|
26
|
+
|
|
27
|
+
expect(res).toBeNull()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("gets a non-existing field", async () => {
|
|
31
|
+
const key = newKey()
|
|
32
|
+
const field = randomUUID()
|
|
33
|
+
await new HSetCommand(key, randomUUID(), randomUUID()).exec(client)
|
|
34
|
+
const res = await new HGetCommand(key, field).exec(client)
|
|
35
|
+
|
|
36
|
+
expect(res).toBeNull()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("gets an object", async () => {
|
|
40
|
+
const key = newKey()
|
|
41
|
+
const field = randomUUID()
|
|
42
|
+
const value = { v: randomUUID() }
|
|
43
|
+
await new HSetCommand(key, field, value).exec(client)
|
|
44
|
+
const res = await new HGetCommand(key, field).exec(client)
|
|
45
|
+
|
|
46
|
+
expect(res).toEqual(value)
|
|
47
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
+
import { HSetCommand } from "./hset"
|
|
5
|
+
import { HGetAllCommand } from "./hgetall"
|
|
6
|
+
|
|
7
|
+
const client = newHttpClient()
|
|
8
|
+
|
|
9
|
+
const { newKey, cleanup } = keygen()
|
|
10
|
+
afterAll(cleanup)
|
|
11
|
+
it("returns all fields", async () => {
|
|
12
|
+
const key = newKey()
|
|
13
|
+
const field2 = randomUUID()
|
|
14
|
+
const field1 = randomUUID()
|
|
15
|
+
const value1 = false
|
|
16
|
+
const value2 = randomUUID()
|
|
17
|
+
await new HSetCommand(key, field1, value1).exec(client)
|
|
18
|
+
await new HSetCommand(key, field2, value2).exec(client)
|
|
19
|
+
const res = await new HGetAllCommand(key).exec(client)
|
|
20
|
+
|
|
21
|
+
const obj = {
|
|
22
|
+
[field1]: value1,
|
|
23
|
+
[field2]: value2,
|
|
24
|
+
}
|
|
25
|
+
expect(res).toEqual(obj)
|
|
26
|
+
})
|
|
27
|
+
describe("when hash does not exist", () => {
|
|
28
|
+
it("it returns null", async () => {
|
|
29
|
+
const res = await new HGetAllCommand(randomUUID()).exec(client)
|
|
30
|
+
expect(res).toBeNull()
|
|
31
|
+
})
|
|
32
|
+
})
|