@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.
Files changed (268) hide show
  1. package/README.md +256 -0
  2. package/{dist/chunk-7YUZYRJS.mjs → chunk-7YUZYRJS.mjs} +0 -0
  3. package/{dist/chunk-FJSI5EBJ.mjs → chunk-AHCVU33N.mjs} +2 -2
  4. package/{dist/chunk-ZIB6XPPC.mjs → chunk-HGM7M7CJ.mjs} +9 -4
  5. package/{dist/chunk-U7OXAQMQ.mjs → chunk-HIDCSH5S.mjs} +0 -1
  6. package/{dist/chunk-Y5TC4HX2.mjs → chunk-T66TTHSV.mjs} +5 -5
  7. package/{dist/cloudflare.d.ts → cloudflare.d.ts} +2 -2
  8. package/{dist/cloudflare.js → cloudflare.js} +12 -9
  9. package/{dist/cloudflare.mjs → cloudflare.mjs} +3 -3
  10. package/{dist/commands.d.ts → commands.d.ts} +5 -3
  11. package/{dist/commands.js → commands.js} +10 -4
  12. package/{dist/commands.mjs → commands.mjs} +3 -1
  13. package/{dist/fastly.d.ts → fastly.d.ts} +2 -2
  14. package/{dist/fastly.js → fastly.js} +12 -9
  15. package/{dist/fastly.mjs → fastly.mjs} +3 -3
  16. package/{dist/http.d.ts → http.d.ts} +0 -0
  17. package/{dist/http.js → http.js} +0 -1
  18. package/{dist/http.mjs → http.mjs} +1 -1
  19. package/{dist/index.d.ts → index.d.ts} +2 -2
  20. package/{dist/index.js → index.js} +13 -10
  21. package/index.mjs +13 -0
  22. package/{dist/nodejs.d.ts → nodejs.d.ts} +2 -2
  23. package/{dist/nodejs.js → nodejs.js} +13 -10
  24. package/nodejs.mjs +10 -0
  25. package/package.json +1 -1
  26. package/{dist/redis-dd052782.d.ts → redis-71fa1ee6.d.ts} +7 -3
  27. package/{dist/zunionstore-dffa797d.d.ts → zunionstore-b38007ba.d.ts} +1 -1
  28. package/.eslintrc.js +0 -49
  29. package/.prettierrc.js +0 -7
  30. package/LICENSE +0 -21
  31. package/dist/index.mjs +0 -13
  32. package/dist/nodejs.mjs +0 -10
  33. package/dist/package.json +0 -1
  34. package/jest.config.js +0 -195
  35. package/pkg/cloudflare.ts +0 -77
  36. package/pkg/command.ts +0 -40
  37. package/pkg/commands/append.test.ts +0 -28
  38. package/pkg/commands/append.ts +0 -10
  39. package/pkg/commands/bitcount.test.ts +0 -36
  40. package/pkg/commands/bitcount.ts +0 -19
  41. package/pkg/commands/bitop.test.ts +0 -44
  42. package/pkg/commands/bitop.ts +0 -22
  43. package/pkg/commands/bitpos.test.ts +0 -26
  44. package/pkg/commands/bitpos.ts +0 -10
  45. package/pkg/commands/dbsize.test.ts +0 -17
  46. package/pkg/commands/dbsize.ts +0 -10
  47. package/pkg/commands/decr.test.ts +0 -22
  48. package/pkg/commands/decr.ts +0 -10
  49. package/pkg/commands/decrby.test.ts +0 -23
  50. package/pkg/commands/decrby.ts +0 -10
  51. package/pkg/commands/del.test.ts +0 -38
  52. package/pkg/commands/del.ts +0 -11
  53. package/pkg/commands/echo.test.ts +0 -11
  54. package/pkg/commands/echo.ts +0 -10
  55. package/pkg/commands/exists.test.ts +0 -37
  56. package/pkg/commands/exists.ts +0 -11
  57. package/pkg/commands/expire.test.ts +0 -22
  58. package/pkg/commands/expire.ts +0 -10
  59. package/pkg/commands/expireat.test.ts +0 -24
  60. package/pkg/commands/expireat.ts +0 -10
  61. package/pkg/commands/flushall.test.ts +0 -17
  62. package/pkg/commands/flushall.ts +0 -13
  63. package/pkg/commands/flushdb.test.ts +0 -17
  64. package/pkg/commands/flushdb.ts +0 -13
  65. package/pkg/commands/get.test.ts +0 -34
  66. package/pkg/commands/get.ts +0 -10
  67. package/pkg/commands/getbit.test.ts +0 -16
  68. package/pkg/commands/getbit.ts +0 -10
  69. package/pkg/commands/getrange.test.ts +0 -25
  70. package/pkg/commands/getrange.ts +0 -10
  71. package/pkg/commands/getset.test.ts +0 -33
  72. package/pkg/commands/getset.ts +0 -10
  73. package/pkg/commands/hdel.test.ts +0 -30
  74. package/pkg/commands/hdel.ts +0 -10
  75. package/pkg/commands/hexists.test.ts +0 -31
  76. package/pkg/commands/hexists.ts +0 -10
  77. package/pkg/commands/hget.test.ts +0 -47
  78. package/pkg/commands/hget.ts +0 -10
  79. package/pkg/commands/hgetall.test.ts +0 -32
  80. package/pkg/commands/hgetall.ts +0 -35
  81. package/pkg/commands/hincrby.test.ts +0 -27
  82. package/pkg/commands/hincrby.ts +0 -10
  83. package/pkg/commands/hincrbyfloat.test.ts +0 -25
  84. package/pkg/commands/hincrbyfloat.ts +0 -10
  85. package/pkg/commands/hkeys.test.ts +0 -22
  86. package/pkg/commands/hkeys.ts +0 -10
  87. package/pkg/commands/hlen.test.ts +0 -24
  88. package/pkg/commands/hlen.ts +0 -10
  89. package/pkg/commands/hmget.test.ts +0 -48
  90. package/pkg/commands/hmget.ts +0 -41
  91. package/pkg/commands/hmset.test.ts +0 -24
  92. package/pkg/commands/hmset.ts +0 -10
  93. package/pkg/commands/hscan.test.ts +0 -46
  94. package/pkg/commands/hscan.ts +0 -22
  95. package/pkg/commands/hset.test.ts +0 -21
  96. package/pkg/commands/hset.ts +0 -10
  97. package/pkg/commands/hsetnx.test.ts +0 -37
  98. package/pkg/commands/hsetnx.ts +0 -10
  99. package/pkg/commands/hstrlen.test.ts +0 -24
  100. package/pkg/commands/hstrlen.ts +0 -10
  101. package/pkg/commands/hvals.test.ts +0 -23
  102. package/pkg/commands/hvals.ts +0 -10
  103. package/pkg/commands/incr.test.ts +0 -23
  104. package/pkg/commands/incr.ts +0 -10
  105. package/pkg/commands/incrby.test.ts +0 -23
  106. package/pkg/commands/incrby.ts +0 -10
  107. package/pkg/commands/incrbyfloat.test.ts +0 -24
  108. package/pkg/commands/incrbyfloat.ts +0 -10
  109. package/pkg/commands/index.ts +0 -107
  110. package/pkg/commands/keys.test.ts +0 -17
  111. package/pkg/commands/keys.ts +0 -10
  112. package/pkg/commands/lindex.test.ts +0 -33
  113. package/pkg/commands/lindex.ts +0 -7
  114. package/pkg/commands/linsert.test.ts +0 -19
  115. package/pkg/commands/linsert.ts +0 -6
  116. package/pkg/commands/llen.test.ts +0 -26
  117. package/pkg/commands/llen.ts +0 -10
  118. package/pkg/commands/lpop.test.ts +0 -27
  119. package/pkg/commands/lpop.ts +0 -10
  120. package/pkg/commands/lpush.test.ts +0 -17
  121. package/pkg/commands/lpush.ts +0 -11
  122. package/pkg/commands/lpushx.test.ts +0 -29
  123. package/pkg/commands/lpushx.ts +0 -11
  124. package/pkg/commands/lrange.test.ts +0 -22
  125. package/pkg/commands/lrange.ts +0 -7
  126. package/pkg/commands/lrem.test.ts +0 -19
  127. package/pkg/commands/lrem.ts +0 -6
  128. package/pkg/commands/lset.test.ts +0 -40
  129. package/pkg/commands/lset.ts +0 -7
  130. package/pkg/commands/ltrim.test.ts +0 -29
  131. package/pkg/commands/ltrim.ts +0 -7
  132. package/pkg/commands/mget.test.ts +0 -44
  133. package/pkg/commands/mget.ts +0 -9
  134. package/pkg/commands/mset.test.ts +0 -24
  135. package/pkg/commands/mset.ts +0 -10
  136. package/pkg/commands/msetnx.test.ts +0 -46
  137. package/pkg/commands/msetnx.ts +0 -10
  138. package/pkg/commands/persist.test.ts +0 -22
  139. package/pkg/commands/persist.ts +0 -10
  140. package/pkg/commands/pexpire.test.ts +0 -24
  141. package/pkg/commands/pexpire.ts +0 -10
  142. package/pkg/commands/pexpireat.test.ts +0 -24
  143. package/pkg/commands/pexpireat.ts +0 -10
  144. package/pkg/commands/ping.test.ts +0 -19
  145. package/pkg/commands/ping.ts +0 -13
  146. package/pkg/commands/psetex.test.ts +0 -23
  147. package/pkg/commands/psetex.ts +0 -10
  148. package/pkg/commands/pttl.test.ts +0 -17
  149. package/pkg/commands/pttl.ts +0 -10
  150. package/pkg/commands/randomkey.test.ts +0 -17
  151. package/pkg/commands/randomkey.ts +0 -10
  152. package/pkg/commands/rename.test.ts +0 -18
  153. package/pkg/commands/rename.ts +0 -10
  154. package/pkg/commands/renamenx.test.ts +0 -32
  155. package/pkg/commands/renamenx.ts +0 -10
  156. package/pkg/commands/rpop.test.ts +0 -27
  157. package/pkg/commands/rpop.ts +0 -10
  158. package/pkg/commands/rpush.test.ts +0 -17
  159. package/pkg/commands/rpush.ts +0 -11
  160. package/pkg/commands/rpushx.test.ts +0 -29
  161. package/pkg/commands/rpushx.ts +0 -11
  162. package/pkg/commands/sadd.test.ts +0 -16
  163. package/pkg/commands/sadd.ts +0 -11
  164. package/pkg/commands/scan.test.ts +0 -50
  165. package/pkg/commands/scan.ts +0 -21
  166. package/pkg/commands/scard.test.ts +0 -15
  167. package/pkg/commands/scard.ts +0 -9
  168. package/pkg/commands/sdiff.test.ts +0 -20
  169. package/pkg/commands/sdiff.ts +0 -9
  170. package/pkg/commands/sdiffstore.test.ts +0 -21
  171. package/pkg/commands/sdiffstore.ts +0 -10
  172. package/pkg/commands/set.test.ts +0 -112
  173. package/pkg/commands/set.ts +0 -53
  174. package/pkg/commands/setbit.test.ts +0 -16
  175. package/pkg/commands/setbit.ts +0 -10
  176. package/pkg/commands/setex.test.ts +0 -22
  177. package/pkg/commands/setex.ts +0 -10
  178. package/pkg/commands/setnx.test.ts +0 -27
  179. package/pkg/commands/setnx.ts +0 -10
  180. package/pkg/commands/setrange.test.ts +0 -25
  181. package/pkg/commands/setrange.ts +0 -10
  182. package/pkg/commands/sinter.test.ts +0 -36
  183. package/pkg/commands/sinter.ts +0 -9
  184. package/pkg/commands/sinterstore.test.ts +0 -21
  185. package/pkg/commands/sinterstore.ts +0 -9
  186. package/pkg/commands/sismember.test.ts +0 -30
  187. package/pkg/commands/sismember.ts +0 -9
  188. package/pkg/commands/smembers.test.ts +0 -22
  189. package/pkg/commands/smembers.ts +0 -10
  190. package/pkg/commands/smove.test.ts +0 -18
  191. package/pkg/commands/smove.ts +0 -9
  192. package/pkg/commands/spop.test.ts +0 -35
  193. package/pkg/commands/spop.ts +0 -13
  194. package/pkg/commands/srandmember.test.ts +0 -32
  195. package/pkg/commands/srandmember.ts +0 -13
  196. package/pkg/commands/srem.test.ts +0 -18
  197. package/pkg/commands/srem.ts +0 -10
  198. package/pkg/commands/sscan.test.ts +0 -50
  199. package/pkg/commands/sscan.ts +0 -22
  200. package/pkg/commands/strlen.test.ts +0 -16
  201. package/pkg/commands/strlen.ts +0 -10
  202. package/pkg/commands/sunion.test.ts +0 -22
  203. package/pkg/commands/sunion.ts +0 -10
  204. package/pkg/commands/sunionstore.test.ts +0 -29
  205. package/pkg/commands/sunionstore.ts +0 -10
  206. package/pkg/commands/time.test.ts +0 -11
  207. package/pkg/commands/time.ts +0 -9
  208. package/pkg/commands/touch.test.ts +0 -20
  209. package/pkg/commands/touch.ts +0 -10
  210. package/pkg/commands/ttl.test.ts +0 -17
  211. package/pkg/commands/ttl.ts +0 -10
  212. package/pkg/commands/type.test.ts +0 -72
  213. package/pkg/commands/type.ts +0 -11
  214. package/pkg/commands/unlink.test.ts +0 -21
  215. package/pkg/commands/unlink.ts +0 -10
  216. package/pkg/commands/zadd.test.ts +0 -177
  217. package/pkg/commands/zadd.ts +0 -64
  218. package/pkg/commands/zcard.test.ts +0 -15
  219. package/pkg/commands/zcard.ts +0 -10
  220. package/pkg/commands/zcount.test.ts +0 -15
  221. package/pkg/commands/zcount.ts +0 -9
  222. package/pkg/commands/zincrby.test.ts +0 -20
  223. package/pkg/commands/zincrby.ts +0 -9
  224. package/pkg/commands/zinterstore.test.ts +0 -239
  225. package/pkg/commands/zinterstore.ts +0 -55
  226. package/pkg/commands/zlexcount.test.ts +0 -22
  227. package/pkg/commands/zlexcount.ts +0 -9
  228. package/pkg/commands/zpopmax.test.ts +0 -45
  229. package/pkg/commands/zpopmax.ts +0 -13
  230. package/pkg/commands/zpopmin.test.ts +0 -49
  231. package/pkg/commands/zpopmin.ts +0 -13
  232. package/pkg/commands/zrange.test.ts +0 -52
  233. package/pkg/commands/zrange.ts +0 -22
  234. package/pkg/commands/zrank.test.ts +0 -22
  235. package/pkg/commands/zrank.ts +0 -10
  236. package/pkg/commands/zrem.test.ts +0 -20
  237. package/pkg/commands/zrem.ts +0 -10
  238. package/pkg/commands/zremrangebylex.test.ts +0 -26
  239. package/pkg/commands/zremrangebylex.ts +0 -9
  240. package/pkg/commands/zremrangebyrank.test.ts +0 -27
  241. package/pkg/commands/zremrangebyrank.ts +0 -9
  242. package/pkg/commands/zremrangebyscore.test.ts +0 -24
  243. package/pkg/commands/zremrangebyscore.ts +0 -9
  244. package/pkg/commands/zrevrank.test.ts +0 -22
  245. package/pkg/commands/zrevrank.ts +0 -10
  246. package/pkg/commands/zscan.test.ts +0 -50
  247. package/pkg/commands/zscan.ts +0 -22
  248. package/pkg/commands/zscore.test.ts +0 -18
  249. package/pkg/commands/zscore.ts +0 -10
  250. package/pkg/commands/zunionstore.test.ts +0 -215
  251. package/pkg/commands/zunionstore.ts +0 -55
  252. package/pkg/commands/zz.ts +0 -1
  253. package/pkg/error.ts +0 -9
  254. package/pkg/fastly.ts +0 -54
  255. package/pkg/http.test.ts +0 -34
  256. package/pkg/http.ts +0 -62
  257. package/pkg/index.ts +0 -2
  258. package/pkg/nodejs.ts +0 -83
  259. package/pkg/pipeline.test.ts +0 -177
  260. package/pkg/pipeline.ts +0 -999
  261. package/pkg/redis.ts +0 -930
  262. package/pkg/test-utils.ts +0 -41
  263. package/pkg/types.ts +0 -4
  264. package/pkg/util.ts +0 -22
  265. package/pnpm-lock.yaml +0 -3940
  266. package/tsconfig.json +0 -100
  267. package/tsconfig.module.json +0 -8
  268. package/tsup.config.ts +0 -16
