@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.
Files changed (265) hide show
  1. package/{dist/chunk-7YUZYRJS.mjs → chunk-7YUZYRJS.mjs} +0 -0
  2. package/{dist/chunk-FJSI5EBJ.mjs → chunk-FJSI5EBJ.mjs} +0 -0
  3. package/{dist/chunk-U7OXAQMQ.mjs → chunk-U7OXAQMQ.mjs} +0 -0
  4. package/{dist/chunk-Y5TC4HX2.mjs → chunk-Y5TC4HX2.mjs} +0 -0
  5. package/{dist/chunk-ZIB6XPPC.mjs → chunk-ZIB6XPPC.mjs} +0 -0
  6. package/{dist/cloudflare.d.ts → cloudflare.d.ts} +0 -0
  7. package/{dist/cloudflare.js → cloudflare.js} +0 -0
  8. package/{dist/cloudflare.mjs → cloudflare.mjs} +0 -0
  9. package/{dist/commands.d.ts → commands.d.ts} +0 -0
  10. package/{dist/commands.js → commands.js} +0 -0
  11. package/{dist/commands.mjs → commands.mjs} +0 -0
  12. package/{dist/fastly.d.ts → fastly.d.ts} +0 -0
  13. package/{dist/fastly.js → fastly.js} +0 -0
  14. package/{dist/fastly.mjs → fastly.mjs} +0 -0
  15. package/{dist/http.d.ts → http.d.ts} +0 -0
  16. package/{dist/http.js → http.js} +0 -0
  17. package/{dist/http.mjs → http.mjs} +0 -0
  18. package/{dist/index.d.ts → index.d.ts} +0 -0
  19. package/{dist/index.js → index.js} +0 -0
  20. package/{dist/index.mjs → index.mjs} +0 -0
  21. package/{dist/nodejs.d.ts → nodejs.d.ts} +0 -0
  22. package/{dist/nodejs.js → nodejs.js} +0 -0
  23. package/{dist/nodejs.mjs → nodejs.mjs} +0 -0
  24. package/package.json +1 -1
  25. package/{dist/redis-dd052782.d.ts → redis-dd052782.d.ts} +0 -0
  26. package/{dist/zunionstore-dffa797d.d.ts → zunionstore-dffa797d.d.ts} +0 -0
  27. package/.eslintrc.js +0 -49
  28. package/.prettierrc.js +0 -7
  29. package/LICENSE +0 -21
  30. package/dist/package.json +0 -1
  31. package/jest.config.js +0 -195
  32. package/pkg/cloudflare.ts +0 -77
  33. package/pkg/command.ts +0 -40
  34. package/pkg/commands/append.test.ts +0 -28
  35. package/pkg/commands/append.ts +0 -10
  36. package/pkg/commands/bitcount.test.ts +0 -36
  37. package/pkg/commands/bitcount.ts +0 -19
  38. package/pkg/commands/bitop.test.ts +0 -44
  39. package/pkg/commands/bitop.ts +0 -22
  40. package/pkg/commands/bitpos.test.ts +0 -26
  41. package/pkg/commands/bitpos.ts +0 -10
  42. package/pkg/commands/dbsize.test.ts +0 -17
  43. package/pkg/commands/dbsize.ts +0 -10
  44. package/pkg/commands/decr.test.ts +0 -22
  45. package/pkg/commands/decr.ts +0 -10
  46. package/pkg/commands/decrby.test.ts +0 -23
  47. package/pkg/commands/decrby.ts +0 -10
  48. package/pkg/commands/del.test.ts +0 -38
  49. package/pkg/commands/del.ts +0 -11
  50. package/pkg/commands/echo.test.ts +0 -11
  51. package/pkg/commands/echo.ts +0 -10
  52. package/pkg/commands/exists.test.ts +0 -37
  53. package/pkg/commands/exists.ts +0 -11
  54. package/pkg/commands/expire.test.ts +0 -22
  55. package/pkg/commands/expire.ts +0 -10
  56. package/pkg/commands/expireat.test.ts +0 -24
  57. package/pkg/commands/expireat.ts +0 -10
  58. package/pkg/commands/flushall.test.ts +0 -17
  59. package/pkg/commands/flushall.ts +0 -13
  60. package/pkg/commands/flushdb.test.ts +0 -17
  61. package/pkg/commands/flushdb.ts +0 -13
  62. package/pkg/commands/get.test.ts +0 -34
  63. package/pkg/commands/get.ts +0 -10
  64. package/pkg/commands/getbit.test.ts +0 -16
  65. package/pkg/commands/getbit.ts +0 -10
  66. package/pkg/commands/getrange.test.ts +0 -25
  67. package/pkg/commands/getrange.ts +0 -10
  68. package/pkg/commands/getset.test.ts +0 -33
  69. package/pkg/commands/getset.ts +0 -10
  70. package/pkg/commands/hdel.test.ts +0 -30
  71. package/pkg/commands/hdel.ts +0 -10
  72. package/pkg/commands/hexists.test.ts +0 -31
  73. package/pkg/commands/hexists.ts +0 -10
  74. package/pkg/commands/hget.test.ts +0 -47
  75. package/pkg/commands/hget.ts +0 -10
  76. package/pkg/commands/hgetall.test.ts +0 -32
  77. package/pkg/commands/hgetall.ts +0 -35
  78. package/pkg/commands/hincrby.test.ts +0 -27
  79. package/pkg/commands/hincrby.ts +0 -10
  80. package/pkg/commands/hincrbyfloat.test.ts +0 -25
  81. package/pkg/commands/hincrbyfloat.ts +0 -10
  82. package/pkg/commands/hkeys.test.ts +0 -22
  83. package/pkg/commands/hkeys.ts +0 -10
  84. package/pkg/commands/hlen.test.ts +0 -24
  85. package/pkg/commands/hlen.ts +0 -10
  86. package/pkg/commands/hmget.test.ts +0 -48
  87. package/pkg/commands/hmget.ts +0 -41
  88. package/pkg/commands/hmset.test.ts +0 -24
  89. package/pkg/commands/hmset.ts +0 -10
  90. package/pkg/commands/hscan.test.ts +0 -46
  91. package/pkg/commands/hscan.ts +0 -22
  92. package/pkg/commands/hset.test.ts +0 -21
  93. package/pkg/commands/hset.ts +0 -10
  94. package/pkg/commands/hsetnx.test.ts +0 -37
  95. package/pkg/commands/hsetnx.ts +0 -10
  96. package/pkg/commands/hstrlen.test.ts +0 -24
  97. package/pkg/commands/hstrlen.ts +0 -10
  98. package/pkg/commands/hvals.test.ts +0 -23
  99. package/pkg/commands/hvals.ts +0 -10
  100. package/pkg/commands/incr.test.ts +0 -23
  101. package/pkg/commands/incr.ts +0 -10
  102. package/pkg/commands/incrby.test.ts +0 -23
  103. package/pkg/commands/incrby.ts +0 -10
  104. package/pkg/commands/incrbyfloat.test.ts +0 -24
  105. package/pkg/commands/incrbyfloat.ts +0 -10
  106. package/pkg/commands/index.ts +0 -107
  107. package/pkg/commands/keys.test.ts +0 -17
  108. package/pkg/commands/keys.ts +0 -10
  109. package/pkg/commands/lindex.test.ts +0 -33
  110. package/pkg/commands/lindex.ts +0 -7
  111. package/pkg/commands/linsert.test.ts +0 -19
  112. package/pkg/commands/linsert.ts +0 -6
  113. package/pkg/commands/llen.test.ts +0 -26
  114. package/pkg/commands/llen.ts +0 -10
  115. package/pkg/commands/lpop.test.ts +0 -27
  116. package/pkg/commands/lpop.ts +0 -10
  117. package/pkg/commands/lpush.test.ts +0 -17
  118. package/pkg/commands/lpush.ts +0 -11
  119. package/pkg/commands/lpushx.test.ts +0 -29
  120. package/pkg/commands/lpushx.ts +0 -11
  121. package/pkg/commands/lrange.test.ts +0 -22
  122. package/pkg/commands/lrange.ts +0 -7
  123. package/pkg/commands/lrem.test.ts +0 -19
  124. package/pkg/commands/lrem.ts +0 -6
  125. package/pkg/commands/lset.test.ts +0 -40
  126. package/pkg/commands/lset.ts +0 -7
  127. package/pkg/commands/ltrim.test.ts +0 -29
  128. package/pkg/commands/ltrim.ts +0 -7
  129. package/pkg/commands/mget.test.ts +0 -44
  130. package/pkg/commands/mget.ts +0 -9
  131. package/pkg/commands/mset.test.ts +0 -24
  132. package/pkg/commands/mset.ts +0 -10
  133. package/pkg/commands/msetnx.test.ts +0 -46
  134. package/pkg/commands/msetnx.ts +0 -10
  135. package/pkg/commands/persist.test.ts +0 -22
  136. package/pkg/commands/persist.ts +0 -10
  137. package/pkg/commands/pexpire.test.ts +0 -24
  138. package/pkg/commands/pexpire.ts +0 -10
  139. package/pkg/commands/pexpireat.test.ts +0 -24
  140. package/pkg/commands/pexpireat.ts +0 -10
  141. package/pkg/commands/ping.test.ts +0 -19
  142. package/pkg/commands/ping.ts +0 -13
  143. package/pkg/commands/psetex.test.ts +0 -23
  144. package/pkg/commands/psetex.ts +0 -10
  145. package/pkg/commands/pttl.test.ts +0 -17
  146. package/pkg/commands/pttl.ts +0 -10
  147. package/pkg/commands/randomkey.test.ts +0 -17
  148. package/pkg/commands/randomkey.ts +0 -10
  149. package/pkg/commands/rename.test.ts +0 -18
  150. package/pkg/commands/rename.ts +0 -10
  151. package/pkg/commands/renamenx.test.ts +0 -32
  152. package/pkg/commands/renamenx.ts +0 -10
  153. package/pkg/commands/rpop.test.ts +0 -27
  154. package/pkg/commands/rpop.ts +0 -10
  155. package/pkg/commands/rpush.test.ts +0 -17
  156. package/pkg/commands/rpush.ts +0 -11
  157. package/pkg/commands/rpushx.test.ts +0 -29
  158. package/pkg/commands/rpushx.ts +0 -11
  159. package/pkg/commands/sadd.test.ts +0 -16
  160. package/pkg/commands/sadd.ts +0 -11
  161. package/pkg/commands/scan.test.ts +0 -50
  162. package/pkg/commands/scan.ts +0 -21
  163. package/pkg/commands/scard.test.ts +0 -15
  164. package/pkg/commands/scard.ts +0 -9
  165. package/pkg/commands/sdiff.test.ts +0 -20
  166. package/pkg/commands/sdiff.ts +0 -9
  167. package/pkg/commands/sdiffstore.test.ts +0 -21
  168. package/pkg/commands/sdiffstore.ts +0 -10
  169. package/pkg/commands/set.test.ts +0 -112
  170. package/pkg/commands/set.ts +0 -53
  171. package/pkg/commands/setbit.test.ts +0 -16
  172. package/pkg/commands/setbit.ts +0 -10
  173. package/pkg/commands/setex.test.ts +0 -22
  174. package/pkg/commands/setex.ts +0 -10
  175. package/pkg/commands/setnx.test.ts +0 -27
  176. package/pkg/commands/setnx.ts +0 -10
  177. package/pkg/commands/setrange.test.ts +0 -25
  178. package/pkg/commands/setrange.ts +0 -10
  179. package/pkg/commands/sinter.test.ts +0 -36
  180. package/pkg/commands/sinter.ts +0 -9
  181. package/pkg/commands/sinterstore.test.ts +0 -21
  182. package/pkg/commands/sinterstore.ts +0 -9
  183. package/pkg/commands/sismember.test.ts +0 -30
  184. package/pkg/commands/sismember.ts +0 -9
  185. package/pkg/commands/smembers.test.ts +0 -22
  186. package/pkg/commands/smembers.ts +0 -10
  187. package/pkg/commands/smove.test.ts +0 -18
  188. package/pkg/commands/smove.ts +0 -9
  189. package/pkg/commands/spop.test.ts +0 -35
  190. package/pkg/commands/spop.ts +0 -13
  191. package/pkg/commands/srandmember.test.ts +0 -32
  192. package/pkg/commands/srandmember.ts +0 -13
  193. package/pkg/commands/srem.test.ts +0 -18
  194. package/pkg/commands/srem.ts +0 -10
  195. package/pkg/commands/sscan.test.ts +0 -50
  196. package/pkg/commands/sscan.ts +0 -22
  197. package/pkg/commands/strlen.test.ts +0 -16
  198. package/pkg/commands/strlen.ts +0 -10
  199. package/pkg/commands/sunion.test.ts +0 -22
  200. package/pkg/commands/sunion.ts +0 -10
  201. package/pkg/commands/sunionstore.test.ts +0 -29
  202. package/pkg/commands/sunionstore.ts +0 -10
  203. package/pkg/commands/time.test.ts +0 -11
  204. package/pkg/commands/time.ts +0 -9
  205. package/pkg/commands/touch.test.ts +0 -20
  206. package/pkg/commands/touch.ts +0 -10
  207. package/pkg/commands/ttl.test.ts +0 -17
  208. package/pkg/commands/ttl.ts +0 -10
  209. package/pkg/commands/type.test.ts +0 -72
  210. package/pkg/commands/type.ts +0 -11
  211. package/pkg/commands/unlink.test.ts +0 -21
  212. package/pkg/commands/unlink.ts +0 -10
  213. package/pkg/commands/zadd.test.ts +0 -177
  214. package/pkg/commands/zadd.ts +0 -64
  215. package/pkg/commands/zcard.test.ts +0 -15
  216. package/pkg/commands/zcard.ts +0 -10
  217. package/pkg/commands/zcount.test.ts +0 -15
  218. package/pkg/commands/zcount.ts +0 -9
  219. package/pkg/commands/zincrby.test.ts +0 -20
  220. package/pkg/commands/zincrby.ts +0 -9
  221. package/pkg/commands/zinterstore.test.ts +0 -239
  222. package/pkg/commands/zinterstore.ts +0 -55
  223. package/pkg/commands/zlexcount.test.ts +0 -22
  224. package/pkg/commands/zlexcount.ts +0 -9
  225. package/pkg/commands/zpopmax.test.ts +0 -45
  226. package/pkg/commands/zpopmax.ts +0 -13
  227. package/pkg/commands/zpopmin.test.ts +0 -49
  228. package/pkg/commands/zpopmin.ts +0 -13
  229. package/pkg/commands/zrange.test.ts +0 -52
  230. package/pkg/commands/zrange.ts +0 -22
  231. package/pkg/commands/zrank.test.ts +0 -22
  232. package/pkg/commands/zrank.ts +0 -10
  233. package/pkg/commands/zrem.test.ts +0 -20
  234. package/pkg/commands/zrem.ts +0 -10
  235. package/pkg/commands/zremrangebylex.test.ts +0 -26
  236. package/pkg/commands/zremrangebylex.ts +0 -9
  237. package/pkg/commands/zremrangebyrank.test.ts +0 -27
  238. package/pkg/commands/zremrangebyrank.ts +0 -9
  239. package/pkg/commands/zremrangebyscore.test.ts +0 -24
  240. package/pkg/commands/zremrangebyscore.ts +0 -9
  241. package/pkg/commands/zrevrank.test.ts +0 -22
  242. package/pkg/commands/zrevrank.ts +0 -10
  243. package/pkg/commands/zscan.test.ts +0 -50
  244. package/pkg/commands/zscan.ts +0 -22
  245. package/pkg/commands/zscore.test.ts +0 -18
  246. package/pkg/commands/zscore.ts +0 -10
  247. package/pkg/commands/zunionstore.test.ts +0 -215
  248. package/pkg/commands/zunionstore.ts +0 -55
  249. package/pkg/commands/zz.ts +0 -1
  250. package/pkg/error.ts +0 -9
  251. package/pkg/fastly.ts +0 -54
  252. package/pkg/http.test.ts +0 -34
  253. package/pkg/http.ts +0 -62
  254. package/pkg/index.ts +0 -2
  255. package/pkg/nodejs.ts +0 -83
  256. package/pkg/pipeline.test.ts +0 -177
  257. package/pkg/pipeline.ts +0 -999
  258. package/pkg/redis.ts +0 -930
  259. package/pkg/test-utils.ts +0 -41
  260. package/pkg/types.ts +0 -4
  261. package/pkg/util.ts +0 -22
  262. package/pnpm-lock.yaml +0 -3940
  263. package/tsconfig.json +0 -100
  264. package/tsconfig.module.json +0 -8
  265. package/tsup.config.ts +0 -16
