@upstash/redis 1.0.0-alpha.2 → 1.0.0-alpha.3
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/{dist/chunk-7YUZYRJS.mjs → chunk-7YUZYRJS.mjs} +0 -0
- package/{dist/chunk-FJSI5EBJ.mjs → chunk-FJSI5EBJ.mjs} +0 -0
- package/{dist/chunk-U7OXAQMQ.mjs → chunk-U7OXAQMQ.mjs} +0 -0
- package/{dist/chunk-Y5TC4HX2.mjs → chunk-Y5TC4HX2.mjs} +0 -0
- package/{dist/chunk-ZIB6XPPC.mjs → chunk-ZIB6XPPC.mjs} +0 -0
- package/{dist/cloudflare.d.ts → cloudflare.d.ts} +0 -0
- package/{dist/cloudflare.js → cloudflare.js} +0 -0
- package/{dist/cloudflare.mjs → cloudflare.mjs} +0 -0
- package/{dist/commands.d.ts → commands.d.ts} +0 -0
- package/{dist/commands.js → commands.js} +0 -0
- package/{dist/commands.mjs → commands.mjs} +0 -0
- package/{dist/fastly.d.ts → fastly.d.ts} +0 -0
- package/{dist/fastly.js → fastly.js} +0 -0
- package/{dist/fastly.mjs → fastly.mjs} +0 -0
- package/{dist/http.d.ts → http.d.ts} +0 -0
- package/{dist/http.js → http.js} +0 -0
- package/{dist/http.mjs → http.mjs} +0 -0
- package/{dist/index.d.ts → index.d.ts} +0 -0
- package/{dist/index.js → index.js} +0 -0
- package/{dist/index.mjs → index.mjs} +0 -0
- package/{dist/nodejs.d.ts → nodejs.d.ts} +0 -0
- package/{dist/nodejs.js → nodejs.js} +0 -0
- package/{dist/nodejs.mjs → nodejs.mjs} +0 -0
- package/package.json +1 -1
- package/{dist/redis-dd052782.d.ts → redis-dd052782.d.ts} +0 -0
- package/{dist/zunionstore-dffa797d.d.ts → zunionstore-dffa797d.d.ts} +0 -0
- package/.eslintrc.js +0 -49
- package/.prettierrc.js +0 -7
- package/LICENSE +0 -21
- 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
|
@@ -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 { ZAddCommand } from "./zadd"
|
|
5
|
-
import { ZRemRangeByRankCommand } from "./zremrangebyrank"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns the number of removed elements", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const score1 = 1
|
|
14
|
-
const member1 = randomUUID()
|
|
15
|
-
const score2 = 2
|
|
16
|
-
const member2 = randomUUID()
|
|
17
|
-
const score3 = 3
|
|
18
|
-
const member3 = randomUUID()
|
|
19
|
-
await new ZAddCommand(
|
|
20
|
-
key,
|
|
21
|
-
{ score: score1, member: member1 },
|
|
22
|
-
{ score: score2, member: member2 },
|
|
23
|
-
{ score: score3, member: member3 },
|
|
24
|
-
).exec(client)
|
|
25
|
-
const res = await new ZRemRangeByRankCommand(key, 1, 2).exec(client)
|
|
26
|
-
expect(res).toBe(2)
|
|
27
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/zremrangebyrank
|
|
4
|
-
*/
|
|
5
|
-
export class ZRemRangeByRankCommand extends Command<number, number> {
|
|
6
|
-
constructor(key: string, start: number, stop: number) {
|
|
7
|
-
super(["zremrangebyrank", key, start, stop])
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import { ZAddCommand } from "./zadd"
|
|
4
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
5
|
-
import { ZRemRangeByScoreCommand } from "./zremrangebyscore"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns the number of removed elements", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const member1 = randomUUID()
|
|
14
|
-
const member2 = randomUUID()
|
|
15
|
-
const member3 = randomUUID()
|
|
16
|
-
await new ZAddCommand(
|
|
17
|
-
key,
|
|
18
|
-
{ score: 1, member: member1 },
|
|
19
|
-
{ score: 2, member: member2 },
|
|
20
|
-
{ score: 3, member: member3 },
|
|
21
|
-
).exec(client)
|
|
22
|
-
const res = await new ZRemRangeByScoreCommand(key, 1, 2).exec(client)
|
|
23
|
-
expect(res).toBe(2)
|
|
24
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/zremrangebyscore
|
|
4
|
-
*/
|
|
5
|
-
export class ZRemRangeByScoreCommand extends Command<number, number> {
|
|
6
|
-
constructor(key: string, min: number, max: number) {
|
|
7
|
-
super(["zremrangebyscore", key, min, max])
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
3
|
-
import { ZAddCommand } from "./zadd"
|
|
4
|
-
import { ZRevRankCommand } from "./zrevrank"
|
|
5
|
-
const client = newHttpClient()
|
|
6
|
-
|
|
7
|
-
const { newKey, cleanup } = keygen()
|
|
8
|
-
afterAll(cleanup)
|
|
9
|
-
|
|
10
|
-
it("returns the rank", async () => {
|
|
11
|
-
const key = newKey()
|
|
12
|
-
|
|
13
|
-
await new ZAddCommand(
|
|
14
|
-
key,
|
|
15
|
-
{ score: 1, member: "member1" },
|
|
16
|
-
{ score: 2, member: "member2" },
|
|
17
|
-
{ score: 3, member: "member3" },
|
|
18
|
-
).exec(client)
|
|
19
|
-
|
|
20
|
-
const res = await new ZRevRankCommand(key, "member2").exec(client)
|
|
21
|
-
expect(res).toBe(1)
|
|
22
|
-
})
|
package/pkg/commands/zrevrank.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
/**
|
|
3
|
-
* @see https://redis.io/commands/zrevrank
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export class ZRevRankCommand<TData> extends Command<number | null, number | null> {
|
|
7
|
-
constructor(key: string, member: TData) {
|
|
8
|
-
super(["zrevrank", key, member])
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -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 { ZAddCommand } from "./zadd"
|
|
5
|
-
import { ZScanCommand } from "./zscan"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
describe("without options", () => {
|
|
11
|
-
it("returns cursor and members", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const value = randomUUID()
|
|
14
|
-
await new ZAddCommand(key, { score: 0, member: value }).exec(client)
|
|
15
|
-
const res = await new ZScanCommand(key, 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 members", async () => {
|
|
26
|
-
const key = newKey()
|
|
27
|
-
const value = randomUUID()
|
|
28
|
-
await new ZAddCommand(key, { score: 0, member: value }).exec(client)
|
|
29
|
-
const res = await new ZScanCommand(key, 0, { match: value }).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 members", async () => {
|
|
40
|
-
const key = newKey()
|
|
41
|
-
const value = randomUUID()
|
|
42
|
-
await new ZAddCommand(key, { score: 0, member: value }).exec(client)
|
|
43
|
-
const res = await new ZScanCommand(key, 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/zscan.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ScanCommandOptions } from "./scan"
|
|
2
|
-
import { Command } from "../command"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @see https://redis.io/commands/zscan
|
|
6
|
-
*/
|
|
7
|
-
export class ZScanCommand extends Command<
|
|
8
|
-
[number, (string | number)[]],
|
|
9
|
-
[number, (string | number)[]]
|
|
10
|
-
> {
|
|
11
|
-
constructor(key: string, cursor: number, opts?: ScanCommandOptions) {
|
|
12
|
-
const command = ["zscan", key, 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
|
-
|
|
20
|
-
super(command)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { keygen, newHttpClient } from "../test-utils"
|
|
2
|
-
import { randomInt, randomUUID } from "crypto"
|
|
3
|
-
import { it, expect, afterAll } from "@jest/globals"
|
|
4
|
-
import { ZAddCommand } from "./zadd"
|
|
5
|
-
import { ZScoreCommand } from "./zscore"
|
|
6
|
-
const client = newHttpClient()
|
|
7
|
-
|
|
8
|
-
const { newKey, cleanup } = keygen()
|
|
9
|
-
afterAll(cleanup)
|
|
10
|
-
|
|
11
|
-
it("returns the score", async () => {
|
|
12
|
-
const key = newKey()
|
|
13
|
-
const member = randomUUID()
|
|
14
|
-
const score = randomInt(10)
|
|
15
|
-
await new ZAddCommand(key, { score, member }).exec(client)
|
|
16
|
-
const res = await new ZScoreCommand(key, member).exec(client)
|
|
17
|
-
expect(res).toBe(score)
|
|
18
|
-
})
|
package/pkg/commands/zscore.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @see https://redis.io/commands/zscore
|
|
5
|
-
*/
|
|
6
|
-
export class ZScoreCommand<TData> extends Command<number | null, string | null> {
|
|
7
|
-
constructor(key: string, member: TData) {
|
|
8
|
-
super(["zscore", key, member])
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,215 +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 { ZUnionStoreCommand } from "./zunionstore"
|
|
5
|
-
import { ZAddCommand } from "./zadd"
|
|
6
|
-
|
|
7
|
-
const client = newHttpClient()
|
|
8
|
-
|
|
9
|
-
const { newKey, cleanup } = keygen()
|
|
10
|
-
afterAll(cleanup)
|
|
11
|
-
|
|
12
|
-
describe("command format", () => {
|
|
13
|
-
describe("without options", () => {
|
|
14
|
-
it("builds the correct command", () => {
|
|
15
|
-
expect(new ZUnionStoreCommand("destination", 1, "key").command).toEqual([
|
|
16
|
-
"zunionstore",
|
|
17
|
-
"destination",
|
|
18
|
-
"1",
|
|
19
|
-
"key",
|
|
20
|
-
])
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
describe("with multiple keys", () => {
|
|
24
|
-
it("builds the correct command", () => {
|
|
25
|
-
expect(new ZUnionStoreCommand("destination", 2, ["key1", "key2"]).command).toEqual([
|
|
26
|
-
"zunionstore",
|
|
27
|
-
"destination",
|
|
28
|
-
"2",
|
|
29
|
-
"key1",
|
|
30
|
-
"key2",
|
|
31
|
-
])
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
describe("with single weight", () => {
|
|
35
|
-
it("builds the correct command", () => {
|
|
36
|
-
expect(new ZUnionStoreCommand("destination", 1, "key", { weight: 4 }).command).toEqual([
|
|
37
|
-
"zunionstore",
|
|
38
|
-
"destination",
|
|
39
|
-
"1",
|
|
40
|
-
"key",
|
|
41
|
-
"weights",
|
|
42
|
-
"4",
|
|
43
|
-
])
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
describe("with multiple weights", () => {
|
|
47
|
-
it("builds the correct command", () => {
|
|
48
|
-
expect(
|
|
49
|
-
new ZUnionStoreCommand("destination", 2, ["key1", "key2"], { weights: [2, 3] }).command,
|
|
50
|
-
).toEqual(["zunionstore", "destination", "2", "key1", "key2", "weights", "2", "3"])
|
|
51
|
-
})
|
|
52
|
-
describe("with aggregate", () => {
|
|
53
|
-
describe("sum", () => {
|
|
54
|
-
it("builds the correct command", () => {
|
|
55
|
-
expect(
|
|
56
|
-
new ZUnionStoreCommand("destination", 1, "key", { aggregate: "sum" }).command,
|
|
57
|
-
).toEqual(["zunionstore", "destination", "1", "key", "aggregate", "sum"])
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
describe("min", () => {
|
|
61
|
-
it("builds the correct command", () => {
|
|
62
|
-
expect(
|
|
63
|
-
new ZUnionStoreCommand("destination", 1, "key", { aggregate: "min" }).command,
|
|
64
|
-
).toEqual(["zunionstore", "destination", "1", "key", "aggregate", "min"])
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
describe("max", () => {
|
|
68
|
-
it("builds the correct command", () => {
|
|
69
|
-
expect(
|
|
70
|
-
new ZUnionStoreCommand("destination", 1, "key", { aggregate: "max" }).command,
|
|
71
|
-
).toEqual(["zunionstore", "destination", "1", "key", "aggregate", "max"])
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
describe("complex", () => {
|
|
76
|
-
it("builds the correct command", () => {
|
|
77
|
-
expect(
|
|
78
|
-
new ZUnionStoreCommand("destination", 2, ["key1", "key2"], {
|
|
79
|
-
weights: [4, 2],
|
|
80
|
-
aggregate: "max",
|
|
81
|
-
}).command,
|
|
82
|
-
).toEqual([
|
|
83
|
-
"zunionstore",
|
|
84
|
-
"destination",
|
|
85
|
-
"2",
|
|
86
|
-
"key1",
|
|
87
|
-
"key2",
|
|
88
|
-
"weights",
|
|
89
|
-
"4",
|
|
90
|
-
"2",
|
|
91
|
-
"aggregate",
|
|
92
|
-
"max",
|
|
93
|
-
])
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
describe("without options", () => {
|
|
100
|
-
it("returns the number of elements in the new set ", async () => {
|
|
101
|
-
const destination = newKey()
|
|
102
|
-
const key1 = newKey()
|
|
103
|
-
const key2 = newKey()
|
|
104
|
-
const score1 = 1
|
|
105
|
-
const member1 = randomUUID()
|
|
106
|
-
const score2 = 2
|
|
107
|
-
const member2 = randomUUID()
|
|
108
|
-
|
|
109
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
110
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
111
|
-
|
|
112
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2]).exec(client)
|
|
113
|
-
expect(res).toBe(2)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
describe("with weights", () => {
|
|
118
|
-
describe("single weight", () => {
|
|
119
|
-
it("returns the number of elements in the new set ", async () => {
|
|
120
|
-
const destination = newKey()
|
|
121
|
-
const key1 = newKey()
|
|
122
|
-
const key2 = newKey()
|
|
123
|
-
const score1 = 1
|
|
124
|
-
const member1 = randomUUID()
|
|
125
|
-
const score2 = 2
|
|
126
|
-
const member2 = randomUUID()
|
|
127
|
-
|
|
128
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
129
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
130
|
-
|
|
131
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2], {
|
|
132
|
-
weights: [2, 3],
|
|
133
|
-
}).exec(client)
|
|
134
|
-
expect(res).toBe(2)
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
describe("multiple weight", () => {
|
|
138
|
-
it("returns the number of elements in the new set ", async () => {
|
|
139
|
-
const destination = newKey()
|
|
140
|
-
const key1 = newKey()
|
|
141
|
-
const key2 = newKey()
|
|
142
|
-
const score1 = 1
|
|
143
|
-
const member1 = randomUUID()
|
|
144
|
-
const score2 = 2
|
|
145
|
-
const member2 = randomUUID()
|
|
146
|
-
|
|
147
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
148
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
149
|
-
|
|
150
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2], {
|
|
151
|
-
weights: [1, 2],
|
|
152
|
-
}).exec(client)
|
|
153
|
-
expect(res).toBe(2)
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
describe("aggregate", () => {
|
|
158
|
-
describe("sum", () => {
|
|
159
|
-
it("returns the number of elements in the new set ", async () => {
|
|
160
|
-
const destination = newKey()
|
|
161
|
-
const key1 = newKey()
|
|
162
|
-
const key2 = newKey()
|
|
163
|
-
const score1 = 1
|
|
164
|
-
const member1 = randomUUID()
|
|
165
|
-
const score2 = 2
|
|
166
|
-
const member2 = randomUUID()
|
|
167
|
-
|
|
168
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
169
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
170
|
-
|
|
171
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2], {
|
|
172
|
-
aggregate: "sum",
|
|
173
|
-
}).exec(client)
|
|
174
|
-
expect(res).toBe(2)
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
describe("min", () => {
|
|
178
|
-
it("returns the number of elements in the new set ", async () => {
|
|
179
|
-
const destination = newKey()
|
|
180
|
-
const key1 = newKey()
|
|
181
|
-
const key2 = newKey()
|
|
182
|
-
const score1 = 1
|
|
183
|
-
const member1 = randomUUID()
|
|
184
|
-
const score2 = 2
|
|
185
|
-
const member2 = randomUUID()
|
|
186
|
-
|
|
187
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
188
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
189
|
-
|
|
190
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2], {
|
|
191
|
-
aggregate: "min",
|
|
192
|
-
}).exec(client)
|
|
193
|
-
expect(res).toBe(2)
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
describe("max", () => {
|
|
197
|
-
it("returns the number of elements in the new set ", async () => {
|
|
198
|
-
const destination = newKey()
|
|
199
|
-
const key1 = newKey()
|
|
200
|
-
const key2 = newKey()
|
|
201
|
-
const score1 = 1
|
|
202
|
-
const member1 = randomUUID()
|
|
203
|
-
const score2 = 2
|
|
204
|
-
const member2 = randomUUID()
|
|
205
|
-
|
|
206
|
-
await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
|
|
207
|
-
await new ZAddCommand(key2, { score: score2, member: member2 }).exec(client)
|
|
208
|
-
|
|
209
|
-
const res = await new ZUnionStoreCommand(destination, 2, [key1, key2], {
|
|
210
|
-
aggregate: "max",
|
|
211
|
-
}).exec(client)
|
|
212
|
-
expect(res).toBe(2)
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command"
|
|
2
|
-
|
|
3
|
-
export type ZUnionStoreCommandOptions = {
|
|
4
|
-
aggregate?: "sum" | "min" | "max"
|
|
5
|
-
} & (
|
|
6
|
-
| {
|
|
7
|
-
weight: number
|
|
8
|
-
weights?: never
|
|
9
|
-
}
|
|
10
|
-
| {
|
|
11
|
-
weight?: never
|
|
12
|
-
weights: number[]
|
|
13
|
-
}
|
|
14
|
-
| {
|
|
15
|
-
weight?: never
|
|
16
|
-
weights?: never
|
|
17
|
-
}
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @see https://redis.io/commands/zunionstore
|
|
22
|
-
*/
|
|
23
|
-
export class ZUnionStoreCommand extends Command<number, number> {
|
|
24
|
-
constructor(destination: string, numKeys: 1, key: string, opts?: ZUnionStoreCommandOptions)
|
|
25
|
-
constructor(
|
|
26
|
-
destination: string,
|
|
27
|
-
numKeys: number,
|
|
28
|
-
keys: string[],
|
|
29
|
-
opts?: ZUnionStoreCommandOptions,
|
|
30
|
-
)
|
|
31
|
-
constructor(
|
|
32
|
-
destination: string,
|
|
33
|
-
numKeys: number,
|
|
34
|
-
keyOrKeys: string | string[],
|
|
35
|
-
opts?: ZUnionStoreCommandOptions,
|
|
36
|
-
) {
|
|
37
|
-
const command: unknown[] = ["zunionstore", destination, numKeys]
|
|
38
|
-
if (Array.isArray(keyOrKeys)) {
|
|
39
|
-
command.push(...keyOrKeys)
|
|
40
|
-
} else {
|
|
41
|
-
command.push(keyOrKeys)
|
|
42
|
-
}
|
|
43
|
-
if (opts) {
|
|
44
|
-
if ("weights" in opts && opts.weights) {
|
|
45
|
-
command.push("weights", ...opts.weights)
|
|
46
|
-
} else if ("weight" in opts && typeof opts.weight === "number") {
|
|
47
|
-
command.push("weights", opts.weight)
|
|
48
|
-
}
|
|
49
|
-
if ("aggregate" in opts) {
|
|
50
|
-
command.push("aggregate", opts.aggregate)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
super(command)
|
|
54
|
-
}
|
|
55
|
-
}
|
package/pkg/commands/zz.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const x = 1
|
package/pkg/error.ts
DELETED
package/pkg/fastly.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as core from "./redis"
|
|
2
|
-
import { HttpClient } from "./http"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Connection credentials for upstash redis.
|
|
6
|
-
* Get them from https://console.upstash.com/redis/<uuid>
|
|
7
|
-
*/
|
|
8
|
-
export type RedisConfigFastly = {
|
|
9
|
-
/**
|
|
10
|
-
* UPSTASH_REDIS_REST_URL
|
|
11
|
-
*/
|
|
12
|
-
url: string
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* UPSTASH_REDIS_REST_TOKEN
|
|
16
|
-
*/
|
|
17
|
-
token: string
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A Request can be forwarded to any backend defined on your service. Backends
|
|
21
|
-
* can be created via the Fastly CLI, API, or web interface, and are
|
|
22
|
-
* referenced by name.
|
|
23
|
-
*/
|
|
24
|
-
backend: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Serverless redis client for upstash.
|
|
29
|
-
*/
|
|
30
|
-
export class Redis extends core.Redis {
|
|
31
|
-
/**
|
|
32
|
-
* Create a new redis client
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const redis = new Redis({
|
|
37
|
-
* url: "<UPSTASH_REDIS_REST_URL>",
|
|
38
|
-
* token: "<UPSTASH_REDIS_REST_TOKEN>",
|
|
39
|
-
* backend: "upstash-db",
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
constructor(config: RedisConfigFastly) {
|
|
44
|
-
const client = new HttpClient({
|
|
45
|
-
baseUrl: config.url,
|
|
46
|
-
headers: {
|
|
47
|
-
authorization: `Bearer ${config.token}`,
|
|
48
|
-
},
|
|
49
|
-
options: { backend: config.backend },
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
super(client)
|
|
53
|
-
}
|
|
54
|
-
}
|
package/pkg/http.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from "./http"
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from "@jest/globals"
|
|
4
|
-
import { newHttpClient } from "./test-utils"
|
|
5
|
-
it("remove trailing slash from urls", () => {
|
|
6
|
-
const client = new HttpClient({
|
|
7
|
-
baseUrl: "https://example.com/",
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
expect(client.baseUrl).toBe("https://example.com")
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
describe("when the request is invalid", () => {
|
|
14
|
-
it("throws", async () => {
|
|
15
|
-
const client = newHttpClient()
|
|
16
|
-
expect(() =>
|
|
17
|
-
client.request({
|
|
18
|
-
body: ["get", "1", "2"],
|
|
19
|
-
}),
|
|
20
|
-
).rejects.toThrowErrorMatchingInlineSnapshot()
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe("whithout authorization", () => {
|
|
25
|
-
it("throws", async () => {
|
|
26
|
-
const client = newHttpClient()
|
|
27
|
-
client.headers = {}
|
|
28
|
-
expect(() =>
|
|
29
|
-
client.request({
|
|
30
|
-
body: ["get", "1", "2"],
|
|
31
|
-
}),
|
|
32
|
-
).rejects.toThrowErrorMatchingInlineSnapshot()
|
|
33
|
-
})
|
|
34
|
-
})
|
package/pkg/http.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import "isomorphic-fetch"
|
|
2
|
-
import { UpstashError } from "./error"
|
|
3
|
-
|
|
4
|
-
export type HttpRequest = {
|
|
5
|
-
path?: string[]
|
|
6
|
-
/**
|
|
7
|
-
* Request body will be serialized to json
|
|
8
|
-
*/
|
|
9
|
-
body?: unknown
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type UpstashResponse<TResult> = {
|
|
13
|
-
result?: TResult
|
|
14
|
-
error?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type HttpClientConfig = {
|
|
18
|
-
headers?: Record<string, string>
|
|
19
|
-
baseUrl: string
|
|
20
|
-
options?: {
|
|
21
|
-
backend?: string
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class HttpClient {
|
|
26
|
-
public baseUrl: string
|
|
27
|
-
public headers: Record<string, string>
|
|
28
|
-
public readonly options?: { backend?: string }
|
|
29
|
-
|
|
30
|
-
public constructor(config: HttpClientConfig) {
|
|
31
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "")
|
|
32
|
-
|
|
33
|
-
this.headers = {
|
|
34
|
-
"Content-Type": "application/json",
|
|
35
|
-
...config.headers,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.options = config.options
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public async request<TResponse>(req: HttpRequest): Promise<TResponse> {
|
|
42
|
-
if (!req.path) {
|
|
43
|
-
req.path = []
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// fetch is defined by isomorphic fetch
|
|
47
|
-
// eslint-disable-next-line no-undef
|
|
48
|
-
const res = await fetch([this.baseUrl, ...req.path].join("/"), {
|
|
49
|
-
method: "POST",
|
|
50
|
-
headers: this.headers,
|
|
51
|
-
body: JSON.stringify(req.body),
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
backend: this.options?.backend,
|
|
54
|
-
})
|
|
55
|
-
const body = await res.json()
|
|
56
|
-
if (!res.ok) {
|
|
57
|
-
throw new UpstashError(body.error)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return body as TResponse
|
|
61
|
-
}
|
|
62
|
-
}
|
package/pkg/index.ts
DELETED