@@ -1,177 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomInt, randomUUID } from "crypto"
3
- import { describe, 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
- describe("command format", () => {
12
- describe("without options", () => {
13
- it("build the correct command", () => {
14
- expect(new ZAddCommand("key", { score: 0, member: "member" }).command).toEqual([
15
- "zadd",
16
- "key",
17
- "0",
18
- "member",
19
- ])
20
- })
21
- })
22
- describe("with nx", () => {
23
- it("build the correct command", () => {
24
- expect(new ZAddCommand("key", { nx: true }, { score: 0, member: "member" }).command).toEqual([
25
- "zadd",
26
- "key",
27
- "nx",
28
- "0",
29
- "member",
30
- ])
31
- })
32
- })
33
- describe("with xx", () => {
34
- it("build the correct command", () => {
35
- expect(new ZAddCommand("key", { xx: true }, { score: 0, member: "member" }).command).toEqual([
36
- "zadd",
37
- "key",
38
- "xx",
39
- "0",
40
- "member",
41
- ])
42
- })
43
- })
44
- describe("with ch", () => {
45
- it("build the correct command", () => {
46
- expect(new ZAddCommand("key", { ch: true }, { score: 0, member: "member" }).command).toEqual([
47
- "zadd",
48
- "key",
49
- "ch",
50
- "0",
51
- "member",
52
- ])
53
- })
54
- })
55
- describe("with incr", () => {
56
- it("build the correct command", () => {
57
- expect(
58
- new ZAddCommand("key", { incr: true }, { score: 0, member: "member" }).command,
59
- ).toEqual(["zadd", "key", "incr", "0", "member"])
60
- })
61
- })
62
- describe("with nx and ch", () => {
63
- it("build the correct command", () => {
64
- expect(
65
- new ZAddCommand("key", { nx: true, ch: true }, { score: 0, member: "member" }).command,
66
- ).toEqual(["zadd", "key", "nx", "ch", "0", "member"])
67
- })
68
- })
69
- describe("with nx,ch and incr", () => {
70
- it("build the correct command", () => {
71
- expect(
72
- new ZAddCommand("key", { nx: true, ch: true, incr: true }, { score: 0, member: "member" })
73
- .command,
74
- ).toEqual(["zadd", "key", "nx", "ch", "incr", "0", "member"])
75
- })
76
- })
77
- describe("with nx and multiple members", () => {
78
- it("build the correct command", () => {
79
- expect(
80
- new ZAddCommand(
81
- "key",
82
- { nx: true },
83
- { score: 0, member: "member" },
84
- { score: 1, member: "member1" },
85
- ).command,
86
- ).toEqual(["zadd", "key", "nx", "0", "member", "1", "member1"])
87
- })
88
- })
89
- })
90
-
91
- describe("without options", () => {
92
- it("adds the member", async () => {
93
- const key = newKey()
94
- const member = randomUUID()
95
- const score = randomInt(10)
96
- const res = await new ZAddCommand(key, { score, member }).exec(client)
97
- expect(res).toBe(1)
98
- })
99
- })
100
-
101
- describe("xx", () => {
102
- describe("when the element exists", () => {
103
- it("updates the element", async () => {
104
- const key = newKey()
105
- const member = randomUUID()
106
- const score = randomInt(10)
107
- await new ZAddCommand(key, { score, member }).exec(client)
108
- const newScore = score + 1
109
- const res = await new ZAddCommand(key, { xx: true }, { score: newScore, member }).exec(client)
110
- expect(res).toBe(0)
111
-
112
- const res2 = await new ZScoreCommand(key, member).exec(client)
113
- expect(res2).toBe(newScore)
114
- })
115
- })
116
- describe("when the element does not exist", () => {
117
- it("does nothing", async () => {
118
- const key = newKey()
119
- const member = randomUUID()
120
- const score = randomInt(10)
121
- await new ZAddCommand(key, { score, member }).exec(client)
122
- const newScore = score + 1
123
- const res = await new ZAddCommand(key, { xx: true }, { score: newScore, member }).exec(client)
124
- expect(res).toBe(0)
125
- })
126
- })
127
- })
128
-
129
- describe("nx", () => {
130
- describe("when the element exists", () => {
131
- it("does nothing", async () => {
132
- const key = newKey()
133
- const member = randomUUID()
134
- const score = randomInt(10)
135
- await new ZAddCommand(key, { score, member }).exec(client)
136
- const newScore = score + 1
137
- const res = await new ZAddCommand(key, { nx: true }, { score: newScore, member }).exec(client)
138
- expect(res).toBe(0)
139
-
140
- const res2 = await new ZScoreCommand(key, member).exec(client)
141
- expect(res2).toBe(score)
142
- })
143
- })
144
- describe("when the element does not exist", () => {
145
- it("creates element", async () => {
146
- const key = newKey()
147
- const member = randomUUID()
148
- const score = randomInt(10)
149
- const res = await new ZAddCommand(key, { nx: true }, { score, member }).exec(client)
150
- expect(res).toBe(1)
151
- })
152
- })
153
- })
154
-
155
- describe("ch", () => {
156
- it("returns the number of changed elements", async () => {
157
- const key = newKey()
158
- const member = randomUUID()
159
- const score = randomInt(10)
160
- await new ZAddCommand(key, { score, member }).exec(client)
161
- const newScore = score + 1
162
- const res = await new ZAddCommand(key, { ch: true }, { score: newScore, member }).exec(client)
163
- expect(res).toBe(1)
164
- })
165
- })
166
-
167
- describe("incr", () => {
168
- it("returns the number of changed elements", async () => {
169
- const key = newKey()
170
- const member = randomUUID()
171
- const score = randomInt(10)
172
- await new ZAddCommand(key, { score, member }).exec(client)
173
- const newScore = score + 1
174
- const res = await new ZAddCommand(key, { ch: true }, { score: newScore, member }).exec(client)
175
- expect(res).toBe(1)
176
- })
177
- })
@@ -1,64 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- export type ZAddCommandOptions = (
4
- | {
5
- nx: true
6
- xx?: never
7
- }
8
- | {
9
- nx?: never
10
- xx: true
11
- }
12
- | { nx?: never; xx?: never }
13
- ) & { ch?: true }
14
-
15
- export type ZAddCommandOptionsWithIncr = ZAddCommandOptions & {
16
- incr: true
17
- }
18
-
19
- export type ScoreMember<TData> = {
20
- score: number
21
- member: TData
22
- }
23
- /**
24
- * @see https://redis.io/commands/zadd
25
- */
26
- export class ZAddCommand<TData = string> extends Command<number | null, number | null> {
27
- constructor(
28
- key: string,
29
- scoreMember: ScoreMember<TData>,
30
- ...scoreMemberPairs: ScoreMember<TData>[]
31
- )
32
- constructor(
33
- key: string,
34
- opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr,
35
- ...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]
36
- )
37
- constructor(
38
- key: string,
39
- arg1: ScoreMember<TData> | ZAddCommandOptions | ZAddCommandOptionsWithIncr,
40
- ...arg2: ScoreMember<TData>[]
41
- ) {
42
- const command: unknown[] = ["zadd", key]
43
-
44
- if ("nx" in arg1 && arg1.nx) {
45
- command.push("nx")
46
- } else if ("xx" in arg1 && arg1.xx) {
47
- command.push("xx")
48
- }
49
- if ("ch" in arg1 && arg1.ch) {
50
- command.push("ch")
51
- }
52
- if ("incr" in arg1 && arg1.incr) {
53
- command.push("incr")
54
- }
55
-
56
- if ("score" in arg1 && "member" in arg1) {
57
- command.push(arg1.score, arg1.member)
58
- }
59
-
60
- command.push(...arg2.flatMap(({ score, member }) => [score, member]))
61
-
62
- super(command)
63
- }
64
- }
@@ -1,15 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { ZAddCommand } from "./zadd"
4
- import { ZCardCommand } from "./zcard"
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 ZAddCommand(key, { score: 1, member: "member1" }).exec(client)
13
- const res = await new ZCardCommand(key).exec(client)
14
- expect(res).toBe(1)
15
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/zcard
5
- */
6
- export class ZCardCommand extends Command<number, number> {
7
- constructor(key: string) {
8
- super(["zcard", key])
9
- }
10
- }
@@ -1,15 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { ZAddCommand } from "./zadd"
4
- import { ZCountCommand } from "./zcount"
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 ZAddCommand(key, { score: 1, member: "member1" }).exec(client)
13
- const res = await new ZCountCommand(key, 0, 2).exec(client)
14
- expect(res).toBe(1)
15
- })
@@ -1,9 +0,0 @@
1
- import { Command } from "../command"
2
- /**
3
- * @see https://redis.io/commands/zcount
4
- */
5
- export class ZCountCommand extends Command<number, number> {
6
- constructor(key: string, min: number | string, max: number | string) {
7
- super(["zcount", key, min, max])
8
- }
9
- }
@@ -1,20 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { ZIncrByComand } from "./zincrby"
4
- import { ZAddCommand } from "./zadd"
5
- import { randomUUID } from "crypto"
6
-
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- it("increments and existing value", async () => {
13
- const key = newKey()
14
- const score = 1
15
- const member = randomUUID()
16
- await new ZAddCommand(key, { score, member }).exec(client)
17
- const res = await new ZIncrByComand(key, 2, member).exec(client)
18
-
19
- expect(res).toEqual(3)
20
- })
@@ -1,9 +0,0 @@
1
- import { Command } from "../command"
2
- /**
3
- * @see https://redis.io/commands/zincrby
4
- */
5
- export class ZIncrByComand<TData> extends Command<number, number> {
6
- constructor(key: string, increment: number, member: TData) {
7
- super(["zincrby", key, increment, member])
8
- }
9
- }
@@ -1,239 +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 { ZInterStoreCommand } from "./zinterstore"
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 ZInterStoreCommand("destination", 1, "key").command).toEqual([
16
- "zinterstore",
17
- "destination",
18
- "1",
19
- "key",
20
- ])
21
- })
22
- })
23
- describe("with multiple keys", () => {
24
- it("builds the correct command", () => {
25
- expect(new ZInterStoreCommand("destination", 2, ["key1", "key2"]).command).toEqual([
26
- "zinterstore",
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 ZInterStoreCommand("destination", 1, "key", { weight: 4 }).command).toEqual([
37
- "zinterstore",
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 ZInterStoreCommand("destination", 2, ["key1", "key2"], { weights: [2, 3] }).command,
50
- ).toEqual(["zinterstore", "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 ZInterStoreCommand("destination", 1, "key", { aggregate: "sum" }).command,
57
- ).toEqual(["zinterstore", "destination", "1", "key", "aggregate", "sum"])
58
- })
59
- })
60
- describe("min", () => {
61
- it("builds the correct command", () => {
62
- expect(
63
- new ZInterStoreCommand("destination", 1, "key", { aggregate: "min" }).command,
64
- ).toEqual(["zinterstore", "destination", "1", "key", "aggregate", "min"])
65
- })
66
- })
67
- describe("max", () => {
68
- it("builds the correct command", () => {
69
- expect(
70
- new ZInterStoreCommand("destination", 1, "key", { aggregate: "max" }).command,
71
- ).toEqual(["zinterstore", "destination", "1", "key", "aggregate", "max"])
72
- })
73
- })
74
- })
75
- describe("complex", () => {
76
- it("builds the correct command", () => {
77
- expect(
78
- new ZInterStoreCommand("destination", 2, ["key1", "key2"], {
79
- weights: [4, 2],
80
- aggregate: "max",
81
- }).command,
82
- ).toEqual([
83
- "zinterstore",
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(
111
- key2,
112
- { score: score1, member: member1 },
113
- { score: score2, member: member2 },
114
- ).exec(client)
115
-
116
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2]).exec(client)
117
- expect(res).toBe(1)
118
- })
119
- })
120
-
121
- describe("with weights", () => {
122
- describe("single weight", () => {
123
- it("returns the number of elements in the new set ", async () => {
124
- const destination = newKey()
125
- const key1 = newKey()
126
- const key2 = newKey()
127
- const score1 = 1
128
- const member1 = randomUUID()
129
- const score2 = 2
130
- const member2 = randomUUID()
131
-
132
- await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
133
- await new ZAddCommand(
134
- key2,
135
- { score: score1, member: member1 },
136
- { score: score2, member: member2 },
137
- ).exec(client)
138
-
139
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2], {
140
- weights: [2, 3],
141
- }).exec(client)
142
- expect(res).toBe(1)
143
- })
144
- })
145
- describe("multiple weight", () => {
146
- it("returns the number of elements in the new set ", async () => {
147
- const destination = newKey()
148
- const key1 = newKey()
149
- const key2 = newKey()
150
- const score1 = 1
151
- const member1 = randomUUID()
152
- const score2 = 2
153
- const member2 = randomUUID()
154
-
155
- await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
156
- await new ZAddCommand(
157
- key2,
158
- { score: score1, member: member1 },
159
- { score: score2, member: member2 },
160
- ).exec(client)
161
-
162
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2], {
163
- weights: [1, 2],
164
- }).exec(client)
165
- expect(res).toBe(1)
166
- })
167
- })
168
- })
169
- describe("aggregate", () => {
170
- describe("sum", () => {
171
- it("returns the number of elements in the new set ", async () => {
172
- const destination = newKey()
173
- const key1 = newKey()
174
- const key2 = newKey()
175
- const score1 = 1
176
- const member1 = randomUUID()
177
- const score2 = 2
178
- const member2 = randomUUID()
179
-
180
- await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
181
- await new ZAddCommand(
182
- key2,
183
- { score: score1, member: member1 },
184
- { score: score2, member: member2 },
185
- ).exec(client)
186
-
187
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2], {
188
- aggregate: "sum",
189
- }).exec(client)
190
- expect(res).toBe(1)
191
- })
192
- })
193
- describe("min", () => {
194
- it("returns the number of elements in the new set ", async () => {
195
- const destination = newKey()
196
- const key1 = newKey()
197
- const key2 = newKey()
198
- const score1 = 1
199
- const member1 = randomUUID()
200
- const score2 = 2
201
- const member2 = randomUUID()
202
-
203
- await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
204
- await new ZAddCommand(
205
- key2,
206
- { score: score1, member: member1 },
207
- { score: score2, member: member2 },
208
- ).exec(client)
209
-
210
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2], {
211
- aggregate: "min",
212
- }).exec(client)
213
- expect(res).toBe(1)
214
- })
215
- })
216
- describe("max", () => {
217
- it("returns the number of elements in the new set ", async () => {
218
- const destination = newKey()
219
- const key1 = newKey()
220
- const key2 = newKey()
221
- const score1 = 1
222
- const member1 = randomUUID()
223
- const score2 = 2
224
- const member2 = randomUUID()
225
-
226
- await new ZAddCommand(key1, { score: score1, member: member1 }).exec(client)
227
- await new ZAddCommand(
228
- key2,
229
- { score: score1, member: member1 },
230
- { score: score2, member: member2 },
231
- ).exec(client)
232
-
233
- const res = await new ZInterStoreCommand(destination, 2, [key1, key2], {
234
- aggregate: "max",
235
- }).exec(client)
236
- expect(res).toBe(1)
237
- })
238
- })
239
- })
@@ -1,55 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- export type ZInterStoreCommandOptions = {
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/zInterstore
22
- */
23
- export class ZInterStoreCommand extends Command<number, number> {
24
- constructor(destination: string, numKeys: 1, key: string, opts?: ZInterStoreCommandOptions)
25
- constructor(
26
- destination: string,
27
- numKeys: number,
28
- keys: string[],
29
- opts?: ZInterStoreCommandOptions,
30
- )
31
- constructor(
32
- destination: string,
33
- numKeys: number,
34
- keyOrKeys: string | string[],
35
- opts?: ZInterStoreCommandOptions,
36
- ) {
37
- const command: unknown[] = ["zinterstore", 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
- }
@@ -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 { ZLexCountCommand } from "./zlexcount"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- it("returns the number of elements in the specified score range", async () => {
11
- const key = newKey()
12
- await new ZAddCommand(
13
- key,
14
- { score: 0, member: "a" },
15
- { score: 0, member: "b" },
16
- { score: 0, member: "c" },
17
- { score: 0, member: "d" },
18
- { score: 0, member: "e" },
19
- ).exec(client)
20
- const res = await new ZLexCountCommand(key, "[b", "[f").exec(client)
21
- expect(res).toBe(4)
22
- })
@@ -1,9 +0,0 @@
1
- import { Command } from "../command"
2
- /**
3
- * @see https://redis.io/commands/zlexcount
4
- */
5
- export class ZLexCountCommand extends Command<number, number> {
6
- constructor(key: string, min: string, max: string) {
7
- super(["zlexcount", key, min, max])
8
- }
9
- }