@@ -1,47 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { HSetCommand } from "./hset"
5
- import { HGetCommand } from "./hget"
6
-
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- it("gets an exiting value", async () => {
13
- const key = newKey()
14
- const field = randomUUID()
15
- const value = randomUUID()
16
- await new HSetCommand(key, field, value).exec(client)
17
- const res = await new HGetCommand(key, field).exec(client)
18
-
19
- expect(res).toEqual(value)
20
- })
21
-
22
- it("gets a non-existing hash", async () => {
23
- const key = newKey()
24
- const field = randomUUID()
25
- const res = await new HGetCommand(key, field).exec(client)
26
-
27
- expect(res).toBeNull()
28
- })
29
-
30
- it("gets a non-existing field", async () => {
31
- const key = newKey()
32
- const field = randomUUID()
33
- await new HSetCommand(key, randomUUID(), randomUUID()).exec(client)
34
- const res = await new HGetCommand(key, field).exec(client)
35
-
36
- expect(res).toBeNull()
37
- })
38
-
39
- it("gets an object", async () => {
40
- const key = newKey()
41
- const field = randomUUID()
42
- const value = { v: randomUUID() }
43
- await new HSetCommand(key, field, value).exec(client)
44
- const res = await new HGetCommand(key, field).exec(client)
45
-
46
- expect(res).toEqual(value)
47
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hget
5
- */
6
- export class HGetCommand<TData> extends Command<TData | null, unknown | null> {
7
- constructor(key: string, field: string) {
8
- super(["hget", key, field])
9
- }
10
- }
@@ -1,32 +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 { HSetCommand } from "./hset"
5
- import { HGetAllCommand } from "./hgetall"
6
-
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
- it("returns all fields", async () => {
12
- const key = newKey()
13
- const field2 = randomUUID()
14
- const field1 = randomUUID()
15
- const value1 = false
16
- const value2 = randomUUID()
17
- await new HSetCommand(key, field1, value1).exec(client)
18
- await new HSetCommand(key, field2, value2).exec(client)
19
- const res = await new HGetAllCommand(key).exec(client)
20
-
21
- const obj = {
22
- [field1]: value1,
23
- [field2]: value2,
24
- }
25
- expect(res).toEqual(obj)
26
- })
27
- describe("when hash does not exist", () => {
28
- it("it returns null", async () => {
29
- const res = await new HGetAllCommand(randomUUID()).exec(client)
30
- expect(res).toBeNull()
31
- })
32
- })
@@ -1,35 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- *
5
- * @param result De
6
- * @returns
7
- */
8
- function deserialize<TData extends Record<string, unknown>>(result: string[]): TData | null {
9
- if (result.length === 0) {
10
- return null
11
- }
12
- const obj: Record<string, unknown> = {}
13
- while (result.length >= 2) {
14
- const key = result.shift()!
15
- const value = result.shift()!
16
- try {
17
- obj[key] = JSON.parse(value)
18
- } catch {
19
- obj[key] = value
20
- }
21
- }
22
- return obj as TData
23
- }
24
-
25
- /**
26
- * @see https://redis.io/commands/hgetall
27
- */
28
- export class HGetAllCommand<TData extends Record<string, unknown>> extends Command<
29
- TData | null,
30
- unknown | null
31
- > {
32
- constructor(key: string) {
33
- super(["hgetall", key], { deserialize: (result) => deserialize<TData>(result as string[]) })
34
- }
35
- }
@@ -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
-
5
- import { HSetCommand } from "./hset"
6
- import { HIncrByCommand } from "./hincrby"
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- it("increments a non-existing value", async () => {
13
- const key = newKey()
14
- const field = randomUUID()
15
- const res = await new HIncrByCommand(key, field, 2).exec(client)
16
-
17
- expect(res).toEqual(2)
18
- })
19
-
20
- it("increments and existing value", async () => {
21
- const key = newKey()
22
- const field = randomUUID()
23
- await new HSetCommand(key, field, 5).exec(client)
24
- const res = await new HIncrByCommand(key, field, 2).exec(client)
25
-
26
- expect(res).toEqual(7)
27
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hincrby
5
- */
6
- export class HIncrByCommand extends Command<number, number> {
7
- constructor(key: string, field: string, increment: number) {
8
- super(["hincrby", key, field, increment])
9
- }
10
- }
@@ -1,25 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { HIncrByFloatCommand } from "./hincrbyfloat"
5
- import { HSetCommand } from "./hset"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
- it("increments a non-existing value", async () => {
11
- const key = newKey()
12
- const field = randomUUID()
13
- const res = await new HIncrByFloatCommand(key, field, 2.5).exec(client)
14
-
15
- expect(res).toEqual(2.5)
16
- })
17
-
18
- it("increments and existing value", async () => {
19
- const key = newKey()
20
- const field = randomUUID()
21
- await new HSetCommand(key, field, 5).exec(client)
22
- const res = await new HIncrByFloatCommand(key, field, 2.5).exec(client)
23
-
24
- expect(res).toEqual(7.5)
25
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hincrbyfloat
5
- */
6
- export class HIncrByFloatCommand extends Command<number, number> {
7
- constructor(key: string, field: string, increment: number) {
8
- super(["hincrbyfloat", key, field, increment])
9
- }
10
- }
@@ -1,22 +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 { HMSetCommand } from "./hmset"
5
- import { HKeysCommand } from "./hkeys"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- describe("with existing hash", () => {
12
- it("returns all keys", async () => {
13
- const key = newKey()
14
- const kv = {
15
- [randomUUID()]: randomUUID(),
16
- [randomUUID()]: randomUUID(),
17
- }
18
- await new HMSetCommand(key, kv).exec(client)
19
- const res = await new HKeysCommand(key).exec(client)
20
- expect(res.sort()).toEqual(Object.keys(kv).sort())
21
- })
22
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hkeys
5
- */
6
- export class HKeysCommand extends Command<string[], string[]> {
7
- constructor(key: string) {
8
- super(["hkeys", key])
9
- }
10
- }
@@ -1,24 +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 { HMSetCommand } from "./hmset"
5
- import { HLenCommand } from "./hlen"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- describe("with existing hash", () => {
12
- it("returns correct number of keys", async () => {
13
- const key = newKey()
14
- const field1 = randomUUID()
15
- const field2 = randomUUID()
16
-
17
- const kv: Record<string, string> = {}
18
- kv[field1] = randomUUID()
19
- kv[field2] = randomUUID()
20
- await new HMSetCommand(key, kv).exec(client)
21
- const res = await new HLenCommand(key).exec(client)
22
- expect(res).toEqual(2)
23
- })
24
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hlen
5
- */
6
- export class HLenCommand extends Command<number, number> {
7
- constructor(key: string) {
8
- super(["hlen", key])
9
- }
10
- }
@@ -1,48 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, describe, afterAll } from "@jest/globals"
4
-
5
- import { HMSetCommand } from "./hmset"
6
- import { HMGetCommand } from "./hmget"
7
- import { HSetCommand } from "./hset"
8
- const client = newHttpClient()
9
-
10
- const { newKey, cleanup } = keygen()
11
- afterAll(cleanup)
12
-
13
- it("gets exiting values", async () => {
14
- const key = newKey()
15
- const field1 = randomUUID()
16
- const value1 = randomUUID()
17
- const field2 = randomUUID()
18
- const value2 = randomUUID()
19
- const kv: Record<string, string> = {
20
- [field1]: value1,
21
- [field2]: value2,
22
- }
23
- const res = await new HMSetCommand(key, kv).exec(client)
24
-
25
- expect(res).toEqual("OK")
26
- const res2 = await new HMGetCommand(key, field1, field2).exec(client)
27
-
28
- expect(res2).toEqual(kv)
29
- })
30
-
31
- describe("when the hash does not exist", () => {
32
- it("returns null", async () => {
33
- const key = newKey()
34
- const res = await new HMGetCommand(key, randomUUID()).exec(client)
35
-
36
- expect(res).toBeNull()
37
- })
38
- })
39
-
40
- it("gets an object", async () => {
41
- const key = newKey()
42
- const field = randomUUID()
43
- const value = { v: randomUUID() }
44
- await new HSetCommand(key, field, value).exec(client)
45
- const cmd = new HMGetCommand(key, field)
46
- const res = await cmd.exec(client)
47
- expect(res).toEqual({ [field]: value })
48
- })
@@ -1,41 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- function deserialize<TData extends Record<string, unknown>>(
4
- fields: string[],
5
- result: (string | null)[],
6
- ): TData | null {
7
- if (result.length === 0 || result.every((field) => field === null)) {
8
- return null
9
- }
10
- const obj: Record<string, unknown> = {}
11
- for (let i = 0; i < fields.length; i++) {
12
- try {
13
- obj[fields[i]] = JSON.parse(result[i]!)
14
- } catch {
15
- obj[fields[i]] = result[i]
16
- }
17
- }
18
- return obj as TData
19
- }
20
-
21
- /**
22
- * hmget returns an object of all requested fields from a hash
23
- * The field values are returned as an object like this:
24
- * ```ts
25
- * {[fieldName: string]: T | null}
26
- * ```
27
- *
28
- * In case the hash does not exist or all fields are empty `null` is returned
29
- *
30
- * @see https://redis.io/commands/hmget
31
- */
32
- export class HMGetCommand<TData extends Record<string, unknown>> extends Command<
33
- TData | null,
34
- (string | null)[]
35
- > {
36
- constructor(key: string, ...fields: string[]) {
37
- super(["hmget", key, ...fields], {
38
- deserialize: (result) => deserialize<TData>(fields, result),
39
- })
40
- }
41
- }
@@ -1,24 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { HMSetCommand } from "./hmset"
5
- import { HMGetCommand } from "./hmget"
6
-
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- it("gets exiting values", async () => {
13
- const key = newKey()
14
- const kv = {
15
- [randomUUID()]: randomUUID(),
16
- [randomUUID()]: randomUUID(),
17
- }
18
- const res = await new HMSetCommand(key, kv).exec(client)
19
-
20
- expect(res).toEqual("OK")
21
- const res2 = await new HMGetCommand(key, ...Object.keys(kv)).exec(client)
22
-
23
- expect(res2).toEqual(kv)
24
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hmset
5
- */
6
- export class HMSetCommand<TData> extends Command<number, number> {
7
- constructor(key: string, kv: { [field: string]: TData }) {
8
- super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])])
9
- }
10
- }
@@ -1,46 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, describe, expect, afterAll } from "@jest/globals"
3
- import { HSetCommand } from "./hset"
4
- import { HScanCommand } from "./hscan"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
- describe("without options", () => {
10
- it("returns cursor and members", async () => {
11
- const key = newKey()
12
- await new HSetCommand(key, "field", "value").exec(client)
13
- const res = await new HScanCommand(key, 0).exec(client)
14
-
15
- expect(res).toBeDefined()
16
- expect(res.length).toBe(2)
17
- expect(typeof res[0]).toBe("number")
18
- expect(res![1].length).toBeGreaterThan(0)
19
- })
20
- })
21
-
22
- describe("with match", () => {
23
- it("returns cursor and members", async () => {
24
- const key = newKey()
25
- await new HSetCommand(key, "field", "value").exec(client)
26
- const res = await new HScanCommand(key, 0, { match: "field" }).exec(client)
27
-
28
- expect(res).toBeDefined()
29
- expect(res.length).toBe(2)
30
- expect(typeof res[0]).toBe("number")
31
- expect(res![1].length).toBeGreaterThan(0)
32
- })
33
- })
34
-
35
- describe("with count", () => {
36
- it("returns cursor and members", async () => {
37
- const key = newKey()
38
- await new HSetCommand(key, "field", "value").exec(client)
39
- const res = await new HScanCommand(key, 0, { count: 1 }).exec(client)
40
-
41
- expect(res).toBeDefined()
42
- expect(res.length).toBe(2)
43
- expect(typeof res[0]).toBe("number")
44
- expect(res![1].length).toBeGreaterThan(0)
45
- })
46
- })
@@ -1,22 +0,0 @@
1
- import { ScanCommandOptions } from "./scan"
2
- import { Command } from "../command"
3
-
4
- /**
5
- * @see https://redis.io/commands/hscan
6
- */
7
- export class HScanCommand extends Command<
8
- [number, (string | number)[]],
9
- [number, (string | number)[]]
10
- > {
11
- constructor(key: string, cursor: number, opts?: ScanCommandOptions) {
12
- const command = ["hscan", 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,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 { HSetCommand } from "./hset"
5
- import { HGetCommand } from "./hget"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
- it("sets value", async () => {
11
- const key = newKey()
12
- const field = randomUUID()
13
- const value = randomUUID()
14
-
15
- const res = await new HSetCommand(key, field, value).exec(client)
16
-
17
- expect(res).toEqual(1)
18
- const res2 = await new HGetCommand(key, field).exec(client)
19
-
20
- expect(res2).toEqual(value)
21
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hset
5
- */
6
- export class HSetCommand<TData> extends Command<number, number> {
7
- constructor(key: string, field: string, value: TData) {
8
- super(["hset", key, field, value])
9
- }
10
- }
@@ -1,37 +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 { HSetCommand } from "./hset"
5
- import { HGetCommand } from "./hget"
6
- import { HSetNXCommand } from "./hsetnx"
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- describe("when hash exists already", () => {
13
- it("returns 0", async () => {
14
- const key = newKey()
15
- const field = randomUUID()
16
- const value = randomUUID()
17
- const newValue = randomUUID()
18
- await new HSetCommand(key, field, value).exec(client)
19
- const res = await new HSetNXCommand(key, field, newValue).exec(client)
20
- expect(res).toBe(0)
21
- const res2 = await new HGetCommand(key, field).exec(client)
22
-
23
- expect(res2).toEqual(value)
24
- })
25
- })
26
- describe("when hash does not exist", () => {
27
- it("returns 1", async () => {
28
- const key = newKey()
29
- const field = randomUUID()
30
- const value = randomUUID()
31
- const res = await new HSetNXCommand(key, field, value).exec(client)
32
- expect(res).toBe(1)
33
- const res2 = await new HGetCommand(key, field).exec(client)
34
-
35
- expect(res2).toEqual(value)
36
- })
37
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hsetnx
5
- */
6
- export class HSetNXCommand<TData> extends Command<0 | 1, "0" | "1"> {
7
- constructor(key: string, field: string, value: TData) {
8
- super(["hsetnx", key, field, value])
9
- }
10
- }
@@ -1,24 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
-
5
- import { HStrLenCommand } from "./hstrlen"
6
- import { HSetCommand } from "./hset"
7
-
8
- const client = newHttpClient()
9
-
10
- const { newKey, cleanup } = keygen()
11
- afterAll(cleanup)
12
- it("returns correct length", async () => {
13
- const key = newKey()
14
- const field = randomUUID()
15
- const value = randomUUID()
16
-
17
- const res = await new HStrLenCommand(key, field).exec(client)
18
- expect(res).toBe(0)
19
- await new HSetCommand(key, field, value).exec(client)
20
-
21
- const res2 = await new HStrLenCommand(key, field).exec(client)
22
-
23
- expect(res2).toBe(36)
24
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hstrlen
5
- */
6
- export class HStrLenCommand extends Command<number, number> {
7
- constructor(key: string, field: string) {
8
- super(["hstrlen", key, field])
9
- }
10
- }
@@ -1,23 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { HValsCommand } from "./hvals"
5
- import { HSetCommand } from "./hset"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- it("returns correct length", async () => {
12
- const key = newKey()
13
- const field = randomUUID()
14
- const value = randomUUID()
15
-
16
- const res = await new HValsCommand(key).exec(client)
17
- expect(res).toEqual([])
18
- await new HSetCommand(key, field, value).exec(client)
19
-
20
- const res2 = await new HValsCommand(key).exec(client)
21
-
22
- expect(res2).toEqual([value])
23
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/hvals
5
- */
6
- export class HValsCommand<TData extends unknown[]> extends Command<TData, unknown[]> {
7
- constructor(key: string) {
8
- super(["hvals", key])
9
- }
10
- }
@@ -1,23 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { SetCommand } from "./set"
4
- import { IncrCommand } from "./incr"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- it("increments a non-existing value", async () => {
11
- const key = newKey()
12
- const res = await new IncrCommand(key).exec(client)
13
-
14
- expect(res).toEqual(1)
15
- })
16
-
17
- it("increments and existing value", async () => {
18
- const key = newKey()
19
- await new SetCommand(key, 4).exec(client)
20
- const res = await new IncrCommand(key).exec(client)
21
-
22
- expect(res).toEqual(5)
23
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/incr
5
- */
6
- export class IncrCommand extends Command<number, number> {
7
- constructor(key: string) {
8
- super(["incr", key])
9
- }
10
- }