@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,28 +0,0 @@
1
- import { AppendCommand } from "./append"
2
- import { keygen, newHttpClient } from "../test-utils"
3
- import { randomUUID } from "crypto"
4
- import { describe, it, expect, afterAll } from "@jest/globals"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- describe("when key is not set", () => {
11
- it("appends to empty value", async () => {
12
- const key = newKey()
13
- const value = randomUUID()
14
- const res = await new AppendCommand(key, value).exec(client)
15
- expect(res).toEqual(value.length)
16
- })
17
- })
18
-
19
- describe("when key is set", () => {
20
- it("appends to existing value", async () => {
21
- const key = newKey()
22
- const value = randomUUID()
23
- const res = await new AppendCommand(key, value).exec(client)
24
- expect(res).toEqual(value.length)
25
- const res2 = await new AppendCommand(key, "_").exec(client)
26
- expect(res2).toEqual(value.length + 1)
27
- })
28
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/append
5
- */
6
- export class AppendCommand extends Command<number, number> {
7
- constructor(key: string, value: string) {
8
- super(["append", key, value])
9
- }
10
- }
@@ -1,36 +0,0 @@
1
- import { BitCountCommand } from "./bitcount"
2
- import { keygen, newHttpClient } from "../test-utils"
3
- import { describe, it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- describe("when key is not set", () => {
11
- it("returns 0", async () => {
12
- const key = newKey()
13
- const res = await new BitCountCommand(key).exec(client)
14
- expect(res).toEqual(0)
15
- })
16
- })
17
-
18
- describe("when key is set", () => {
19
- it("returns bitcount", async () => {
20
- const key = newKey()
21
- const value = "Hello World"
22
- await new SetCommand(key, value).exec(client)
23
- const res = await new BitCountCommand(key).exec(client)
24
- expect(res).toEqual(43)
25
- })
26
-
27
- describe("with start and end", () => {
28
- it("returns bitcount", async () => {
29
- const key = newKey()
30
- const value = "Hello World"
31
- await new SetCommand(key, value).exec(client)
32
- const res = await new BitCountCommand(key, 4, 8).exec(client)
33
- expect(res).toEqual(22)
34
- })
35
- })
36
- })
@@ -1,19 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/bitcount
5
- */
6
- export class BitCountCommand extends Command<number, number> {
7
- constructor(key: string, start?: never, end?: never)
8
- constructor(key: string, start: number, end: number)
9
- constructor(key: string, start?: number, end?: number) {
10
- const command: unknown[] = ["bitcount", key]
11
- if (typeof start === "number") {
12
- command.push(start)
13
- }
14
- if (typeof end === "number") {
15
- command.push(end)
16
- }
17
- super(command)
18
- }
19
- }
@@ -1,44 +0,0 @@
1
- import { BitOpCommand } from "./bitop"
2
- import { keygen, newHttpClient } from "../test-utils"
3
- import { describe, it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- describe("when key is not set", () => {
11
- it("returns 0", async () => {
12
- const source = newKey()
13
- const dest = newKey()
14
- const res = await new BitOpCommand("and", dest, source).exec(client)
15
- expect(res).toEqual(0)
16
- })
17
- })
18
-
19
- describe("when key is set", () => {
20
- describe("not", () => {
21
- it("inverts all bits", async () => {
22
- const source = newKey()
23
- const sourcevalue = "Hello World"
24
- const dest = newKey()
25
- const destValue = "foo: bar"
26
- await new SetCommand(source, sourcevalue).exec(client)
27
- await new SetCommand(dest, destValue).exec(client)
28
- const res = await new BitOpCommand("not", dest, source).exec(client)
29
- expect(res).toEqual(11)
30
- })
31
- })
32
- describe("and", () => {
33
- it("works", async () => {
34
- const source = newKey()
35
- const sourcevalue = "Hello World"
36
- const dest = newKey()
37
- const destValue = "foo: bar"
38
- await new SetCommand(source, sourcevalue).exec(client)
39
- await new SetCommand(dest, destValue).exec(client)
40
- const res = await new BitOpCommand("and", dest, source).exec(client)
41
- expect(res).toEqual(11)
42
- })
43
- })
44
- })
@@ -1,22 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/bitop
5
- */
6
- export class BitOpCommand extends Command<number, number> {
7
- constructor(
8
- op: "and" | "or" | "xor",
9
- destinationKey: string,
10
- sourceKey: string,
11
- ...sourceKeys: string[]
12
- )
13
- constructor(op: "not", destinationKey: string, sourceKey: string)
14
- constructor(
15
- op: "and" | "or" | "xor" | "not",
16
- destinationKey: string,
17
- sourceKey: string,
18
- ...sourceKeys: string[]
19
- ) {
20
- super(["bitop", op, destinationKey, sourceKey, ...sourceKeys])
21
- }
22
- }
@@ -1,26 +0,0 @@
1
- import { BitPosCommand } from "./bitpos"
2
- import { keygen, newHttpClient } from "../test-utils"
3
- import { describe, it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- describe("when key is not set", () => {
11
- it("returns 0", async () => {
12
- const key = newKey()
13
- const res = await new BitPosCommand(key, 1, 1).exec(client)
14
- expect(res).toEqual(-1)
15
- })
16
- })
17
-
18
- describe("when key is set", () => {
19
- it("returns position of first set bit", async () => {
20
- const key = newKey()
21
- const value = "Hello World"
22
- await new SetCommand(key, value).exec(client)
23
- const res = await new BitPosCommand(key, 2, 3).exec(client)
24
- expect(res).toEqual(24)
25
- })
26
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/bitpos
5
- */
6
- export class BitPosCommand extends Command<number, number> {
7
- constructor(key: string, start: number, end: number) {
8
- super(["bitpos", key, start, end])
9
- }
10
- }
@@ -1,17 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- import { DBSizeCommand } from "./dbsize"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- it("returns the db size", async () => {
12
- const key = newKey()
13
- const value = randomUUID()
14
- await new SetCommand(key, value).exec(client)
15
- const res = await new DBSizeCommand().exec(client)
16
- expect(res).toBeGreaterThan(0)
17
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/dbsize
5
- */
6
- export class DBSizeCommand extends Command<number, number> {
7
- constructor() {
8
- super(["dbsize"])
9
- }
10
- }
@@ -1,22 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { SetCommand } from "./set"
4
- import { DecrCommand } from "./decr"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
- it("decrements a non-existing value", async () => {
10
- const key = newKey()
11
- const res = await new DecrCommand(key).exec(client)
12
-
13
- expect(res).toEqual(-1)
14
- })
15
-
16
- it("decrements and existing value", async () => {
17
- const key = newKey()
18
- await new SetCommand(key, 4).exec(client)
19
- const res = await new DecrCommand(key).exec(client)
20
-
21
- expect(res).toEqual(3)
22
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/decr
5
- */
6
- export class DecrCommand extends Command<number, number> {
7
- constructor(key: string) {
8
- super(["decr", key])
9
- }
10
- }
@@ -1,23 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { SetCommand } from "./set"
3
- import { DecrByCommand } from "./decrby"
4
- import { it, expect, afterAll } from "@jest/globals"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- it("decrements a non-existing value", async () => {
11
- const key = newKey()
12
- const res = await new DecrByCommand(key, 2).exec(client)
13
-
14
- expect(res).toEqual(-2)
15
- })
16
-
17
- it("decrements and existing value", async () => {
18
- const key = newKey()
19
- await new SetCommand(key, 5).exec(client)
20
- const res = await new DecrByCommand(key, 2).exec(client)
21
-
22
- expect(res).toEqual(3)
23
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/decrby
5
- */
6
- export class DecrByCommand extends Command<number, number> {
7
- constructor(key: string, decrement: number) {
8
- super(["decrby", key, decrement])
9
- }
10
- }
@@ -1,38 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
-
3
- import { DelCommand } from "./del"
4
- import { SetCommand } from "./set"
5
- import { describe, it, expect, afterAll } from "@jest/globals"
6
-
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- describe("when key does not exist", () => {
13
- it("does nothing", async () => {
14
- const key = newKey()
15
-
16
- const res = await new DelCommand(key).exec(client)
17
- expect(res).toEqual(0)
18
- })
19
- })
20
- describe("when key does exist", () => {
21
- it("deletes the key", async () => {
22
- const key = newKey()
23
- await new SetCommand(key, "value").exec(client)
24
- const res = await new DelCommand(key).exec(client)
25
- expect(res).toEqual(1)
26
- })
27
- })
28
- describe("with multiple keys", () => {
29
- describe("when one does not exist", () => {
30
- it("deletes all keys", async () => {
31
- const key1 = newKey()
32
- const key2 = newKey()
33
- await new SetCommand(key1, "value").exec(client)
34
- const res = await new DelCommand(key1, key2).exec(client)
35
- expect(res).toEqual(1)
36
- })
37
- })
38
- })
@@ -1,11 +0,0 @@
1
- import { NonEmptyArray } from "../types"
2
- import { Command } from "../command"
3
-
4
- /**
5
- * @see https://redis.io/commands/del
6
- */
7
- export class DelCommand extends Command<number, number> {
8
- constructor(...keys: NonEmptyArray<string>) {
9
- super(["del", ...keys])
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect } from "@jest/globals"
4
- import { EchoCommand } from "./echo"
5
- const client = newHttpClient()
6
-
7
- it("returns the message", async () => {
8
- const message = randomUUID()
9
- const res = await new EchoCommand(message).exec(client)
10
- expect(res).toBe(message)
11
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/echo
5
- */
6
- export class EchoCommand extends Command<string, string> {
7
- constructor(message: string) {
8
- super(["echo", message])
9
- }
10
- }
@@ -1,37 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { ExistsCommand } from "./exists"
3
- import { describe, it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
-
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- describe("when the key does not eist", () => {
12
- it("it returns 1", async () => {
13
- const key = newKey()
14
-
15
- const res = await new ExistsCommand(key).exec(client)
16
- expect(res).toEqual(0)
17
- })
18
- })
19
- describe("when the key exists", () => {
20
- it("it returns 1", async () => {
21
- const key = newKey()
22
- await new SetCommand(key, "value").exec(client)
23
- const res = await new ExistsCommand(key).exec(client)
24
- expect(res).toEqual(1)
25
- })
26
- })
27
- describe("with multiple keys", () => {
28
- it("it returns the number of found keys", async () => {
29
- const key1 = newKey()
30
- const key2 = newKey()
31
- const key3 = newKey()
32
- await new SetCommand(key1, "value").exec(client)
33
- await new SetCommand(key2, "value").exec(client)
34
- const res = await new ExistsCommand(key1, key2, key3).exec(client)
35
- expect(res).toEqual(2)
36
- })
37
- })
@@ -1,11 +0,0 @@
1
- import { NonEmptyArray } from "../types"
2
- import { Command } from "../command"
3
-
4
- /**
5
- * @see https://redis.io/commands/exists
6
- */
7
- export class ExistsCommand extends Command<0 | 1, "0" | "1"> {
8
- constructor(...keys: NonEmptyArray<string>) {
9
- super(["exists", ...keys])
10
- }
11
- }
@@ -1,22 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- import { ExpireCommand } from "./expire"
6
- import { GetCommand } from "./get"
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- it("expires a key correctly", async () => {
13
- const key = newKey()
14
- const value = randomUUID()
15
- await new SetCommand(key, value).exec(client)
16
- const res = await new ExpireCommand(key, 1).exec(client)
17
- expect(res).toEqual(1)
18
- await new Promise((res) => setTimeout(res, 2000))
19
- const res2 = await new GetCommand(key).exec(client)
20
-
21
- expect(res2).toBeNull()
22
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/expire
5
- */
6
- export class ExpireCommand extends Command<0 | 1, "0" | "1"> {
7
- constructor(key: string, seconds: number) {
8
- super(["expire", key, seconds])
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 { SetCommand } from "./set"
5
- import { GetCommand } from "./get"
6
- import { ExpireAtCommand } from "./expireat"
7
- const client = newHttpClient()
8
-
9
- const { newKey, cleanup } = keygen()
10
- afterAll(cleanup)
11
-
12
- describe("without options", () => {
13
- it("expires the key", async () => {
14
- const key = newKey()
15
- const value = randomUUID()
16
- await new SetCommand(key, value).exec(client)
17
-
18
- const res = await new ExpireAtCommand(key, 1).exec(client)
19
- expect(res).toEqual(1)
20
- await new Promise((res) => setTimeout(res, 2000))
21
- const res2 = await new GetCommand(key).exec(client)
22
- expect(res2).toBeNull
23
- })
24
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/expireat
5
- */
6
- export class ExpireAtCommand extends Command<0 | 1, "0" | "1"> {
7
- constructor(key: string, unix: number) {
8
- super(["expireat", key, unix])
9
- }
10
- }
@@ -1,17 +0,0 @@
1
- import { newHttpClient } from "../test-utils"
2
- import { describe, it, expect } from "@jest/globals"
3
- import { FlushAllCommand } from "./flushall"
4
- const client = newHttpClient()
5
-
6
- describe("without options", () => {
7
- it("flushes the db", async () => {
8
- const res = await new FlushAllCommand().exec(client)
9
- expect(res).toBe("OK")
10
- })
11
- })
12
- describe("async", () => {
13
- it("flushes the db", async () => {
14
- const res = await new FlushAllCommand({ async: true }).exec(client)
15
- expect(res).toBe("OK")
16
- })
17
- })
@@ -1,13 +0,0 @@
1
- import { Command } from "../command"
2
- /**
3
- * @see https://redis.io/commands/flushall
4
- */
5
- export class FlushAllCommand extends Command<"OK", "OK"> {
6
- constructor(opts?: { async?: boolean }) {
7
- const command = ["flushall"]
8
- if (opts?.async) {
9
- command.push("async")
10
- }
11
- super(command)
12
- }
13
- }
@@ -1,17 +0,0 @@
1
- import { newHttpClient } from "../test-utils"
2
- import { describe, it, expect } from "@jest/globals"
3
- import { FlushDBCommand } from "./flushdb"
4
- const client = newHttpClient()
5
-
6
- describe("without options", () => {
7
- it("flushes the db", async () => {
8
- const res = await new FlushDBCommand().exec(client)
9
- expect(res).toBe("OK")
10
- })
11
- })
12
- describe("async", () => {
13
- it("flushes the db", async () => {
14
- const res = await new FlushDBCommand({ async: true }).exec(client)
15
- expect(res).toBe("OK")
16
- })
17
- })
@@ -1,13 +0,0 @@
1
- import { Command } from "../command"
2
- /**
3
- * @see https://redis.io/commands/flushdb
4
- */
5
- export class FlushDBCommand extends Command<"OK", "OK"> {
6
- constructor(opts?: { async?: boolean }) {
7
- const command = ["flushdb"]
8
- if (opts?.async) {
9
- command.push("async")
10
- }
11
- super(command)
12
- }
13
- }
@@ -1,34 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { randomUUID } from "crypto"
3
- import { it, expect, afterAll } from "@jest/globals"
4
- import { SetCommand } from "./set"
5
- import { GetCommand } from "./get"
6
- const client = newHttpClient()
7
-
8
- const { newKey, cleanup } = keygen()
9
- afterAll(cleanup)
10
-
11
- it("gets an exiting value", async () => {
12
- const key = newKey()
13
- const value = randomUUID()
14
- await new SetCommand(key, value).exec(client)
15
- const res = await new GetCommand(key).exec(client)
16
-
17
- expect(res).toEqual(value)
18
- })
19
-
20
- it("gets a non-existing value", async () => {
21
- const key = newKey()
22
- const res = await new GetCommand(key).exec(client)
23
-
24
- expect(res).toBeNull()
25
- })
26
-
27
- it("gets an object", async () => {
28
- const key = newKey()
29
- const value = { v: randomUUID() }
30
- await new SetCommand(key, value).exec(client)
31
- const res = await new GetCommand(key).exec(client)
32
-
33
- expect(res).toEqual(value)
34
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/get
5
- */
6
- export class GetCommand<TData = string> extends Command<TData | null, unknown | null> {
7
- constructor(key: string) {
8
- super(["get", key])
9
- }
10
- }
@@ -1,16 +0,0 @@
1
- import { keygen, newHttpClient } from "../test-utils"
2
- import { it, expect, afterAll } from "@jest/globals"
3
- import { SetBitCommand } from "./setbit"
4
- import { GetBitCommand } from "./getbit"
5
- const client = newHttpClient()
6
-
7
- const { newKey, cleanup } = keygen()
8
- afterAll(cleanup)
9
-
10
- it("returns the bit at offset", async () => {
11
- const key = newKey()
12
-
13
- await new SetBitCommand(key, 0, 1).exec(client)
14
- const res = await new GetBitCommand(key, 0).exec(client)
15
- expect(res).toBe(1)
16
- })
@@ -1,10 +0,0 @@
1
- import { Command } from "../command"
2
-
3
- /**
4
- * @see https://redis.io/commands/getbit
5
- */
6
- export class GetBitCommand extends Command<0 | 1, "0" | "1"> {
7
- constructor(key: string, offset: number) {
8
- super(["getbit", key, offset])
9
- }
10
- }