@upstash/redis 1.0.0-alpha.2 → 1.0.0-alpha.7
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/README.md +256 -0
- package/{dist/chunk-7YUZYRJS.mjs → chunk-7YUZYRJS.mjs} +0 -0
- package/{dist/chunk-FJSI5EBJ.mjs → chunk-AHCVU33N.mjs} +2 -2
- package/{dist/chunk-ZIB6XPPC.mjs → chunk-HGM7M7CJ.mjs} +9 -4
- package/{dist/chunk-U7OXAQMQ.mjs → chunk-HIDCSH5S.mjs} +0 -1
- package/{dist/chunk-Y5TC4HX2.mjs → chunk-T66TTHSV.mjs} +5 -5
- package/{dist/cloudflare.d.ts → cloudflare.d.ts} +2 -2
- package/{dist/cloudflare.js → cloudflare.js} +12 -9
- package/{dist/cloudflare.mjs → cloudflare.mjs} +3 -3
- package/{dist/commands.d.ts → commands.d.ts} +5 -3
- package/{dist/commands.js → commands.js} +10 -4
- package/{dist/commands.mjs → commands.mjs} +3 -1
- package/{dist/fastly.d.ts → fastly.d.ts} +2 -2
- package/{dist/fastly.js → fastly.js} +12 -9
- package/{dist/fastly.mjs → fastly.mjs} +3 -3
- package/{dist/http.d.ts → http.d.ts} +0 -0
- package/{dist/http.js → http.js} +0 -1
- package/{dist/http.mjs → http.mjs} +1 -1
- package/{dist/index.d.ts → index.d.ts} +2 -2
- package/{dist/index.js → index.js} +13 -10
- package/index.mjs +13 -0
- package/{dist/nodejs.d.ts → nodejs.d.ts} +2 -2
- package/{dist/nodejs.js → nodejs.js} +13 -10
- package/nodejs.mjs +10 -0
- package/package.json +1 -1
- package/{dist/redis-dd052782.d.ts → redis-71fa1ee6.d.ts} +7 -3
- package/{dist/zunionstore-dffa797d.d.ts → zunionstore-b38007ba.d.ts} +1 -1
- package/.eslintrc.js +0 -49
- package/.prettierrc.js +0 -7
- package/LICENSE +0 -21
- package/dist/index.mjs +0 -13
- package/dist/nodejs.mjs +0 -10
- package/dist/package.json +0 -1
- package/jest.config.js +0 -195
- package/pkg/cloudflare.ts +0 -77
- package/pkg/command.ts +0 -40
- package/pkg/commands/append.test.ts +0 -28
- package/pkg/commands/append.ts +0 -10
- package/pkg/commands/bitcount.test.ts +0 -36
- package/pkg/commands/bitcount.ts +0 -19
- package/pkg/commands/bitop.test.ts +0 -44
- package/pkg/commands/bitop.ts +0 -22
- package/pkg/commands/bitpos.test.ts +0 -26
- package/pkg/commands/bitpos.ts +0 -10
- package/pkg/commands/dbsize.test.ts +0 -17
- package/pkg/commands/dbsize.ts +0 -10
- package/pkg/commands/decr.test.ts +0 -22
- package/pkg/commands/decr.ts +0 -10
- package/pkg/commands/decrby.test.ts +0 -23
- package/pkg/commands/decrby.ts +0 -10
- package/pkg/commands/del.test.ts +0 -38
- package/pkg/commands/del.ts +0 -11
- package/pkg/commands/echo.test.ts +0 -11
- package/pkg/commands/echo.ts +0 -10
- package/pkg/commands/exists.test.ts +0 -37
- package/pkg/commands/exists.ts +0 -11
- package/pkg/commands/expire.test.ts +0 -22
- package/pkg/commands/expire.ts +0 -10
- package/pkg/commands/expireat.test.ts +0 -24
- package/pkg/commands/expireat.ts +0 -10
- package/pkg/commands/flushall.test.ts +0 -17
- package/pkg/commands/flushall.ts +0 -13
- package/pkg/commands/flushdb.test.ts +0 -17
- package/pkg/commands/flushdb.ts +0 -13
- package/pkg/commands/get.test.ts +0 -34
- package/pkg/commands/get.ts +0 -10
- package/pkg/commands/getbit.test.ts +0 -16
- package/pkg/commands/getbit.ts +0 -10
- package/pkg/commands/getrange.test.ts +0 -25
- package/pkg/commands/getrange.ts +0 -10
- package/pkg/commands/getset.test.ts +0 -33
- package/pkg/commands/getset.ts +0 -10
- package/pkg/commands/hdel.test.ts +0 -30
- package/pkg/commands/hdel.ts +0 -10
- package/pkg/commands/hexists.test.ts +0 -31
- package/pkg/commands/hexists.ts +0 -10
- package/pkg/commands/hget.test.ts +0 -47
- package/pkg/commands/hget.ts +0 -10
- package/pkg/commands/hgetall.test.ts +0 -32
- package/pkg/commands/hgetall.ts +0 -35
- package/pkg/commands/hincrby.test.ts +0 -27
- package/pkg/commands/hincrby.ts +0 -10
- package/pkg/commands/hincrbyfloat.test.ts +0 -25
- package/pkg/commands/hincrbyfloat.ts +0 -10
- package/pkg/commands/hkeys.test.ts +0 -22
- package/pkg/commands/hkeys.ts +0 -10
- package/pkg/commands/hlen.test.ts +0 -24
- package/pkg/commands/hlen.ts +0 -10
- package/pkg/commands/hmget.test.ts +0 -48
- package/pkg/commands/hmget.ts +0 -41
- package/pkg/commands/hmset.test.ts +0 -24
- package/pkg/commands/hmset.ts +0 -10
- package/pkg/commands/hscan.test.ts +0 -46
- package/pkg/commands/hscan.ts +0 -22
- package/pkg/commands/hset.test.ts +0 -21
- package/pkg/commands/hset.ts +0 -10
- package/pkg/commands/hsetnx.test.ts +0 -37
- package/pkg/commands/hsetnx.ts +0 -10
- package/pkg/commands/hstrlen.test.ts +0 -24
- package/pkg/commands/hstrlen.ts +0 -10
- package/pkg/commands/hvals.test.ts +0 -23
- package/pkg/commands/hvals.ts +0 -10
- package/pkg/commands/incr.test.ts +0 -23
- package/pkg/commands/incr.ts +0 -10
- package/pkg/commands/incrby.test.ts +0 -23
- package/pkg/commands/incrby.ts +0 -10
- package/pkg/commands/incrbyfloat.test.ts +0 -24
- package/pkg/commands/incrbyfloat.ts +0 -10
- package/pkg/commands/index.ts +0 -107
- package/pkg/commands/keys.test.ts +0 -17
- package/pkg/commands/keys.ts +0 -10
- package/pkg/commands/lindex.test.ts +0 -33
- package/pkg/commands/lindex.ts +0 -7
- package/pkg/commands/linsert.test.ts +0 -19
- package/pkg/commands/linsert.ts +0 -6
- package/pkg/commands/llen.test.ts +0 -26
- package/pkg/commands/llen.ts +0 -10
- package/pkg/commands/lpop.test.ts +0 -27
- package/pkg/commands/lpop.ts +0 -10
- package/pkg/commands/lpush.test.ts +0 -17
- package/pkg/commands/lpush.ts +0 -11
- package/pkg/commands/lpushx.test.ts +0 -29
- package/pkg/commands/lpushx.ts +0 -11
- package/pkg/commands/lrange.test.ts +0 -22
- package/pkg/commands/lrange.ts +0 -7
- package/pkg/commands/lrem.test.ts +0 -19
- package/pkg/commands/lrem.ts +0 -6
- package/pkg/commands/lset.test.ts +0 -40
- package/pkg/commands/lset.ts +0 -7
- package/pkg/commands/ltrim.test.ts +0 -29
- package/pkg/commands/ltrim.ts +0 -7
- package/pkg/commands/mget.test.ts +0 -44
- package/pkg/commands/mget.ts +0 -9
- package/pkg/commands/mset.test.ts +0 -24
- package/pkg/commands/mset.ts +0 -10
- package/pkg/commands/msetnx.test.ts +0 -46
- package/pkg/commands/msetnx.ts +0 -10
- package/pkg/commands/persist.test.ts +0 -22
- package/pkg/commands/persist.ts +0 -10
- package/pkg/commands/pexpire.test.ts +0 -24
- package/pkg/commands/pexpire.ts +0 -10
- package/pkg/commands/pexpireat.test.ts +0 -24
- package/pkg/commands/pexpireat.ts +0 -10
- package/pkg/commands/ping.test.ts +0 -19
- package/pkg/commands/ping.ts +0 -13
- package/pkg/commands/psetex.test.ts +0 -23
- package/pkg/commands/psetex.ts +0 -10
- package/pkg/commands/pttl.test.ts +0 -17
- package/pkg/commands/pttl.ts +0 -10
- package/pkg/commands/randomkey.test.ts +0 -17
- package/pkg/commands/randomkey.ts +0 -10
- package/pkg/commands/rename.test.ts +0 -18
- package/pkg/commands/rename.ts +0 -10
- package/pkg/commands/renamenx.test.ts +0 -32
- package/pkg/commands/renamenx.ts +0 -10
- package/pkg/commands/rpop.test.ts +0 -27
- package/pkg/commands/rpop.ts +0 -10
- package/pkg/commands/rpush.test.ts +0 -17
- package/pkg/commands/rpush.ts +0 -11
- package/pkg/commands/rpushx.test.ts +0 -29
- package/pkg/commands/rpushx.ts +0 -11
- package/pkg/commands/sadd.test.ts +0 -16
- package/pkg/commands/sadd.ts +0 -11
- package/pkg/commands/scan.test.ts +0 -50
- package/pkg/commands/scan.ts +0 -21
- package/pkg/commands/scard.test.ts +0 -15
- package/pkg/commands/scard.ts +0 -9
- package/pkg/commands/sdiff.test.ts +0 -20
- package/pkg/commands/sdiff.ts +0 -9
- package/pkg/commands/sdiffstore.test.ts +0 -21
- package/pkg/commands/sdiffstore.ts +0 -10
- package/pkg/commands/set.test.ts +0 -112
- package/pkg/commands/set.ts +0 -53
- package/pkg/commands/setbit.test.ts +0 -16
- package/pkg/commands/setbit.ts +0 -10
- package/pkg/commands/setex.test.ts +0 -22
- package/pkg/commands/setex.ts +0 -10
- package/pkg/commands/setnx.test.ts +0 -27
- package/pkg/commands/setnx.ts +0 -10
- package/pkg/commands/setrange.test.ts +0 -25
- package/pkg/commands/setrange.ts +0 -10
- package/pkg/commands/sinter.test.ts +0 -36
- package/pkg/commands/sinter.ts +0 -9
- package/pkg/commands/sinterstore.test.ts +0 -21
- package/pkg/commands/sinterstore.ts +0 -9
- package/pkg/commands/sismember.test.ts +0 -30
- package/pkg/commands/sismember.ts +0 -9
- package/pkg/commands/smembers.test.ts +0 -22
- package/pkg/commands/smembers.ts +0 -10
- package/pkg/commands/smove.test.ts +0 -18
- package/pkg/commands/smove.ts +0 -9
- package/pkg/commands/spop.test.ts +0 -35
- package/pkg/commands/spop.ts +0 -13
- package/pkg/commands/srandmember.test.ts +0 -32
- package/pkg/commands/srandmember.ts +0 -13
- package/pkg/commands/srem.test.ts +0 -18
- package/pkg/commands/srem.ts +0 -10
- package/pkg/commands/sscan.test.ts +0 -50
- package/pkg/commands/sscan.ts +0 -22
- package/pkg/commands/strlen.test.ts +0 -16
- package/pkg/commands/strlen.ts +0 -10
- package/pkg/commands/sunion.test.ts +0 -22
- package/pkg/commands/sunion.ts +0 -10
- package/pkg/commands/sunionstore.test.ts +0 -29
- package/pkg/commands/sunionstore.ts +0 -10
- package/pkg/commands/time.test.ts +0 -11
- package/pkg/commands/time.ts +0 -9
- package/pkg/commands/touch.test.ts +0 -20
- package/pkg/commands/touch.ts +0 -10
- package/pkg/commands/ttl.test.ts +0 -17
- package/pkg/commands/ttl.ts +0 -10
- package/pkg/commands/type.test.ts +0 -72
- package/pkg/commands/type.ts +0 -11
- package/pkg/commands/unlink.test.ts +0 -21
- package/pkg/commands/unlink.ts +0 -10
- package/pkg/commands/zadd.test.ts +0 -177
- package/pkg/commands/zadd.ts +0 -64
- package/pkg/commands/zcard.test.ts +0 -15
- package/pkg/commands/zcard.ts +0 -10
- package/pkg/commands/zcount.test.ts +0 -15
- package/pkg/commands/zcount.ts +0 -9
- package/pkg/commands/zincrby.test.ts +0 -20
- package/pkg/commands/zincrby.ts +0 -9
- package/pkg/commands/zinterstore.test.ts +0 -239
- package/pkg/commands/zinterstore.ts +0 -55
- package/pkg/commands/zlexcount.test.ts +0 -22
- package/pkg/commands/zlexcount.ts +0 -9
- package/pkg/commands/zpopmax.test.ts +0 -45
- package/pkg/commands/zpopmax.ts +0 -13
- package/pkg/commands/zpopmin.test.ts +0 -49
- package/pkg/commands/zpopmin.ts +0 -13
- package/pkg/commands/zrange.test.ts +0 -52
- package/pkg/commands/zrange.ts +0 -22
- package/pkg/commands/zrank.test.ts +0 -22
- package/pkg/commands/zrank.ts +0 -10
- package/pkg/commands/zrem.test.ts +0 -20
- package/pkg/commands/zrem.ts +0 -10
- package/pkg/commands/zremrangebylex.test.ts +0 -26
- package/pkg/commands/zremrangebylex.ts +0 -9
- package/pkg/commands/zremrangebyrank.test.ts +0 -27
- package/pkg/commands/zremrangebyrank.ts +0 -9
- package/pkg/commands/zremrangebyscore.test.ts +0 -24
- package/pkg/commands/zremrangebyscore.ts +0 -9
- package/pkg/commands/zrevrank.test.ts +0 -22
- package/pkg/commands/zrevrank.ts +0 -10
- package/pkg/commands/zscan.test.ts +0 -50
- package/pkg/commands/zscan.ts +0 -22
- package/pkg/commands/zscore.test.ts +0 -18
- package/pkg/commands/zscore.ts +0 -10
- package/pkg/commands/zunionstore.test.ts +0 -215
- package/pkg/commands/zunionstore.ts +0 -55
- package/pkg/commands/zz.ts +0 -1
- package/pkg/error.ts +0 -9
- package/pkg/fastly.ts +0 -54
- package/pkg/http.test.ts +0 -34
- package/pkg/http.ts +0 -62
- package/pkg/index.ts +0 -2
- package/pkg/nodejs.ts +0 -83
- package/pkg/pipeline.test.ts +0 -177
- package/pkg/pipeline.ts +0 -999
- package/pkg/redis.ts +0 -930
- package/pkg/test-utils.ts +0 -41
- package/pkg/types.ts +0 -4
- package/pkg/util.ts +0 -22
- package/pnpm-lock.yaml +0 -3940
- package/tsconfig.json +0 -100
- package/tsconfig.module.json +0 -8
- package/tsup.config.ts +0 -16
package/pkg/commands/rpushx.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NonEmptyArray } from "../types"
|
|
2
|
-
import { Command } from "../command"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @see https://redis.io/commands/rpushx
|
|
6
|
-
*/
|
|
7
|
-
export class RPushXCommand<TData = string> extends Command<number, number> {
|
|
8
|
-
constructor(key: string, ...elements: NonEmptyArray<TData>) {
|
|
9
|
-
super(["rpushx", key, ...elements])
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
const client = newHttpClient()
|
|
6
|
-
|
|
7
|
-
const { newKey, cleanup } = keygen()
|
|
8
|
-
afterAll(cleanup)
|
|
9
|
-
|
|
10
|
-
it("returns the number of added members", async () => {
|
|
11
|
-
const key = newKey()
|
|
12
|
-
const value1 = randomUUID()
|
|
13
|
-
const value2 = randomUUID()
|
|
14
|
-
const res = await new SAddCommand(key, value1, value2).exec(client)
|
|
15
|
-
expect(res).toBe(2)
|
|
16
|
-
})
|
package/pkg/commands/sadd.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NonEmptyArray } from "../types"
|
|
2
|
-
import { Command } from "../command"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @see https://redis.io/commands/sadd
|
|
6
|
-
*/
|
|
7
|
-
export class SAddCommand<TData = string> extends Command<number, number> {
|
|
8
|
-
constructor(key: string, ...members: NonEmptyArray<TData>) {
|
|
9
|
-
super(["sadd", key, ...members])
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, describe, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SetCommand } from "./set"
|
|
5
|
-
import { ScanCommand } from "./scan"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
describe("without options", () => {
|
|
11
|
-
it("returns cursor and keys", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const value = randomUUID()
|
|
14
|
-
await new SetCommand(key, value).exec(client)
|
|
15
|
-
const res = await new ScanCommand(0).exec(client)
|
|
16
|
-
|
|
17
|
-
expect(res).toBeDefined()
|
|
18
|
-
expect(res.length).toBe(2)
|
|
19
|
-
expect(typeof res[0]).toBe("number")
|
|
20
|
-
expect(res![1].length).toBeGreaterThan(0)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe("with match", () => {
|
|
25
|
-
it("returns cursor and keys", async () => {
|
|
26
|
-
const key = newKey()
|
|
27
|
-
const value = randomUUID()
|
|
28
|
-
await new SetCommand(key, value).exec(client)
|
|
29
|
-
const res = await new ScanCommand(0, { match: key }).exec(client)
|
|
30
|
-
|
|
31
|
-
expect(res).toBeDefined()
|
|
32
|
-
expect(res.length).toBe(2)
|
|
33
|
-
expect(typeof res[0]).toBe("number")
|
|
34
|
-
expect(res![1].length).toBeGreaterThan(0)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe("with count", () => {
|
|
39
|
-
it("returns cursor and keys", async () => {
|
|
40
|
-
const key = newKey()
|
|
41
|
-
const value = randomUUID()
|
|
42
|
-
await new SetCommand(key, value).exec(client)
|
|
43
|
-
const res = await new ScanCommand(0, { count: 1 }).exec(client)
|
|
44
|
-
|
|
45
|
-
expect(res).toBeDefined()
|
|
46
|
-
expect(res.length).toBe(2)
|
|
47
|
-
expect(typeof res[0]).toBe("number")
|
|
48
|
-
expect(res![1].length).toBeGreaterThan(0)
|
|
49
|
-
})
|
|
50
|
-
})
|
package/pkg/commands/scan.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
export type ScanCommandOptions = {
|
|
4
|
-
match?: string
|
|
5
|
-
count?: number
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @see https://redis.io/commands/scan
|
|
9
|
-
*/
|
|
10
|
-
export class ScanCommand extends Command<[number, string[]], [number, string[]]> {
|
|
11
|
-
constructor(cursor: number, opts?: ScanCommandOptions) {
|
|
12
|
-
const command = ["scan", cursor]
|
|
13
|
-
if (opts?.match) {
|
|
14
|
-
command.push("match", opts.match)
|
|
15
|
-
}
|
|
16
|
-
if (typeof opts?.count === "number") {
|
|
17
|
-
command.push("count", opts.count)
|
|
18
|
-
}
|
|
19
|
-
super(command)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
-
import { SAddCommand } from "./sadd"
|
|
4
|
-
import { SCardCommand } from "./scard"
|
|
5
|
-
const client = newHttpClient()
|
|
6
|
-
|
|
7
|
-
const { newKey, cleanup } = keygen()
|
|
8
|
-
afterAll(cleanup)
|
|
9
|
-
|
|
10
|
-
it("returns the cardinality", async () => {
|
|
11
|
-
const key = newKey()
|
|
12
|
-
await new SAddCommand(key, "member1").exec(client)
|
|
13
|
-
const res = await new SCardCommand(key).exec(client)
|
|
14
|
-
expect(res).toBe(1)
|
|
15
|
-
})
|
package/pkg/commands/scard.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
import { SDiffCommand } from "./sdiff"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns the diff", async () => {
|
|
12
|
-
const key1 = newKey()
|
|
13
|
-
const member1 = randomUUID()
|
|
14
|
-
const key2 = newKey()
|
|
15
|
-
const member2 = randomUUID()
|
|
16
|
-
await new SAddCommand(key1, member1).exec(client)
|
|
17
|
-
await new SAddCommand(key2, member2).exec(client)
|
|
18
|
-
const res = await new SDiffCommand(key1, key2).exec(client)
|
|
19
|
-
expect(res).toEqual([member1])
|
|
20
|
-
})
|
package/pkg/commands/sdiff.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
import { SDiffStoreCommand } from "./sdiffstore"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns the diff", async () => {
|
|
12
|
-
const key1 = newKey()
|
|
13
|
-
const member1 = randomUUID()
|
|
14
|
-
const key2 = newKey()
|
|
15
|
-
const member2 = randomUUID()
|
|
16
|
-
const destination = newKey()
|
|
17
|
-
await new SAddCommand(key1, member1).exec(client)
|
|
18
|
-
await new SAddCommand(key2, member2).exec(client)
|
|
19
|
-
const res = await new SDiffStoreCommand(destination, key1, key2).exec(client)
|
|
20
|
-
expect(res).toEqual(1)
|
|
21
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { NonEmptyArray } from "../types"
|
|
2
|
-
import { Command } from "../command"
|
|
3
|
-
/**
|
|
4
|
-
* @see https://redis.io/commands/sdiffstpre
|
|
5
|
-
*/
|
|
6
|
-
export class SDiffStoreCommand extends Command<number, number> {
|
|
7
|
-
constructor(destination: string, ...keys: NonEmptyArray<string>) {
|
|
8
|
-
super(["sdiffstore", destination, ...keys])
|
|
9
|
-
}
|
|
10
|
-
}
|
package/pkg/commands/set.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { GetCommand } from "./get"
|
|
5
|
-
import { SetCommand } from "./set"
|
|
6
|
-
|
|
7
|
-
const client = newHttpClient()
|
|
8
|
-
|
|
9
|
-
const { newKey, cleanup } = keygen()
|
|
10
|
-
afterAll(cleanup)
|
|
11
|
-
describe("without options", () => {
|
|
12
|
-
it("sets value", async () => {
|
|
13
|
-
const key = newKey()
|
|
14
|
-
const value = randomUUID()
|
|
15
|
-
|
|
16
|
-
const res = await new SetCommand(key, value).exec(client)
|
|
17
|
-
expect(res).toEqual("OK")
|
|
18
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
19
|
-
expect(res2).toEqual(value)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
describe("ex", () => {
|
|
23
|
-
it("sets value", async () => {
|
|
24
|
-
const key = newKey()
|
|
25
|
-
const value = randomUUID()
|
|
26
|
-
|
|
27
|
-
const res = await new SetCommand(key, value, { ex: 1 }).exec(client)
|
|
28
|
-
expect(res).toEqual("OK")
|
|
29
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
30
|
-
expect(res2).toEqual(value)
|
|
31
|
-
await new Promise((res) => setTimeout(res, 2000))
|
|
32
|
-
|
|
33
|
-
const res3 = await new GetCommand(key).exec(client)
|
|
34
|
-
expect(res3).toEqual(null)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
describe("px", () => {
|
|
38
|
-
it("sets value", async () => {
|
|
39
|
-
const key = newKey()
|
|
40
|
-
const value = randomUUID()
|
|
41
|
-
|
|
42
|
-
const res = await new SetCommand(key, value, { px: 1000 }).exec(client)
|
|
43
|
-
expect(res).toEqual("OK")
|
|
44
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
45
|
-
expect(res2).toEqual(value)
|
|
46
|
-
await new Promise((res) => setTimeout(res, 2000))
|
|
47
|
-
|
|
48
|
-
const res3 = await new GetCommand(key).exec(client)
|
|
49
|
-
|
|
50
|
-
expect(res3).toBeNull()
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
describe("nx", () => {
|
|
54
|
-
describe("when key exists", () => {
|
|
55
|
-
it("does nothing", async () => {
|
|
56
|
-
const key = newKey()
|
|
57
|
-
const value = randomUUID()
|
|
58
|
-
const newValue = randomUUID()
|
|
59
|
-
|
|
60
|
-
await new SetCommand(key, value).exec(client)
|
|
61
|
-
const res = await new SetCommand(key, newValue, {
|
|
62
|
-
nx: true,
|
|
63
|
-
}).exec(client)
|
|
64
|
-
expect(res).toBeNull()
|
|
65
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
66
|
-
expect(res2).toEqual(value)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
describe("when key does not exists", () => {
|
|
70
|
-
it("overwrites key", async () => {
|
|
71
|
-
const key = newKey()
|
|
72
|
-
const value = randomUUID()
|
|
73
|
-
|
|
74
|
-
const res = await new SetCommand(key, value, {
|
|
75
|
-
nx: true,
|
|
76
|
-
}).exec(client)
|
|
77
|
-
expect(res).toEqual("OK")
|
|
78
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
79
|
-
expect(res2).toEqual(value)
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
describe("xx", () => {
|
|
84
|
-
describe("when key exists", () => {
|
|
85
|
-
it("overwrites key", async () => {
|
|
86
|
-
const key = newKey()
|
|
87
|
-
const value = randomUUID()
|
|
88
|
-
const newValue = randomUUID()
|
|
89
|
-
|
|
90
|
-
await new SetCommand(key, value).exec(client)
|
|
91
|
-
const res = await new SetCommand(key, newValue, {
|
|
92
|
-
xx: true,
|
|
93
|
-
}).exec(client)
|
|
94
|
-
expect(res).toEqual("OK")
|
|
95
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
96
|
-
expect(res2).toEqual(newValue)
|
|
97
|
-
})
|
|
98
|
-
})
|
|
99
|
-
describe("when key does not exists", () => {
|
|
100
|
-
it("does nothing", async () => {
|
|
101
|
-
const key = newKey()
|
|
102
|
-
const value = randomUUID()
|
|
103
|
-
|
|
104
|
-
const res = await new SetCommand(key, value, {
|
|
105
|
-
xx: true,
|
|
106
|
-
}).exec(client)
|
|
107
|
-
expect(res).toBeNull()
|
|
108
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
109
|
-
expect(res2).toBeNull()
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
})
|
package/pkg/commands/set.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
export type SetCommandOptions = (
|
|
4
|
-
| {
|
|
5
|
-
ex: number
|
|
6
|
-
px?: never
|
|
7
|
-
}
|
|
8
|
-
| {
|
|
9
|
-
ex?: never
|
|
10
|
-
px: number
|
|
11
|
-
}
|
|
12
|
-
| {
|
|
13
|
-
ex?: never
|
|
14
|
-
px?: never
|
|
15
|
-
}
|
|
16
|
-
) &
|
|
17
|
-
(
|
|
18
|
-
| {
|
|
19
|
-
nx: true
|
|
20
|
-
xx?: never
|
|
21
|
-
}
|
|
22
|
-
| {
|
|
23
|
-
xx: true
|
|
24
|
-
nx?: never
|
|
25
|
-
}
|
|
26
|
-
| {
|
|
27
|
-
xx?: never
|
|
28
|
-
nx?: never
|
|
29
|
-
}
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @see https://redis.io/commands/set
|
|
34
|
-
*/
|
|
35
|
-
export class SetCommand<TData, TResult = "OK"> extends Command<TData, TResult> {
|
|
36
|
-
constructor(key: string, value: TData, opts?: SetCommandOptions) {
|
|
37
|
-
const command: unknown[] = ["set", key, value]
|
|
38
|
-
if (opts) {
|
|
39
|
-
if ("ex" in opts && typeof opts.ex === "number") {
|
|
40
|
-
command.push("ex", opts.ex)
|
|
41
|
-
} else if ("px" in opts && typeof opts.px === "number") {
|
|
42
|
-
command.push("px", opts.px)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ("nx" in opts && opts.nx) {
|
|
46
|
-
command.push("nx")
|
|
47
|
-
} else if ("xx" in opts && opts.xx) {
|
|
48
|
-
command.push("xx")
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
super(command)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { SetBitCommand } from "./setbit"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
const client = newHttpClient()
|
|
5
|
-
|
|
6
|
-
const { newKey, cleanup } = keygen()
|
|
7
|
-
afterAll(cleanup)
|
|
8
|
-
|
|
9
|
-
it("returns the original bit", async () => {
|
|
10
|
-
const key = newKey()
|
|
11
|
-
const res = await new SetBitCommand(key, 0, 1).exec(client)
|
|
12
|
-
expect(res).toBe(0)
|
|
13
|
-
const res2 = await new SetBitCommand(key, 0, 1).exec(client)
|
|
14
|
-
|
|
15
|
-
expect(res2).toBe(1)
|
|
16
|
-
})
|
package/pkg/commands/setbit.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/setbit
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export class SetBitCommand extends Command<0 | 1, "0" | "1"> {
|
|
7
|
-
constructor(key: string, offset: number, value: 0 | 1) {
|
|
8
|
-
super(["setbit", key, offset, value])
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SetExCommand } from "./setex"
|
|
5
|
-
import { GetCommand } from "./get"
|
|
6
|
-
|
|
7
|
-
const client = newHttpClient()
|
|
8
|
-
|
|
9
|
-
const { newKey, cleanup } = keygen()
|
|
10
|
-
afterAll(cleanup)
|
|
11
|
-
it("sets value", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const value = randomUUID()
|
|
14
|
-
|
|
15
|
-
const res = await new SetExCommand(key, 1, value).exec(client)
|
|
16
|
-
|
|
17
|
-
expect(res).toEqual("OK")
|
|
18
|
-
await new Promise((res) => setTimeout(res, 2000))
|
|
19
|
-
const res2 = await new GetCommand(key).exec(client)
|
|
20
|
-
|
|
21
|
-
expect(res2).toBeNull()
|
|
22
|
-
})
|
package/pkg/commands/setex.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @see https://redis.io/commands/setex
|
|
5
|
-
*/
|
|
6
|
-
export class SetExCommand<TData = string> extends Command<"OK", "OK"> {
|
|
7
|
-
constructor(key: string, ttl: number, value: TData) {
|
|
8
|
-
super(["setex", key, ttl, value])
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
import { SetNxCommand } from "./setnx"
|
|
7
|
-
|
|
8
|
-
const client = newHttpClient()
|
|
9
|
-
|
|
10
|
-
const { newKey, cleanup } = keygen()
|
|
11
|
-
afterAll(cleanup)
|
|
12
|
-
|
|
13
|
-
it("sets value", async () => {
|
|
14
|
-
const key = newKey()
|
|
15
|
-
const value = randomUUID()
|
|
16
|
-
const newValue = randomUUID()
|
|
17
|
-
|
|
18
|
-
const res = await new SetCommand(key, value).exec(client)
|
|
19
|
-
|
|
20
|
-
expect(res).toEqual("OK")
|
|
21
|
-
const res2 = await new SetNxCommand(key, newValue).exec(client)
|
|
22
|
-
|
|
23
|
-
expect(res2).toEqual(0)
|
|
24
|
-
const res3 = await new GetCommand(key).exec(client)
|
|
25
|
-
|
|
26
|
-
expect(res3).toEqual(value)
|
|
27
|
-
})
|
package/pkg/commands/setnx.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
-
import { SetCommand } from "./set"
|
|
4
|
-
import { SetRangeCommand } from "./setrange"
|
|
5
|
-
import { GetCommand } from "./get"
|
|
6
|
-
|
|
7
|
-
const client = newHttpClient()
|
|
8
|
-
|
|
9
|
-
const { newKey, cleanup } = keygen()
|
|
10
|
-
afterAll(cleanup)
|
|
11
|
-
|
|
12
|
-
it("sets value", async () => {
|
|
13
|
-
const key = newKey()
|
|
14
|
-
const value = "originalValue"
|
|
15
|
-
|
|
16
|
-
const res = await new SetCommand(key, value).exec(client)
|
|
17
|
-
|
|
18
|
-
expect(res).toEqual("OK")
|
|
19
|
-
const res2 = await new SetRangeCommand(key, 4, "helloWorld").exec(client)
|
|
20
|
-
|
|
21
|
-
expect(res2).toEqual(14)
|
|
22
|
-
const res3 = await new GetCommand(key).exec(client)
|
|
23
|
-
|
|
24
|
-
expect(res3).toEqual("orighelloWorld")
|
|
25
|
-
})
|
package/pkg/commands/setrange.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @see https://redis.io/commands/setrange
|
|
5
|
-
*/
|
|
6
|
-
export class SetRangeCommand extends Command<number, number> {
|
|
7
|
-
constructor(key: string, offset: number, value: string) {
|
|
8
|
-
super(["setrange", key, offset, value])
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
import { SInterCommand } from "./sinter"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
describe("with single set", () => {
|
|
12
|
-
it("returns the members of the set", async () => {
|
|
13
|
-
const key = newKey()
|
|
14
|
-
const value1 = { v: randomUUID() }
|
|
15
|
-
const value2 = { v: randomUUID() }
|
|
16
|
-
await new SAddCommand(key, value1, value2).exec(client)
|
|
17
|
-
const res = await new SInterCommand<{ v: string }>(key).exec(client)
|
|
18
|
-
expect(res).toHaveLength(2)
|
|
19
|
-
expect(res.map(({ v }) => v).includes(value1.v)).toBe(true)
|
|
20
|
-
expect(res.map(({ v }) => v).includes(value2.v)).toBe(true)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe("with multiple sets", () => {
|
|
25
|
-
it("returns the members of the set", async () => {
|
|
26
|
-
const key1 = newKey()
|
|
27
|
-
const key2 = newKey()
|
|
28
|
-
const value1 = { v: randomUUID() }
|
|
29
|
-
const value2 = { v: randomUUID() }
|
|
30
|
-
const value3 = { v: randomUUID() }
|
|
31
|
-
await new SAddCommand(key1, value1, value2).exec(client)
|
|
32
|
-
await new SAddCommand(key2, value2, value3).exec(client)
|
|
33
|
-
const res = await new SInterCommand(key1, key2).exec(client)
|
|
34
|
-
expect(res).toEqual([value2])
|
|
35
|
-
})
|
|
36
|
-
})
|
package/pkg/commands/sinter.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
import { SInterStoreCommand } from "./sinterstore"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("stores the intersection", async () => {
|
|
12
|
-
const key1 = newKey()
|
|
13
|
-
const member1 = randomUUID()
|
|
14
|
-
const key2 = newKey()
|
|
15
|
-
const member2 = member1
|
|
16
|
-
const destination = newKey()
|
|
17
|
-
await new SAddCommand(key1, member1).exec(client)
|
|
18
|
-
await new SAddCommand(key2, member2).exec(client)
|
|
19
|
-
const res = await new SInterStoreCommand(destination, key1, key2).exec(client)
|
|
20
|
-
expect(res).toEqual(1)
|
|
21
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/sinterstore
|
|
4
|
-
*/
|
|
5
|
-
export class SInterStoreCommand<TData = string> extends Command<TData[], unknown[]> {
|
|
6
|
-
constructor(destination: string, key: string, ...keys: string[]) {
|
|
7
|
-
super(["sinterstore", destination, key, ...keys])
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { SAddCommand } from "./sadd"
|
|
4
|
-
import { SIsMemberCommand } from "./sismember"
|
|
5
|
-
import { describe, it, expect, afterAll } from "@jest/globals"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
describe("when member exists", () => {
|
|
12
|
-
it("returns 1", async () => {
|
|
13
|
-
const key = newKey()
|
|
14
|
-
const value = randomUUID()
|
|
15
|
-
await new SAddCommand(key, value).exec(client)
|
|
16
|
-
const res = await new SIsMemberCommand(key, value).exec(client)
|
|
17
|
-
expect(res).toBe(1)
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe("when member exists", () => {
|
|
22
|
-
it("returns 1", async () => {
|
|
23
|
-
const key = newKey()
|
|
24
|
-
const value1 = randomUUID()
|
|
25
|
-
const value2 = randomUUID()
|
|
26
|
-
await new SAddCommand(key, value1).exec(client)
|
|
27
|
-
const res = await new SIsMemberCommand(key, value2).exec(client)
|
|
28
|
-
expect(res).toBe(0)
|
|
29
|
-
})
|
|
30
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/sismember
|
|
4
|
-
*/
|
|
5
|
-
export class SIsMemberCommand<TData = string> extends Command<0 | 1, "0" | "1"> {
|
|
6
|
-
constructor(key: string, member: TData) {
|
|
7
|
-
super(["sismember", key, member])
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { SAddCommand } from "./sadd"
|
|
5
|
-
import { SMembersCommand } from "./smembers"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns all members of the set", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const value1 = { v: randomUUID() }
|
|
14
|
-
const value2 = { v: randomUUID() }
|
|
15
|
-
|
|
16
|
-
await new SAddCommand(key, value1, value2).exec(client)
|
|
17
|
-
const res = await new SMembersCommand<{ v: string }>(key).exec(client)
|
|
18
|
-
expect(res).toBeDefined()
|
|
19
|
-
expect(res!.length).toBe(2)
|
|
20
|
-
expect(res!.map(({ v }) => v).includes(value1.v)).toBe(true)
|
|
21
|
-
expect(res!.map(({ v }) => v).includes(value2.v)).toBe(true)
|
|
22
|
-
})
|
package/pkg/commands/smembers.ts
DELETED