@upstash/redis 0.0.0-ci.d2ee3690 → 0.0.0-ci.d3985e1d3f7f296ee10dff2746b51fa88dddc9a9-20251222113217

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 (395) hide show
  1. package/README.md +45 -23
  2. package/chunk-LU3F3BSG.mjs +4690 -0
  3. package/cloudflare.d.mts +55 -0
  4. package/cloudflare.d.ts +55 -0
  5. package/cloudflare.js +4796 -0
  6. package/cloudflare.mjs +97 -0
  7. package/fastly.d.mts +48 -0
  8. package/fastly.d.ts +48 -0
  9. package/fastly.js +4765 -0
  10. package/fastly.mjs +66 -0
  11. package/nodejs.d.mts +81 -0
  12. package/nodejs.d.ts +81 -0
  13. package/nodejs.js +4818 -0
  14. package/nodejs.mjs +119 -0
  15. package/package.json +1 -101
  16. package/zmscore-CSYwsf1L.d.mts +4168 -0
  17. package/zmscore-CSYwsf1L.d.ts +4168 -0
  18. package/.releaserc +0 -14
  19. package/esm/package.json +0 -3
  20. package/esm/pkg/commands/append.js +0 -9
  21. package/esm/pkg/commands/bitcount.js +0 -16
  22. package/esm/pkg/commands/bitop.js +0 -9
  23. package/esm/pkg/commands/bitpos.js +0 -9
  24. package/esm/pkg/commands/command.js +0 -57
  25. package/esm/pkg/commands/dbsize.js +0 -9
  26. package/esm/pkg/commands/decr.js +0 -9
  27. package/esm/pkg/commands/decrby.js +0 -9
  28. package/esm/pkg/commands/del.js +0 -9
  29. package/esm/pkg/commands/echo.js +0 -9
  30. package/esm/pkg/commands/eval.js +0 -9
  31. package/esm/pkg/commands/evalsha.js +0 -9
  32. package/esm/pkg/commands/exists.js +0 -9
  33. package/esm/pkg/commands/expire.js +0 -9
  34. package/esm/pkg/commands/expireat.js +0 -9
  35. package/esm/pkg/commands/flushall.js +0 -13
  36. package/esm/pkg/commands/flushdb.js +0 -13
  37. package/esm/pkg/commands/get.js +0 -9
  38. package/esm/pkg/commands/getbit.js +0 -9
  39. package/esm/pkg/commands/getrange.js +0 -9
  40. package/esm/pkg/commands/getset.js +0 -9
  41. package/esm/pkg/commands/hdel.js +0 -9
  42. package/esm/pkg/commands/hexists.js +0 -9
  43. package/esm/pkg/commands/hget.js +0 -9
  44. package/esm/pkg/commands/hgetall.js +0 -33
  45. package/esm/pkg/commands/hincrby.js +0 -9
  46. package/esm/pkg/commands/hincrbyfloat.js +0 -9
  47. package/esm/pkg/commands/hkeys.js +0 -9
  48. package/esm/pkg/commands/hlen.js +0 -9
  49. package/esm/pkg/commands/hmget.js +0 -35
  50. package/esm/pkg/commands/hmset.js +0 -13
  51. package/esm/pkg/commands/hscan.js +0 -16
  52. package/esm/pkg/commands/hset.js +0 -13
  53. package/esm/pkg/commands/hsetnx.js +0 -9
  54. package/esm/pkg/commands/hstrlen.js +0 -9
  55. package/esm/pkg/commands/hvals.js +0 -9
  56. package/esm/pkg/commands/incr.js +0 -9
  57. package/esm/pkg/commands/incrby.js +0 -9
  58. package/esm/pkg/commands/incrbyfloat.js +0 -9
  59. package/esm/pkg/commands/keys.js +0 -9
  60. package/esm/pkg/commands/lindex.js +0 -6
  61. package/esm/pkg/commands/linsert.js +0 -6
  62. package/esm/pkg/commands/llen.js +0 -9
  63. package/esm/pkg/commands/lpop.js +0 -9
  64. package/esm/pkg/commands/lpush.js +0 -9
  65. package/esm/pkg/commands/lpushx.js +0 -9
  66. package/esm/pkg/commands/lrange.js +0 -6
  67. package/esm/pkg/commands/lrem.js +0 -6
  68. package/esm/pkg/commands/lset.js +0 -6
  69. package/esm/pkg/commands/ltrim.js +0 -6
  70. package/esm/pkg/commands/mget.js +0 -9
  71. package/esm/pkg/commands/mod.js +0 -114
  72. package/esm/pkg/commands/mset.js +0 -12
  73. package/esm/pkg/commands/msetnx.js +0 -9
  74. package/esm/pkg/commands/persist.js +0 -9
  75. package/esm/pkg/commands/pexpire.js +0 -9
  76. package/esm/pkg/commands/pexpireat.js +0 -9
  77. package/esm/pkg/commands/ping.js +0 -13
  78. package/esm/pkg/commands/psetex.js +0 -9
  79. package/esm/pkg/commands/pttl.js +0 -9
  80. package/esm/pkg/commands/publish.js +0 -9
  81. package/esm/pkg/commands/randomkey.js +0 -9
  82. package/esm/pkg/commands/rename.js +0 -9
  83. package/esm/pkg/commands/renamenx.js +0 -9
  84. package/esm/pkg/commands/rpop.js +0 -9
  85. package/esm/pkg/commands/rpush.js +0 -9
  86. package/esm/pkg/commands/rpushx.js +0 -9
  87. package/esm/pkg/commands/sadd.js +0 -9
  88. package/esm/pkg/commands/scan.js +0 -16
  89. package/esm/pkg/commands/scard.js +0 -9
  90. package/esm/pkg/commands/script_exists.js +0 -12
  91. package/esm/pkg/commands/script_flush.js +0 -16
  92. package/esm/pkg/commands/script_load.js +0 -9
  93. package/esm/pkg/commands/sdiff.js +0 -9
  94. package/esm/pkg/commands/sdiffstore.js +0 -9
  95. package/esm/pkg/commands/set.js +0 -24
  96. package/esm/pkg/commands/setbit.js +0 -9
  97. package/esm/pkg/commands/setex.js +0 -9
  98. package/esm/pkg/commands/setnx.js +0 -9
  99. package/esm/pkg/commands/setrange.js +0 -9
  100. package/esm/pkg/commands/sinter.js +0 -9
  101. package/esm/pkg/commands/sinterstore.js +0 -9
  102. package/esm/pkg/commands/sismember.js +0 -9
  103. package/esm/pkg/commands/smembers.js +0 -9
  104. package/esm/pkg/commands/smove.js +0 -9
  105. package/esm/pkg/commands/spop.js +0 -13
  106. package/esm/pkg/commands/srandmember.js +0 -13
  107. package/esm/pkg/commands/srem.js +0 -9
  108. package/esm/pkg/commands/sscan.js +0 -16
  109. package/esm/pkg/commands/strlen.js +0 -9
  110. package/esm/pkg/commands/sunion.js +0 -9
  111. package/esm/pkg/commands/sunionstore.js +0 -9
  112. package/esm/pkg/commands/time.js +0 -9
  113. package/esm/pkg/commands/touch.js +0 -9
  114. package/esm/pkg/commands/ttl.js +0 -9
  115. package/esm/pkg/commands/type.js +0 -9
  116. package/esm/pkg/commands/unlink.js +0 -9
  117. package/esm/pkg/commands/zadd.js +0 -26
  118. package/esm/pkg/commands/zcard.js +0 -9
  119. package/esm/pkg/commands/zcount.js +0 -9
  120. package/esm/pkg/commands/zincrby.js +0 -9
  121. package/esm/pkg/commands/zinterstore.js +0 -27
  122. package/esm/pkg/commands/zlexcount.js +0 -9
  123. package/esm/pkg/commands/zpopmax.js +0 -13
  124. package/esm/pkg/commands/zpopmin.js +0 -13
  125. package/esm/pkg/commands/zrange.js +0 -20
  126. package/esm/pkg/commands/zrank.js +0 -9
  127. package/esm/pkg/commands/zrem.js +0 -9
  128. package/esm/pkg/commands/zremrangebylex.js +0 -9
  129. package/esm/pkg/commands/zremrangebyrank.js +0 -9
  130. package/esm/pkg/commands/zremrangebyscore.js +0 -9
  131. package/esm/pkg/commands/zrevrank.js +0 -9
  132. package/esm/pkg/commands/zscan.js +0 -16
  133. package/esm/pkg/commands/zscore.js +0 -9
  134. package/esm/pkg/commands/zunionstore.js +0 -27
  135. package/esm/pkg/error.js +0 -9
  136. package/esm/pkg/http.js +0 -77
  137. package/esm/pkg/pipeline.js +0 -1125
  138. package/esm/pkg/redis.js +0 -1067
  139. package/esm/pkg/types.js +0 -1
  140. package/esm/pkg/util.js +0 -31
  141. package/esm/platforms/cloudflare.js +0 -62
  142. package/esm/platforms/fastly.js +0 -40
  143. package/esm/platforms/node_with_fetch.js +0 -60
  144. package/esm/platforms/nodejs.js +0 -59
  145. package/script/package.json +0 -3
  146. package/script/pkg/commands/append.js +0 -13
  147. package/script/pkg/commands/bitcount.js +0 -20
  148. package/script/pkg/commands/bitop.js +0 -13
  149. package/script/pkg/commands/bitpos.js +0 -13
  150. package/script/pkg/commands/command.js +0 -61
  151. package/script/pkg/commands/dbsize.js +0 -13
  152. package/script/pkg/commands/decr.js +0 -13
  153. package/script/pkg/commands/decrby.js +0 -13
  154. package/script/pkg/commands/del.js +0 -13
  155. package/script/pkg/commands/echo.js +0 -13
  156. package/script/pkg/commands/eval.js +0 -13
  157. package/script/pkg/commands/evalsha.js +0 -13
  158. package/script/pkg/commands/exists.js +0 -13
  159. package/script/pkg/commands/expire.js +0 -13
  160. package/script/pkg/commands/expireat.js +0 -13
  161. package/script/pkg/commands/flushall.js +0 -17
  162. package/script/pkg/commands/flushdb.js +0 -17
  163. package/script/pkg/commands/get.js +0 -13
  164. package/script/pkg/commands/getbit.js +0 -13
  165. package/script/pkg/commands/getrange.js +0 -13
  166. package/script/pkg/commands/getset.js +0 -13
  167. package/script/pkg/commands/hdel.js +0 -13
  168. package/script/pkg/commands/hexists.js +0 -13
  169. package/script/pkg/commands/hget.js +0 -13
  170. package/script/pkg/commands/hgetall.js +0 -37
  171. package/script/pkg/commands/hincrby.js +0 -13
  172. package/script/pkg/commands/hincrbyfloat.js +0 -13
  173. package/script/pkg/commands/hkeys.js +0 -13
  174. package/script/pkg/commands/hlen.js +0 -13
  175. package/script/pkg/commands/hmget.js +0 -39
  176. package/script/pkg/commands/hmset.js +0 -17
  177. package/script/pkg/commands/hscan.js +0 -20
  178. package/script/pkg/commands/hset.js +0 -17
  179. package/script/pkg/commands/hsetnx.js +0 -13
  180. package/script/pkg/commands/hstrlen.js +0 -13
  181. package/script/pkg/commands/hvals.js +0 -13
  182. package/script/pkg/commands/incr.js +0 -13
  183. package/script/pkg/commands/incrby.js +0 -13
  184. package/script/pkg/commands/incrbyfloat.js +0 -13
  185. package/script/pkg/commands/keys.js +0 -13
  186. package/script/pkg/commands/lindex.js +0 -10
  187. package/script/pkg/commands/linsert.js +0 -10
  188. package/script/pkg/commands/llen.js +0 -13
  189. package/script/pkg/commands/lpop.js +0 -13
  190. package/script/pkg/commands/lpush.js +0 -13
  191. package/script/pkg/commands/lpushx.js +0 -13
  192. package/script/pkg/commands/lrange.js +0 -10
  193. package/script/pkg/commands/lrem.js +0 -10
  194. package/script/pkg/commands/lset.js +0 -10
  195. package/script/pkg/commands/ltrim.js +0 -10
  196. package/script/pkg/commands/mget.js +0 -13
  197. package/script/pkg/commands/mod.js +0 -130
  198. package/script/pkg/commands/mset.js +0 -16
  199. package/script/pkg/commands/msetnx.js +0 -13
  200. package/script/pkg/commands/persist.js +0 -13
  201. package/script/pkg/commands/pexpire.js +0 -13
  202. package/script/pkg/commands/pexpireat.js +0 -13
  203. package/script/pkg/commands/ping.js +0 -17
  204. package/script/pkg/commands/psetex.js +0 -13
  205. package/script/pkg/commands/pttl.js +0 -13
  206. package/script/pkg/commands/publish.js +0 -13
  207. package/script/pkg/commands/randomkey.js +0 -13
  208. package/script/pkg/commands/rename.js +0 -13
  209. package/script/pkg/commands/renamenx.js +0 -13
  210. package/script/pkg/commands/rpop.js +0 -13
  211. package/script/pkg/commands/rpush.js +0 -13
  212. package/script/pkg/commands/rpushx.js +0 -13
  213. package/script/pkg/commands/sadd.js +0 -13
  214. package/script/pkg/commands/scan.js +0 -20
  215. package/script/pkg/commands/scard.js +0 -13
  216. package/script/pkg/commands/script_exists.js +0 -16
  217. package/script/pkg/commands/script_flush.js +0 -20
  218. package/script/pkg/commands/script_load.js +0 -13
  219. package/script/pkg/commands/sdiff.js +0 -13
  220. package/script/pkg/commands/sdiffstore.js +0 -13
  221. package/script/pkg/commands/set.js +0 -28
  222. package/script/pkg/commands/setbit.js +0 -13
  223. package/script/pkg/commands/setex.js +0 -13
  224. package/script/pkg/commands/setnx.js +0 -13
  225. package/script/pkg/commands/setrange.js +0 -13
  226. package/script/pkg/commands/sinter.js +0 -13
  227. package/script/pkg/commands/sinterstore.js +0 -13
  228. package/script/pkg/commands/sismember.js +0 -13
  229. package/script/pkg/commands/smembers.js +0 -13
  230. package/script/pkg/commands/smove.js +0 -13
  231. package/script/pkg/commands/spop.js +0 -17
  232. package/script/pkg/commands/srandmember.js +0 -17
  233. package/script/pkg/commands/srem.js +0 -13
  234. package/script/pkg/commands/sscan.js +0 -20
  235. package/script/pkg/commands/strlen.js +0 -13
  236. package/script/pkg/commands/sunion.js +0 -13
  237. package/script/pkg/commands/sunionstore.js +0 -13
  238. package/script/pkg/commands/time.js +0 -13
  239. package/script/pkg/commands/touch.js +0 -13
  240. package/script/pkg/commands/ttl.js +0 -13
  241. package/script/pkg/commands/type.js +0 -13
  242. package/script/pkg/commands/unlink.js +0 -13
  243. package/script/pkg/commands/zadd.js +0 -30
  244. package/script/pkg/commands/zcard.js +0 -13
  245. package/script/pkg/commands/zcount.js +0 -13
  246. package/script/pkg/commands/zincrby.js +0 -13
  247. package/script/pkg/commands/zinterstore.js +0 -31
  248. package/script/pkg/commands/zlexcount.js +0 -13
  249. package/script/pkg/commands/zpopmax.js +0 -17
  250. package/script/pkg/commands/zpopmin.js +0 -17
  251. package/script/pkg/commands/zrange.js +0 -24
  252. package/script/pkg/commands/zrank.js +0 -13
  253. package/script/pkg/commands/zrem.js +0 -13
  254. package/script/pkg/commands/zremrangebylex.js +0 -13
  255. package/script/pkg/commands/zremrangebyrank.js +0 -13
  256. package/script/pkg/commands/zremrangebyscore.js +0 -13
  257. package/script/pkg/commands/zrevrank.js +0 -13
  258. package/script/pkg/commands/zscan.js +0 -20
  259. package/script/pkg/commands/zscore.js +0 -13
  260. package/script/pkg/commands/zunionstore.js +0 -31
  261. package/script/pkg/error.js +0 -13
  262. package/script/pkg/http.js +0 -81
  263. package/script/pkg/pipeline.js +0 -1129
  264. package/script/pkg/redis.js +0 -1071
  265. package/script/pkg/types.js +0 -2
  266. package/script/pkg/util.js +0 -35
  267. package/script/platforms/cloudflare.js +0 -89
  268. package/script/platforms/fastly.js +0 -67
  269. package/script/platforms/node_with_fetch.js +0 -87
  270. package/script/platforms/nodejs.js +0 -86
  271. package/types/pkg/commands/append.d.ts +0 -7
  272. package/types/pkg/commands/bitcount.d.ts +0 -8
  273. package/types/pkg/commands/bitop.d.ts +0 -13
  274. package/types/pkg/commands/bitpos.d.ts +0 -7
  275. package/types/pkg/commands/command.d.ts +0 -37
  276. package/types/pkg/commands/dbsize.d.ts +0 -7
  277. package/types/pkg/commands/decr.d.ts +0 -7
  278. package/types/pkg/commands/decrby.d.ts +0 -7
  279. package/types/pkg/commands/del.d.ts +0 -7
  280. package/types/pkg/commands/echo.d.ts +0 -7
  281. package/types/pkg/commands/eval.d.ts +0 -7
  282. package/types/pkg/commands/evalsha.d.ts +0 -7
  283. package/types/pkg/commands/exists.d.ts +0 -7
  284. package/types/pkg/commands/expire.d.ts +0 -7
  285. package/types/pkg/commands/expireat.d.ts +0 -7
  286. package/types/pkg/commands/flushall.d.ts +0 -9
  287. package/types/pkg/commands/flushdb.d.ts +0 -9
  288. package/types/pkg/commands/get.d.ts +0 -7
  289. package/types/pkg/commands/getbit.d.ts +0 -7
  290. package/types/pkg/commands/getrange.d.ts +0 -7
  291. package/types/pkg/commands/getset.d.ts +0 -7
  292. package/types/pkg/commands/hdel.d.ts +0 -7
  293. package/types/pkg/commands/hexists.d.ts +0 -7
  294. package/types/pkg/commands/hget.d.ts +0 -7
  295. package/types/pkg/commands/hgetall.d.ts +0 -7
  296. package/types/pkg/commands/hincrby.d.ts +0 -7
  297. package/types/pkg/commands/hincrbyfloat.d.ts +0 -7
  298. package/types/pkg/commands/hkeys.d.ts +0 -7
  299. package/types/pkg/commands/hlen.d.ts +0 -7
  300. package/types/pkg/commands/hmget.d.ts +0 -15
  301. package/types/pkg/commands/hmset.d.ts +0 -9
  302. package/types/pkg/commands/hscan.d.ts +0 -24
  303. package/types/pkg/commands/hset.d.ts +0 -9
  304. package/types/pkg/commands/hsetnx.d.ts +0 -7
  305. package/types/pkg/commands/hstrlen.d.ts +0 -7
  306. package/types/pkg/commands/hvals.d.ts +0 -7
  307. package/types/pkg/commands/incr.d.ts +0 -7
  308. package/types/pkg/commands/incrby.d.ts +0 -7
  309. package/types/pkg/commands/incrbyfloat.d.ts +0 -7
  310. package/types/pkg/commands/keys.d.ts +0 -7
  311. package/types/pkg/commands/lindex.d.ts +0 -4
  312. package/types/pkg/commands/linsert.d.ts +0 -9
  313. package/types/pkg/commands/llen.d.ts +0 -7
  314. package/types/pkg/commands/lpop.d.ts +0 -7
  315. package/types/pkg/commands/lpush.d.ts +0 -7
  316. package/types/pkg/commands/lpushx.d.ts +0 -7
  317. package/types/pkg/commands/lrange.d.ts +0 -4
  318. package/types/pkg/commands/lrem.d.ts +0 -4
  319. package/types/pkg/commands/lset.d.ts +0 -4
  320. package/types/pkg/commands/ltrim.d.ts +0 -4
  321. package/types/pkg/commands/mget.d.ts +0 -7
  322. package/types/pkg/commands/mod.d.ts +0 -114
  323. package/types/pkg/commands/mset.d.ts +0 -9
  324. package/types/pkg/commands/msetnx.d.ts +0 -9
  325. package/types/pkg/commands/persist.d.ts +0 -7
  326. package/types/pkg/commands/pexpire.d.ts +0 -7
  327. package/types/pkg/commands/pexpireat.d.ts +0 -7
  328. package/types/pkg/commands/ping.d.ts +0 -7
  329. package/types/pkg/commands/psetex.d.ts +0 -7
  330. package/types/pkg/commands/pttl.d.ts +0 -7
  331. package/types/pkg/commands/publish.d.ts +0 -7
  332. package/types/pkg/commands/randomkey.d.ts +0 -7
  333. package/types/pkg/commands/rename.d.ts +0 -7
  334. package/types/pkg/commands/renamenx.d.ts +0 -7
  335. package/types/pkg/commands/rpop.d.ts +0 -7
  336. package/types/pkg/commands/rpush.d.ts +0 -7
  337. package/types/pkg/commands/rpushx.d.ts +0 -7
  338. package/types/pkg/commands/sadd.d.ts +0 -7
  339. package/types/pkg/commands/scan.d.ts +0 -17
  340. package/types/pkg/commands/scard.d.ts +0 -7
  341. package/types/pkg/commands/script_exists.d.ts +0 -7
  342. package/types/pkg/commands/script_flush.d.ts +0 -14
  343. package/types/pkg/commands/script_load.d.ts +0 -7
  344. package/types/pkg/commands/sdiff.d.ts +0 -7
  345. package/types/pkg/commands/sdiffstore.d.ts +0 -7
  346. package/types/pkg/commands/set.d.ts +0 -26
  347. package/types/pkg/commands/setbit.d.ts +0 -7
  348. package/types/pkg/commands/setex.d.ts +0 -7
  349. package/types/pkg/commands/setnx.d.ts +0 -7
  350. package/types/pkg/commands/setrange.d.ts +0 -7
  351. package/types/pkg/commands/sinter.d.ts +0 -7
  352. package/types/pkg/commands/sinterstore.d.ts +0 -7
  353. package/types/pkg/commands/sismember.d.ts +0 -7
  354. package/types/pkg/commands/smembers.d.ts +0 -7
  355. package/types/pkg/commands/smove.d.ts +0 -7
  356. package/types/pkg/commands/spop.d.ts +0 -7
  357. package/types/pkg/commands/srandmember.d.ts +0 -7
  358. package/types/pkg/commands/srem.d.ts +0 -7
  359. package/types/pkg/commands/sscan.d.ts +0 -24
  360. package/types/pkg/commands/strlen.d.ts +0 -7
  361. package/types/pkg/commands/sunion.d.ts +0 -7
  362. package/types/pkg/commands/sunionstore.d.ts +0 -7
  363. package/types/pkg/commands/time.d.ts +0 -7
  364. package/types/pkg/commands/touch.d.ts +0 -7
  365. package/types/pkg/commands/ttl.d.ts +0 -7
  366. package/types/pkg/commands/type.d.ts +0 -8
  367. package/types/pkg/commands/unlink.d.ts +0 -7
  368. package/types/pkg/commands/zadd.d.ts +0 -35
  369. package/types/pkg/commands/zcard.d.ts +0 -7
  370. package/types/pkg/commands/zcount.d.ts +0 -7
  371. package/types/pkg/commands/zincrby.d.ts +0 -7
  372. package/types/pkg/commands/zinterstore.d.ts +0 -30
  373. package/types/pkg/commands/zlexcount.d.ts +0 -7
  374. package/types/pkg/commands/zpopmax.d.ts +0 -7
  375. package/types/pkg/commands/zpopmin.d.ts +0 -7
  376. package/types/pkg/commands/zrange.d.ts +0 -35
  377. package/types/pkg/commands/zrank.d.ts +0 -7
  378. package/types/pkg/commands/zrem.d.ts +0 -7
  379. package/types/pkg/commands/zremrangebylex.d.ts +0 -7
  380. package/types/pkg/commands/zremrangebyrank.d.ts +0 -7
  381. package/types/pkg/commands/zremrangebyscore.d.ts +0 -7
  382. package/types/pkg/commands/zrevrank.d.ts +0 -7
  383. package/types/pkg/commands/zscan.d.ts +0 -24
  384. package/types/pkg/commands/zscore.d.ts +0 -7
  385. package/types/pkg/commands/zunionstore.d.ts +0 -30
  386. package/types/pkg/error.d.ts +0 -6
  387. package/types/pkg/http.d.ts +0 -54
  388. package/types/pkg/pipeline.d.ts +0 -540
  389. package/types/pkg/redis.d.ts +0 -516
  390. package/types/pkg/types.d.ts +0 -1
  391. package/types/pkg/util.d.ts +0 -1
  392. package/types/platforms/cloudflare.d.ts +0 -42
  393. package/types/platforms/fastly.d.ts +0 -45
  394. package/types/platforms/node_with_fetch.d.ts +0 -82
  395. package/types/platforms/nodejs.d.ts +0 -81
package/cloudflare.js ADDED
@@ -0,0 +1,4796 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // platforms/cloudflare.ts
21
+ var cloudflare_exports = {};
22
+ __export(cloudflare_exports, {
23
+ Redis: () => Redis2,
24
+ errors: () => error_exports
25
+ });
26
+ module.exports = __toCommonJS(cloudflare_exports);
27
+
28
+ // pkg/error.ts
29
+ var error_exports = {};
30
+ __export(error_exports, {
31
+ UpstashError: () => UpstashError,
32
+ UpstashJSONParseError: () => UpstashJSONParseError,
33
+ UrlError: () => UrlError
34
+ });
35
+ var UpstashError = class extends Error {
36
+ constructor(message, options) {
37
+ super(message, options);
38
+ this.name = "UpstashError";
39
+ }
40
+ };
41
+ var UrlError = class extends Error {
42
+ constructor(url) {
43
+ super(
44
+ `Upstash Redis client was passed an invalid URL. You should pass a URL starting with https. Received: "${url}". `
45
+ );
46
+ this.name = "UrlError";
47
+ }
48
+ };
49
+ var UpstashJSONParseError = class extends UpstashError {
50
+ constructor(body, options) {
51
+ const truncatedBody = body.length > 200 ? body.slice(0, 200) + "..." : body;
52
+ super(`Unable to parse response body: ${truncatedBody}`, options);
53
+ this.name = "UpstashJSONParseError";
54
+ }
55
+ };
56
+
57
+ // pkg/util.ts
58
+ function parseRecursive(obj) {
59
+ const parsed = Array.isArray(obj) ? obj.map((o) => {
60
+ try {
61
+ return parseRecursive(o);
62
+ } catch {
63
+ return o;
64
+ }
65
+ }) : JSON.parse(obj);
66
+ if (typeof parsed === "number" && parsed.toString() !== obj) {
67
+ return obj;
68
+ }
69
+ return parsed;
70
+ }
71
+ function parseResponse(result) {
72
+ try {
73
+ return parseRecursive(result);
74
+ } catch {
75
+ return result;
76
+ }
77
+ }
78
+ function deserializeScanResponse(result) {
79
+ return [result[0], ...parseResponse(result.slice(1))];
80
+ }
81
+ function deserializeScanWithTypesResponse(result) {
82
+ const [cursor, keys] = result;
83
+ const parsedKeys = [];
84
+ for (let i = 0; i < keys.length; i += 2) {
85
+ parsedKeys.push({ key: keys[i], type: keys[i + 1] });
86
+ }
87
+ return [cursor, parsedKeys];
88
+ }
89
+ function mergeHeaders(...headers) {
90
+ const merged = {};
91
+ for (const header of headers) {
92
+ if (!header) continue;
93
+ for (const [key, value] of Object.entries(header)) {
94
+ if (value !== void 0 && value !== null) {
95
+ merged[key] = value;
96
+ }
97
+ }
98
+ }
99
+ return merged;
100
+ }
101
+ function kvArrayToObject(v) {
102
+ if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
103
+ if (!Array.isArray(v)) return {};
104
+ const obj = {};
105
+ for (let i = 0; i < v.length; i += 2) {
106
+ if (typeof v[i] === "string") obj[v[i]] = v[i + 1];
107
+ }
108
+ return obj;
109
+ }
110
+
111
+ // pkg/http.ts
112
+ var HttpClient = class {
113
+ baseUrl;
114
+ headers;
115
+ options;
116
+ readYourWrites;
117
+ upstashSyncToken = "";
118
+ hasCredentials;
119
+ retry;
120
+ constructor(config) {
121
+ this.options = {
122
+ backend: config.options?.backend,
123
+ agent: config.agent,
124
+ responseEncoding: config.responseEncoding ?? "base64",
125
+ // default to base64
126
+ cache: config.cache,
127
+ signal: config.signal,
128
+ keepAlive: config.keepAlive ?? true
129
+ };
130
+ this.upstashSyncToken = "";
131
+ this.readYourWrites = config.readYourWrites ?? true;
132
+ this.baseUrl = (config.baseUrl || "").replace(/\/$/, "");
133
+ const urlRegex = /^https?:\/\/[^\s#$./?].\S*$/;
134
+ if (this.baseUrl && !urlRegex.test(this.baseUrl)) {
135
+ throw new UrlError(this.baseUrl);
136
+ }
137
+ this.headers = {
138
+ "Content-Type": "application/json",
139
+ ...config.headers
140
+ };
141
+ this.hasCredentials = Boolean(this.baseUrl && this.headers.authorization.split(" ")[1]);
142
+ if (this.options.responseEncoding === "base64") {
143
+ this.headers["Upstash-Encoding"] = "base64";
144
+ }
145
+ this.retry = typeof config.retry === "boolean" && !config.retry ? {
146
+ attempts: 1,
147
+ backoff: () => 0
148
+ } : {
149
+ attempts: config.retry?.retries ?? 5,
150
+ backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
151
+ };
152
+ }
153
+ mergeTelemetry(telemetry) {
154
+ this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
155
+ this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
156
+ this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
157
+ }
158
+ async request(req) {
159
+ const requestHeaders = mergeHeaders(this.headers, req.headers ?? {});
160
+ const requestUrl = [this.baseUrl, ...req.path ?? []].join("/");
161
+ const isEventStream = requestHeaders.Accept === "text/event-stream";
162
+ const signal = req.signal ?? this.options.signal;
163
+ const isSignalFunction = typeof signal === "function";
164
+ const requestOptions = {
165
+ //@ts-expect-error this should throw due to bun regression
166
+ cache: this.options.cache,
167
+ method: "POST",
168
+ headers: requestHeaders,
169
+ body: JSON.stringify(req.body),
170
+ keepalive: this.options.keepAlive,
171
+ agent: this.options.agent,
172
+ signal: isSignalFunction ? signal() : signal,
173
+ /**
174
+ * Fastly specific
175
+ */
176
+ backend: this.options.backend
177
+ };
178
+ if (!this.hasCredentials) {
179
+ console.warn(
180
+ "[Upstash Redis] Redis client was initialized without url or token. Failed to execute command."
181
+ );
182
+ }
183
+ if (this.readYourWrites) {
184
+ const newHeader = this.upstashSyncToken;
185
+ this.headers["upstash-sync-token"] = newHeader;
186
+ }
187
+ let res = null;
188
+ let error = null;
189
+ for (let i = 0; i <= this.retry.attempts; i++) {
190
+ try {
191
+ res = await fetch(requestUrl, requestOptions);
192
+ break;
193
+ } catch (error_) {
194
+ if (requestOptions.signal?.aborted && isSignalFunction) {
195
+ throw error_;
196
+ } else if (requestOptions.signal?.aborted) {
197
+ const myBlob = new Blob([
198
+ JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
199
+ ]);
200
+ const myOptions = {
201
+ status: 200,
202
+ statusText: requestOptions.signal.reason ?? "Aborted"
203
+ };
204
+ res = new Response(myBlob, myOptions);
205
+ break;
206
+ }
207
+ error = error_;
208
+ if (i < this.retry.attempts) {
209
+ await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
210
+ }
211
+ }
212
+ }
213
+ if (!res) {
214
+ throw error ?? new Error("Exhausted all retries");
215
+ }
216
+ if (!res.ok) {
217
+ let body2;
218
+ const rawBody2 = await res.text();
219
+ try {
220
+ body2 = JSON.parse(rawBody2);
221
+ } catch (error2) {
222
+ throw new UpstashJSONParseError(rawBody2, { cause: error2 });
223
+ }
224
+ throw new UpstashError(`${body2.error}, command was: ${JSON.stringify(req.body)}`);
225
+ }
226
+ if (this.readYourWrites) {
227
+ const headers = res.headers;
228
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
229
+ }
230
+ if (isEventStream && req && req.onMessage && res.body) {
231
+ const reader = res.body.getReader();
232
+ const decoder = new TextDecoder();
233
+ (async () => {
234
+ try {
235
+ while (true) {
236
+ const { value, done } = await reader.read();
237
+ if (done) break;
238
+ const chunk = decoder.decode(value);
239
+ const lines = chunk.split("\n");
240
+ for (const line of lines) {
241
+ if (line.startsWith("data: ")) {
242
+ const data = line.slice(6);
243
+ req.onMessage?.(data);
244
+ }
245
+ }
246
+ }
247
+ } catch (error2) {
248
+ if (error2 instanceof Error && error2.name === "AbortError") {
249
+ } else {
250
+ console.error("Stream reading error:", error2);
251
+ }
252
+ } finally {
253
+ try {
254
+ await reader.cancel();
255
+ } catch {
256
+ }
257
+ }
258
+ })();
259
+ return { result: 1 };
260
+ }
261
+ let body;
262
+ const rawBody = await res.text();
263
+ try {
264
+ body = JSON.parse(rawBody);
265
+ } catch (error2) {
266
+ throw new UpstashJSONParseError(rawBody, { cause: error2 });
267
+ }
268
+ if (this.readYourWrites) {
269
+ const headers = res.headers;
270
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
271
+ }
272
+ if (this.options.responseEncoding === "base64") {
273
+ if (Array.isArray(body)) {
274
+ return body.map(({ result: result2, error: error2 }) => ({
275
+ result: decode(result2),
276
+ error: error2
277
+ }));
278
+ }
279
+ const result = decode(body.result);
280
+ return { result, error: body.error };
281
+ }
282
+ return body;
283
+ }
284
+ };
285
+ function base64decode(b64) {
286
+ let dec = "";
287
+ try {
288
+ const binString = atob(b64);
289
+ const size = binString.length;
290
+ const bytes = new Uint8Array(size);
291
+ for (let i = 0; i < size; i++) {
292
+ bytes[i] = binString.charCodeAt(i);
293
+ }
294
+ dec = new TextDecoder().decode(bytes);
295
+ } catch {
296
+ dec = b64;
297
+ }
298
+ return dec;
299
+ }
300
+ function decode(raw) {
301
+ let result = void 0;
302
+ switch (typeof raw) {
303
+ case "undefined": {
304
+ return raw;
305
+ }
306
+ case "number": {
307
+ result = raw;
308
+ break;
309
+ }
310
+ case "object": {
311
+ if (Array.isArray(raw)) {
312
+ result = raw.map(
313
+ (v) => typeof v === "string" ? base64decode(v) : Array.isArray(v) ? v.map((element) => decode(element)) : v
314
+ );
315
+ } else {
316
+ result = null;
317
+ }
318
+ break;
319
+ }
320
+ case "string": {
321
+ result = raw === "OK" ? "OK" : base64decode(raw);
322
+ break;
323
+ }
324
+ default: {
325
+ break;
326
+ }
327
+ }
328
+ return result;
329
+ }
330
+ function merge(obj, key, value) {
331
+ if (!value) {
332
+ return obj;
333
+ }
334
+ obj[key] = obj[key] ? [obj[key], value].join(",") : value;
335
+ return obj;
336
+ }
337
+
338
+ // pkg/auto-pipeline.ts
339
+ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
340
+ "scan",
341
+ "keys",
342
+ "flushdb",
343
+ "flushall",
344
+ "dbsize",
345
+ "hscan",
346
+ "hgetall",
347
+ "hkeys",
348
+ "lrange",
349
+ "sscan",
350
+ "smembers",
351
+ "xrange",
352
+ "xrevrange",
353
+ "zscan",
354
+ "zrange",
355
+ "exec"
356
+ ]);
357
+ function createAutoPipelineProxy(_redis, namespace = "root") {
358
+ const redis = _redis;
359
+ if (!redis.autoPipelineExecutor) {
360
+ redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
361
+ }
362
+ return new Proxy(redis, {
363
+ get: (redis2, command) => {
364
+ if (command === "pipelineCounter") {
365
+ return redis2.autoPipelineExecutor.pipelineCounter;
366
+ }
367
+ if (namespace === "root" && command === "json") {
368
+ return createAutoPipelineProxy(redis2, "json");
369
+ }
370
+ if (namespace === "root" && command === "functions") {
371
+ return createAutoPipelineProxy(redis2, "functions");
372
+ }
373
+ if (namespace === "root") {
374
+ const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
375
+ const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
376
+ if (commandInRedisButNotPipeline || isCommandExcluded) {
377
+ return redis2[command];
378
+ }
379
+ }
380
+ const pipeline = redis2.autoPipelineExecutor.pipeline;
381
+ const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
382
+ const isFunction = typeof targetFunction === "function";
383
+ if (isFunction) {
384
+ return (...args) => {
385
+ return redis2.autoPipelineExecutor.withAutoPipeline((pipeline2) => {
386
+ const targetFunction2 = namespace === "json" ? pipeline2.json[command] : namespace === "functions" ? pipeline2.functions[command] : pipeline2[command];
387
+ targetFunction2(...args);
388
+ });
389
+ };
390
+ }
391
+ return targetFunction;
392
+ }
393
+ });
394
+ }
395
+ var AutoPipelineExecutor = class {
396
+ pipelinePromises = /* @__PURE__ */ new WeakMap();
397
+ activePipeline = null;
398
+ indexInCurrentPipeline = 0;
399
+ redis;
400
+ pipeline;
401
+ // only to make sure that proxy can work
402
+ pipelineCounter = 0;
403
+ // to keep track of how many times a pipeline was executed
404
+ constructor(redis) {
405
+ this.redis = redis;
406
+ this.pipeline = redis.pipeline();
407
+ }
408
+ async withAutoPipeline(executeWithPipeline) {
409
+ const pipeline = this.activePipeline ?? this.redis.pipeline();
410
+ if (!this.activePipeline) {
411
+ this.activePipeline = pipeline;
412
+ this.indexInCurrentPipeline = 0;
413
+ }
414
+ const index = this.indexInCurrentPipeline++;
415
+ executeWithPipeline(pipeline);
416
+ const pipelineDone = this.deferExecution().then(() => {
417
+ if (!this.pipelinePromises.has(pipeline)) {
418
+ const pipelinePromise = pipeline.exec({ keepErrors: true });
419
+ this.pipelineCounter += 1;
420
+ this.pipelinePromises.set(pipeline, pipelinePromise);
421
+ this.activePipeline = null;
422
+ }
423
+ return this.pipelinePromises.get(pipeline);
424
+ });
425
+ const results = await pipelineDone;
426
+ const commandResult = results[index];
427
+ if (commandResult.error) {
428
+ throw new UpstashError(`Command failed: ${commandResult.error}`);
429
+ }
430
+ return commandResult.result;
431
+ }
432
+ async deferExecution() {
433
+ await Promise.resolve();
434
+ await Promise.resolve();
435
+ }
436
+ };
437
+
438
+ // pkg/commands/command.ts
439
+ var defaultSerializer = (c) => {
440
+ switch (typeof c) {
441
+ case "string":
442
+ case "number":
443
+ case "boolean": {
444
+ return c;
445
+ }
446
+ default: {
447
+ return JSON.stringify(c);
448
+ }
449
+ }
450
+ };
451
+ var Command = class {
452
+ command;
453
+ serialize;
454
+ deserialize;
455
+ headers;
456
+ path;
457
+ onMessage;
458
+ isStreaming;
459
+ signal;
460
+ /**
461
+ * Create a new command instance.
462
+ *
463
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
464
+ */
465
+ constructor(command, opts) {
466
+ this.serialize = defaultSerializer;
467
+ this.deserialize = opts?.automaticDeserialization === void 0 || opts.automaticDeserialization ? opts?.deserialize ?? parseResponse : (x) => x;
468
+ this.command = command.map((c) => this.serialize(c));
469
+ this.headers = opts?.headers;
470
+ this.path = opts?.path;
471
+ this.onMessage = opts?.streamOptions?.onMessage;
472
+ this.isStreaming = opts?.streamOptions?.isStreaming ?? false;
473
+ this.signal = opts?.streamOptions?.signal;
474
+ if (opts?.latencyLogging) {
475
+ const originalExec = this.exec.bind(this);
476
+ this.exec = async (client) => {
477
+ const start = performance.now();
478
+ const result = await originalExec(client);
479
+ const end = performance.now();
480
+ const loggerResult = (end - start).toFixed(2);
481
+ console.log(
482
+ `Latency for \x1B[38;2;19;185;39m${this.command[0].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
483
+ );
484
+ return result;
485
+ };
486
+ }
487
+ }
488
+ /**
489
+ * Execute the command using a client.
490
+ */
491
+ async exec(client) {
492
+ const { result, error } = await client.request({
493
+ body: this.command,
494
+ path: this.path,
495
+ upstashSyncToken: client.upstashSyncToken,
496
+ headers: this.headers,
497
+ onMessage: this.onMessage,
498
+ isStreaming: this.isStreaming,
499
+ signal: this.signal
500
+ });
501
+ if (error) {
502
+ throw new UpstashError(error);
503
+ }
504
+ if (result === void 0) {
505
+ throw new TypeError("Request did not return a result");
506
+ }
507
+ return this.deserialize(result);
508
+ }
509
+ };
510
+
511
+ // pkg/commands/append.ts
512
+ var AppendCommand = class extends Command {
513
+ constructor(cmd, opts) {
514
+ super(["append", ...cmd], opts);
515
+ }
516
+ };
517
+
518
+ // pkg/commands/bitcount.ts
519
+ var BitCountCommand = class extends Command {
520
+ constructor([key, start, end], opts) {
521
+ const command = ["bitcount", key];
522
+ if (typeof start === "number") {
523
+ command.push(start);
524
+ }
525
+ if (typeof end === "number") {
526
+ command.push(end);
527
+ }
528
+ super(command, opts);
529
+ }
530
+ };
531
+
532
+ // pkg/commands/bitfield.ts
533
+ var BitFieldCommand = class {
534
+ constructor(args, client, opts, execOperation = (command) => command.exec(this.client)) {
535
+ this.client = client;
536
+ this.opts = opts;
537
+ this.execOperation = execOperation;
538
+ this.command = ["bitfield", ...args];
539
+ }
540
+ command;
541
+ chain(...args) {
542
+ this.command.push(...args);
543
+ return this;
544
+ }
545
+ get(...args) {
546
+ return this.chain("get", ...args);
547
+ }
548
+ set(...args) {
549
+ return this.chain("set", ...args);
550
+ }
551
+ incrby(...args) {
552
+ return this.chain("incrby", ...args);
553
+ }
554
+ overflow(overflow) {
555
+ return this.chain("overflow", overflow);
556
+ }
557
+ exec() {
558
+ const command = new Command(this.command, this.opts);
559
+ return this.execOperation(command);
560
+ }
561
+ };
562
+
563
+ // pkg/commands/bitop.ts
564
+ var BitOpCommand = class extends Command {
565
+ constructor(cmd, opts) {
566
+ super(["bitop", ...cmd], opts);
567
+ }
568
+ };
569
+
570
+ // pkg/commands/bitpos.ts
571
+ var BitPosCommand = class extends Command {
572
+ constructor(cmd, opts) {
573
+ super(["bitpos", ...cmd], opts);
574
+ }
575
+ };
576
+
577
+ // pkg/commands/copy.ts
578
+ var CopyCommand = class extends Command {
579
+ constructor([key, destinationKey, opts], commandOptions) {
580
+ super(["COPY", key, destinationKey, ...opts?.replace ? ["REPLACE"] : []], {
581
+ ...commandOptions,
582
+ deserialize(result) {
583
+ if (result > 0) {
584
+ return "COPIED";
585
+ }
586
+ return "NOT_COPIED";
587
+ }
588
+ });
589
+ }
590
+ };
591
+
592
+ // pkg/commands/dbsize.ts
593
+ var DBSizeCommand = class extends Command {
594
+ constructor(opts) {
595
+ super(["dbsize"], opts);
596
+ }
597
+ };
598
+
599
+ // pkg/commands/decr.ts
600
+ var DecrCommand = class extends Command {
601
+ constructor(cmd, opts) {
602
+ super(["decr", ...cmd], opts);
603
+ }
604
+ };
605
+
606
+ // pkg/commands/decrby.ts
607
+ var DecrByCommand = class extends Command {
608
+ constructor(cmd, opts) {
609
+ super(["decrby", ...cmd], opts);
610
+ }
611
+ };
612
+
613
+ // pkg/commands/del.ts
614
+ var DelCommand = class extends Command {
615
+ constructor(cmd, opts) {
616
+ super(["del", ...cmd], opts);
617
+ }
618
+ };
619
+
620
+ // pkg/commands/echo.ts
621
+ var EchoCommand = class extends Command {
622
+ constructor(cmd, opts) {
623
+ super(["echo", ...cmd], opts);
624
+ }
625
+ };
626
+
627
+ // pkg/commands/evalRo.ts
628
+ var EvalROCommand = class extends Command {
629
+ constructor([script, keys, args], opts) {
630
+ super(["eval_ro", script, keys.length, ...keys, ...args ?? []], opts);
631
+ }
632
+ };
633
+
634
+ // pkg/commands/eval.ts
635
+ var EvalCommand = class extends Command {
636
+ constructor([script, keys, args], opts) {
637
+ super(["eval", script, keys.length, ...keys, ...args ?? []], opts);
638
+ }
639
+ };
640
+
641
+ // pkg/commands/evalshaRo.ts
642
+ var EvalshaROCommand = class extends Command {
643
+ constructor([sha, keys, args], opts) {
644
+ super(["evalsha_ro", sha, keys.length, ...keys, ...args ?? []], opts);
645
+ }
646
+ };
647
+
648
+ // pkg/commands/evalsha.ts
649
+ var EvalshaCommand = class extends Command {
650
+ constructor([sha, keys, args], opts) {
651
+ super(["evalsha", sha, keys.length, ...keys, ...args ?? []], opts);
652
+ }
653
+ };
654
+
655
+ // pkg/commands/exec.ts
656
+ var ExecCommand = class extends Command {
657
+ constructor(cmd, opts) {
658
+ const normalizedCmd = cmd.map((arg) => typeof arg === "string" ? arg : String(arg));
659
+ super(normalizedCmd, opts);
660
+ }
661
+ };
662
+
663
+ // pkg/commands/exists.ts
664
+ var ExistsCommand = class extends Command {
665
+ constructor(cmd, opts) {
666
+ super(["exists", ...cmd], opts);
667
+ }
668
+ };
669
+
670
+ // pkg/commands/expire.ts
671
+ var ExpireCommand = class extends Command {
672
+ constructor(cmd, opts) {
673
+ super(["expire", ...cmd.filter(Boolean)], opts);
674
+ }
675
+ };
676
+
677
+ // pkg/commands/expireat.ts
678
+ var ExpireAtCommand = class extends Command {
679
+ constructor(cmd, opts) {
680
+ super(["expireat", ...cmd], opts);
681
+ }
682
+ };
683
+
684
+ // pkg/commands/fcall.ts
685
+ var FCallCommand = class extends Command {
686
+ constructor([fn, keys, args], opts) {
687
+ super(["fcall", fn, ...keys ? [keys.length, ...keys] : [0], ...args ?? []], opts);
688
+ }
689
+ };
690
+
691
+ // pkg/commands/fcall_ro.ts
692
+ var FCallRoCommand = class extends Command {
693
+ constructor([fn, keys, args], opts) {
694
+ super(["fcall_ro", fn, ...keys ? [keys.length, ...keys] : [], ...args ?? []], opts);
695
+ }
696
+ };
697
+
698
+ // pkg/commands/flushall.ts
699
+ var FlushAllCommand = class extends Command {
700
+ constructor(args, opts) {
701
+ const command = ["flushall"];
702
+ if (args && args.length > 0 && args[0].async) {
703
+ command.push("async");
704
+ }
705
+ super(command, opts);
706
+ }
707
+ };
708
+
709
+ // pkg/commands/flushdb.ts
710
+ var FlushDBCommand = class extends Command {
711
+ constructor([opts], cmdOpts) {
712
+ const command = ["flushdb"];
713
+ if (opts?.async) {
714
+ command.push("async");
715
+ }
716
+ super(command, cmdOpts);
717
+ }
718
+ };
719
+
720
+ // pkg/commands/function_delete.ts
721
+ var FunctionDeleteCommand = class extends Command {
722
+ constructor([libraryName], opts) {
723
+ super(["function", "delete", libraryName], opts);
724
+ }
725
+ };
726
+
727
+ // pkg/commands/function_flush.ts
728
+ var FunctionFlushCommand = class extends Command {
729
+ constructor(opts) {
730
+ super(["function", "flush"], opts);
731
+ }
732
+ };
733
+
734
+ // pkg/commands/function_list.ts
735
+ var FunctionListCommand = class extends Command {
736
+ constructor([args], opts) {
737
+ const command = ["function", "list"];
738
+ if (args?.libraryName) {
739
+ command.push("libraryname", args.libraryName);
740
+ }
741
+ if (args?.withCode) {
742
+ command.push("withcode");
743
+ }
744
+ super(command, { deserialize, ...opts });
745
+ }
746
+ };
747
+ function deserialize(result) {
748
+ if (!Array.isArray(result)) return [];
749
+ return result.map((libRaw) => {
750
+ const lib = kvArrayToObject(libRaw);
751
+ const functionsParsed = lib.functions.map(
752
+ (fnRaw) => kvArrayToObject(fnRaw)
753
+ );
754
+ return {
755
+ libraryName: lib.library_name,
756
+ engine: lib.engine,
757
+ functions: functionsParsed.map((fn) => ({
758
+ name: fn.name,
759
+ description: fn.description ?? void 0,
760
+ flags: fn.flags
761
+ })),
762
+ libraryCode: lib.library_code
763
+ };
764
+ });
765
+ }
766
+
767
+ // pkg/commands/function_load.ts
768
+ var FunctionLoadCommand = class extends Command {
769
+ constructor([args], opts) {
770
+ super(["function", "load", ...args.replace ? ["replace"] : [], args.code], opts);
771
+ }
772
+ };
773
+
774
+ // pkg/commands/function_stats.ts
775
+ var FunctionStatsCommand = class extends Command {
776
+ constructor(opts) {
777
+ super(["function", "stats"], { deserialize: deserialize2, ...opts });
778
+ }
779
+ };
780
+ function deserialize2(result) {
781
+ const rawEngines = kvArrayToObject(kvArrayToObject(result).engines);
782
+ const parsedEngines = Object.fromEntries(
783
+ Object.entries(rawEngines).map(([key, value]) => [key, kvArrayToObject(value)])
784
+ );
785
+ const final = {
786
+ engines: Object.fromEntries(
787
+ Object.entries(parsedEngines).map(([key, value]) => [
788
+ key,
789
+ {
790
+ librariesCount: value.libraries_count,
791
+ functionsCount: value.functions_count
792
+ }
793
+ ])
794
+ )
795
+ };
796
+ return final;
797
+ }
798
+
799
+ // pkg/commands/geo_add.ts
800
+ var GeoAddCommand = class extends Command {
801
+ constructor([key, arg1, ...arg2], opts) {
802
+ const command = ["geoadd", key];
803
+ if ("nx" in arg1 && arg1.nx) {
804
+ command.push("nx");
805
+ } else if ("xx" in arg1 && arg1.xx) {
806
+ command.push("xx");
807
+ }
808
+ if ("ch" in arg1 && arg1.ch) {
809
+ command.push("ch");
810
+ }
811
+ if ("latitude" in arg1 && arg1.latitude) {
812
+ command.push(arg1.longitude, arg1.latitude, arg1.member);
813
+ }
814
+ command.push(
815
+ ...arg2.flatMap(({ latitude, longitude, member }) => [longitude, latitude, member])
816
+ );
817
+ super(command, opts);
818
+ }
819
+ };
820
+
821
+ // pkg/commands/geo_dist.ts
822
+ var GeoDistCommand = class extends Command {
823
+ constructor([key, member1, member2, unit = "M"], opts) {
824
+ super(["GEODIST", key, member1, member2, unit], opts);
825
+ }
826
+ };
827
+
828
+ // pkg/commands/geo_hash.ts
829
+ var GeoHashCommand = class extends Command {
830
+ constructor(cmd, opts) {
831
+ const [key] = cmd;
832
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
833
+ super(["GEOHASH", key, ...members], opts);
834
+ }
835
+ };
836
+
837
+ // pkg/commands/geo_pos.ts
838
+ var GeoPosCommand = class extends Command {
839
+ constructor(cmd, opts) {
840
+ const [key] = cmd;
841
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
842
+ super(["GEOPOS", key, ...members], {
843
+ deserialize: (result) => transform(result),
844
+ ...opts
845
+ });
846
+ }
847
+ };
848
+ function transform(result) {
849
+ const final = [];
850
+ for (const pos of result) {
851
+ if (!pos?.[0] || !pos?.[1]) {
852
+ continue;
853
+ }
854
+ final.push({ lng: Number.parseFloat(pos[0]), lat: Number.parseFloat(pos[1]) });
855
+ }
856
+ return final;
857
+ }
858
+
859
+ // pkg/commands/geo_search.ts
860
+ var GeoSearchCommand = class extends Command {
861
+ constructor([key, centerPoint, shape, order, opts], commandOptions) {
862
+ const command = ["GEOSEARCH", key];
863
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
864
+ command.push(centerPoint.type, centerPoint.member);
865
+ }
866
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
867
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
868
+ }
869
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
870
+ command.push(shape.type, shape.radius, shape.radiusType);
871
+ }
872
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
873
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
874
+ }
875
+ command.push(order);
876
+ if (opts?.count) {
877
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
878
+ }
879
+ const transform2 = (result) => {
880
+ if (!opts?.withCoord && !opts?.withDist && !opts?.withHash) {
881
+ return result.map((member) => {
882
+ try {
883
+ return { member: JSON.parse(member) };
884
+ } catch {
885
+ return { member };
886
+ }
887
+ });
888
+ }
889
+ return result.map((members) => {
890
+ let counter = 1;
891
+ const obj = {};
892
+ try {
893
+ obj.member = JSON.parse(members[0]);
894
+ } catch {
895
+ obj.member = members[0];
896
+ }
897
+ if (opts.withDist) {
898
+ obj.dist = Number.parseFloat(members[counter++]);
899
+ }
900
+ if (opts.withHash) {
901
+ obj.hash = members[counter++].toString();
902
+ }
903
+ if (opts.withCoord) {
904
+ obj.coord = {
905
+ long: Number.parseFloat(members[counter][0]),
906
+ lat: Number.parseFloat(members[counter][1])
907
+ };
908
+ }
909
+ return obj;
910
+ });
911
+ };
912
+ super(
913
+ [
914
+ ...command,
915
+ ...opts?.withCoord ? ["WITHCOORD"] : [],
916
+ ...opts?.withDist ? ["WITHDIST"] : [],
917
+ ...opts?.withHash ? ["WITHHASH"] : []
918
+ ],
919
+ {
920
+ deserialize: transform2,
921
+ ...commandOptions
922
+ }
923
+ );
924
+ }
925
+ };
926
+
927
+ // pkg/commands/geo_search_store.ts
928
+ var GeoSearchStoreCommand = class extends Command {
929
+ constructor([destination, key, centerPoint, shape, order, opts], commandOptions) {
930
+ const command = ["GEOSEARCHSTORE", destination, key];
931
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
932
+ command.push(centerPoint.type, centerPoint.member);
933
+ }
934
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
935
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
936
+ }
937
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
938
+ command.push(shape.type, shape.radius, shape.radiusType);
939
+ }
940
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
941
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
942
+ }
943
+ command.push(order);
944
+ if (opts?.count) {
945
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
946
+ }
947
+ super([...command, ...opts?.storeDist ? ["STOREDIST"] : []], commandOptions);
948
+ }
949
+ };
950
+
951
+ // pkg/commands/get.ts
952
+ var GetCommand = class extends Command {
953
+ constructor(cmd, opts) {
954
+ super(["get", ...cmd], opts);
955
+ }
956
+ };
957
+
958
+ // pkg/commands/getbit.ts
959
+ var GetBitCommand = class extends Command {
960
+ constructor(cmd, opts) {
961
+ super(["getbit", ...cmd], opts);
962
+ }
963
+ };
964
+
965
+ // pkg/commands/getdel.ts
966
+ var GetDelCommand = class extends Command {
967
+ constructor(cmd, opts) {
968
+ super(["getdel", ...cmd], opts);
969
+ }
970
+ };
971
+
972
+ // pkg/commands/getex.ts
973
+ var GetExCommand = class extends Command {
974
+ constructor([key, opts], cmdOpts) {
975
+ const command = ["getex", key];
976
+ if (opts) {
977
+ if ("ex" in opts && typeof opts.ex === "number") {
978
+ command.push("ex", opts.ex);
979
+ } else if ("px" in opts && typeof opts.px === "number") {
980
+ command.push("px", opts.px);
981
+ } else if ("exat" in opts && typeof opts.exat === "number") {
982
+ command.push("exat", opts.exat);
983
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
984
+ command.push("pxat", opts.pxat);
985
+ } else if ("persist" in opts && opts.persist) {
986
+ command.push("persist");
987
+ }
988
+ }
989
+ super(command, cmdOpts);
990
+ }
991
+ };
992
+
993
+ // pkg/commands/getrange.ts
994
+ var GetRangeCommand = class extends Command {
995
+ constructor(cmd, opts) {
996
+ super(["getrange", ...cmd], opts);
997
+ }
998
+ };
999
+
1000
+ // pkg/commands/getset.ts
1001
+ var GetSetCommand = class extends Command {
1002
+ constructor(cmd, opts) {
1003
+ super(["getset", ...cmd], opts);
1004
+ }
1005
+ };
1006
+
1007
+ // pkg/commands/hdel.ts
1008
+ var HDelCommand = class extends Command {
1009
+ constructor(cmd, opts) {
1010
+ super(["hdel", ...cmd], opts);
1011
+ }
1012
+ };
1013
+
1014
+ // pkg/commands/hexists.ts
1015
+ var HExistsCommand = class extends Command {
1016
+ constructor(cmd, opts) {
1017
+ super(["hexists", ...cmd], opts);
1018
+ }
1019
+ };
1020
+
1021
+ // pkg/commands/hexpire.ts
1022
+ var HExpireCommand = class extends Command {
1023
+ constructor(cmd, opts) {
1024
+ const [key, fields, seconds, option] = cmd;
1025
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1026
+ super(
1027
+ [
1028
+ "hexpire",
1029
+ key,
1030
+ seconds,
1031
+ ...option ? [option] : [],
1032
+ "FIELDS",
1033
+ fieldArray.length,
1034
+ ...fieldArray
1035
+ ],
1036
+ opts
1037
+ );
1038
+ }
1039
+ };
1040
+
1041
+ // pkg/commands/hexpireat.ts
1042
+ var HExpireAtCommand = class extends Command {
1043
+ constructor(cmd, opts) {
1044
+ const [key, fields, timestamp, option] = cmd;
1045
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1046
+ super(
1047
+ [
1048
+ "hexpireat",
1049
+ key,
1050
+ timestamp,
1051
+ ...option ? [option] : [],
1052
+ "FIELDS",
1053
+ fieldArray.length,
1054
+ ...fieldArray
1055
+ ],
1056
+ opts
1057
+ );
1058
+ }
1059
+ };
1060
+
1061
+ // pkg/commands/hexpiretime.ts
1062
+ var HExpireTimeCommand = class extends Command {
1063
+ constructor(cmd, opts) {
1064
+ const [key, fields] = cmd;
1065
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1066
+ super(["hexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1067
+ }
1068
+ };
1069
+
1070
+ // pkg/commands/hpersist.ts
1071
+ var HPersistCommand = class extends Command {
1072
+ constructor(cmd, opts) {
1073
+ const [key, fields] = cmd;
1074
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1075
+ super(["hpersist", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1076
+ }
1077
+ };
1078
+
1079
+ // pkg/commands/hpexpire.ts
1080
+ var HPExpireCommand = class extends Command {
1081
+ constructor(cmd, opts) {
1082
+ const [key, fields, milliseconds, option] = cmd;
1083
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1084
+ super(
1085
+ [
1086
+ "hpexpire",
1087
+ key,
1088
+ milliseconds,
1089
+ ...option ? [option] : [],
1090
+ "FIELDS",
1091
+ fieldArray.length,
1092
+ ...fieldArray
1093
+ ],
1094
+ opts
1095
+ );
1096
+ }
1097
+ };
1098
+
1099
+ // pkg/commands/hpexpireat.ts
1100
+ var HPExpireAtCommand = class extends Command {
1101
+ constructor(cmd, opts) {
1102
+ const [key, fields, timestamp, option] = cmd;
1103
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1104
+ super(
1105
+ [
1106
+ "hpexpireat",
1107
+ key,
1108
+ timestamp,
1109
+ ...option ? [option] : [],
1110
+ "FIELDS",
1111
+ fieldArray.length,
1112
+ ...fieldArray
1113
+ ],
1114
+ opts
1115
+ );
1116
+ }
1117
+ };
1118
+
1119
+ // pkg/commands/hpexpiretime.ts
1120
+ var HPExpireTimeCommand = class extends Command {
1121
+ constructor(cmd, opts) {
1122
+ const [key, fields] = cmd;
1123
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1124
+ super(["hpexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1125
+ }
1126
+ };
1127
+
1128
+ // pkg/commands/hpttl.ts
1129
+ var HPTtlCommand = class extends Command {
1130
+ constructor(cmd, opts) {
1131
+ const [key, fields] = cmd;
1132
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1133
+ super(["hpttl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1134
+ }
1135
+ };
1136
+
1137
+ // pkg/commands/hget.ts
1138
+ var HGetCommand = class extends Command {
1139
+ constructor(cmd, opts) {
1140
+ super(["hget", ...cmd], opts);
1141
+ }
1142
+ };
1143
+
1144
+ // pkg/commands/hgetall.ts
1145
+ function deserialize3(result) {
1146
+ if (result.length === 0) {
1147
+ return null;
1148
+ }
1149
+ const obj = {};
1150
+ for (let i = 0; i < result.length; i += 2) {
1151
+ const key = result[i];
1152
+ const value = result[i + 1];
1153
+ try {
1154
+ const valueIsNumberAndNotSafeInteger = !Number.isNaN(Number(value)) && !Number.isSafeInteger(Number(value));
1155
+ obj[key] = valueIsNumberAndNotSafeInteger ? value : JSON.parse(value);
1156
+ } catch {
1157
+ obj[key] = value;
1158
+ }
1159
+ }
1160
+ return obj;
1161
+ }
1162
+ var HGetAllCommand = class extends Command {
1163
+ constructor(cmd, opts) {
1164
+ super(["hgetall", ...cmd], {
1165
+ deserialize: (result) => deserialize3(result),
1166
+ ...opts
1167
+ });
1168
+ }
1169
+ };
1170
+
1171
+ // pkg/commands/hincrby.ts
1172
+ var HIncrByCommand = class extends Command {
1173
+ constructor(cmd, opts) {
1174
+ super(["hincrby", ...cmd], opts);
1175
+ }
1176
+ };
1177
+
1178
+ // pkg/commands/hincrbyfloat.ts
1179
+ var HIncrByFloatCommand = class extends Command {
1180
+ constructor(cmd, opts) {
1181
+ super(["hincrbyfloat", ...cmd], opts);
1182
+ }
1183
+ };
1184
+
1185
+ // pkg/commands/hkeys.ts
1186
+ var HKeysCommand = class extends Command {
1187
+ constructor([key], opts) {
1188
+ super(["hkeys", key], opts);
1189
+ }
1190
+ };
1191
+
1192
+ // pkg/commands/hlen.ts
1193
+ var HLenCommand = class extends Command {
1194
+ constructor(cmd, opts) {
1195
+ super(["hlen", ...cmd], opts);
1196
+ }
1197
+ };
1198
+
1199
+ // pkg/commands/hmget.ts
1200
+ function deserialize4(fields, result) {
1201
+ if (result.every((field) => field === null)) {
1202
+ return null;
1203
+ }
1204
+ const obj = {};
1205
+ for (const [i, field] of fields.entries()) {
1206
+ try {
1207
+ obj[field] = JSON.parse(result[i]);
1208
+ } catch {
1209
+ obj[field] = result[i];
1210
+ }
1211
+ }
1212
+ return obj;
1213
+ }
1214
+ var HMGetCommand = class extends Command {
1215
+ constructor([key, ...fields], opts) {
1216
+ super(["hmget", key, ...fields], {
1217
+ deserialize: (result) => deserialize4(fields, result),
1218
+ ...opts
1219
+ });
1220
+ }
1221
+ };
1222
+
1223
+ // pkg/commands/hmset.ts
1224
+ var HMSetCommand = class extends Command {
1225
+ constructor([key, kv], opts) {
1226
+ super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
1227
+ }
1228
+ };
1229
+
1230
+ // pkg/commands/hrandfield.ts
1231
+ function deserialize5(result) {
1232
+ if (result.length === 0) {
1233
+ return null;
1234
+ }
1235
+ const obj = {};
1236
+ for (let i = 0; i < result.length; i += 2) {
1237
+ const key = result[i];
1238
+ const value = result[i + 1];
1239
+ try {
1240
+ obj[key] = JSON.parse(value);
1241
+ } catch {
1242
+ obj[key] = value;
1243
+ }
1244
+ }
1245
+ return obj;
1246
+ }
1247
+ var HRandFieldCommand = class extends Command {
1248
+ constructor(cmd, opts) {
1249
+ const command = ["hrandfield", cmd[0]];
1250
+ if (typeof cmd[1] === "number") {
1251
+ command.push(cmd[1]);
1252
+ }
1253
+ if (cmd[2]) {
1254
+ command.push("WITHVALUES");
1255
+ }
1256
+ super(command, {
1257
+ // @ts-expect-error to silence compiler
1258
+ deserialize: cmd[2] ? (result) => deserialize5(result) : opts?.deserialize,
1259
+ ...opts
1260
+ });
1261
+ }
1262
+ };
1263
+
1264
+ // pkg/commands/hscan.ts
1265
+ var HScanCommand = class extends Command {
1266
+ constructor([key, cursor, cmdOpts], opts) {
1267
+ const command = ["hscan", key, cursor];
1268
+ if (cmdOpts?.match) {
1269
+ command.push("match", cmdOpts.match);
1270
+ }
1271
+ if (typeof cmdOpts?.count === "number") {
1272
+ command.push("count", cmdOpts.count);
1273
+ }
1274
+ super(command, {
1275
+ deserialize: deserializeScanResponse,
1276
+ ...opts
1277
+ });
1278
+ }
1279
+ };
1280
+
1281
+ // pkg/commands/hset.ts
1282
+ var HSetCommand = class extends Command {
1283
+ constructor([key, kv], opts) {
1284
+ super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
1285
+ }
1286
+ };
1287
+
1288
+ // pkg/commands/hsetnx.ts
1289
+ var HSetNXCommand = class extends Command {
1290
+ constructor(cmd, opts) {
1291
+ super(["hsetnx", ...cmd], opts);
1292
+ }
1293
+ };
1294
+
1295
+ // pkg/commands/hstrlen.ts
1296
+ var HStrLenCommand = class extends Command {
1297
+ constructor(cmd, opts) {
1298
+ super(["hstrlen", ...cmd], opts);
1299
+ }
1300
+ };
1301
+
1302
+ // pkg/commands/httl.ts
1303
+ var HTtlCommand = class extends Command {
1304
+ constructor(cmd, opts) {
1305
+ const [key, fields] = cmd;
1306
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1307
+ super(["httl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1308
+ }
1309
+ };
1310
+
1311
+ // pkg/commands/hvals.ts
1312
+ var HValsCommand = class extends Command {
1313
+ constructor(cmd, opts) {
1314
+ super(["hvals", ...cmd], opts);
1315
+ }
1316
+ };
1317
+
1318
+ // pkg/commands/incr.ts
1319
+ var IncrCommand = class extends Command {
1320
+ constructor(cmd, opts) {
1321
+ super(["incr", ...cmd], opts);
1322
+ }
1323
+ };
1324
+
1325
+ // pkg/commands/incrby.ts
1326
+ var IncrByCommand = class extends Command {
1327
+ constructor(cmd, opts) {
1328
+ super(["incrby", ...cmd], opts);
1329
+ }
1330
+ };
1331
+
1332
+ // pkg/commands/incrbyfloat.ts
1333
+ var IncrByFloatCommand = class extends Command {
1334
+ constructor(cmd, opts) {
1335
+ super(["incrbyfloat", ...cmd], opts);
1336
+ }
1337
+ };
1338
+
1339
+ // pkg/commands/json_arrappend.ts
1340
+ var JsonArrAppendCommand = class extends Command {
1341
+ constructor(cmd, opts) {
1342
+ super(["JSON.ARRAPPEND", ...cmd], opts);
1343
+ }
1344
+ };
1345
+
1346
+ // pkg/commands/json_arrindex.ts
1347
+ var JsonArrIndexCommand = class extends Command {
1348
+ constructor(cmd, opts) {
1349
+ super(["JSON.ARRINDEX", ...cmd], opts);
1350
+ }
1351
+ };
1352
+
1353
+ // pkg/commands/json_arrinsert.ts
1354
+ var JsonArrInsertCommand = class extends Command {
1355
+ constructor(cmd, opts) {
1356
+ super(["JSON.ARRINSERT", ...cmd], opts);
1357
+ }
1358
+ };
1359
+
1360
+ // pkg/commands/json_arrlen.ts
1361
+ var JsonArrLenCommand = class extends Command {
1362
+ constructor(cmd, opts) {
1363
+ super(["JSON.ARRLEN", cmd[0], cmd[1] ?? "$"], opts);
1364
+ }
1365
+ };
1366
+
1367
+ // pkg/commands/json_arrpop.ts
1368
+ var JsonArrPopCommand = class extends Command {
1369
+ constructor(cmd, opts) {
1370
+ super(["JSON.ARRPOP", ...cmd], opts);
1371
+ }
1372
+ };
1373
+
1374
+ // pkg/commands/json_arrtrim.ts
1375
+ var JsonArrTrimCommand = class extends Command {
1376
+ constructor(cmd, opts) {
1377
+ const path = cmd[1] ?? "$";
1378
+ const start = cmd[2] ?? 0;
1379
+ const stop = cmd[3] ?? 0;
1380
+ super(["JSON.ARRTRIM", cmd[0], path, start, stop], opts);
1381
+ }
1382
+ };
1383
+
1384
+ // pkg/commands/json_clear.ts
1385
+ var JsonClearCommand = class extends Command {
1386
+ constructor(cmd, opts) {
1387
+ super(["JSON.CLEAR", ...cmd], opts);
1388
+ }
1389
+ };
1390
+
1391
+ // pkg/commands/json_del.ts
1392
+ var JsonDelCommand = class extends Command {
1393
+ constructor(cmd, opts) {
1394
+ super(["JSON.DEL", ...cmd], opts);
1395
+ }
1396
+ };
1397
+
1398
+ // pkg/commands/json_forget.ts
1399
+ var JsonForgetCommand = class extends Command {
1400
+ constructor(cmd, opts) {
1401
+ super(["JSON.FORGET", ...cmd], opts);
1402
+ }
1403
+ };
1404
+
1405
+ // pkg/commands/json_get.ts
1406
+ var JsonGetCommand = class extends Command {
1407
+ constructor(cmd, opts) {
1408
+ const command = ["JSON.GET"];
1409
+ if (typeof cmd[1] === "string") {
1410
+ command.push(...cmd);
1411
+ } else {
1412
+ command.push(cmd[0]);
1413
+ if (cmd[1]) {
1414
+ if (cmd[1].indent) {
1415
+ command.push("INDENT", cmd[1].indent);
1416
+ }
1417
+ if (cmd[1].newline) {
1418
+ command.push("NEWLINE", cmd[1].newline);
1419
+ }
1420
+ if (cmd[1].space) {
1421
+ command.push("SPACE", cmd[1].space);
1422
+ }
1423
+ }
1424
+ command.push(...cmd.slice(2));
1425
+ }
1426
+ super(command, opts);
1427
+ }
1428
+ };
1429
+
1430
+ // pkg/commands/json_merge.ts
1431
+ var JsonMergeCommand = class extends Command {
1432
+ constructor(cmd, opts) {
1433
+ const command = ["JSON.MERGE", ...cmd];
1434
+ super(command, opts);
1435
+ }
1436
+ };
1437
+
1438
+ // pkg/commands/json_mget.ts
1439
+ var JsonMGetCommand = class extends Command {
1440
+ constructor(cmd, opts) {
1441
+ super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
1442
+ }
1443
+ };
1444
+
1445
+ // pkg/commands/json_mset.ts
1446
+ var JsonMSetCommand = class extends Command {
1447
+ constructor(cmd, opts) {
1448
+ const command = ["JSON.MSET"];
1449
+ for (const c of cmd) {
1450
+ command.push(c.key, c.path, c.value);
1451
+ }
1452
+ super(command, opts);
1453
+ }
1454
+ };
1455
+
1456
+ // pkg/commands/json_numincrby.ts
1457
+ var JsonNumIncrByCommand = class extends Command {
1458
+ constructor(cmd, opts) {
1459
+ super(["JSON.NUMINCRBY", ...cmd], opts);
1460
+ }
1461
+ };
1462
+
1463
+ // pkg/commands/json_nummultby.ts
1464
+ var JsonNumMultByCommand = class extends Command {
1465
+ constructor(cmd, opts) {
1466
+ super(["JSON.NUMMULTBY", ...cmd], opts);
1467
+ }
1468
+ };
1469
+
1470
+ // pkg/commands/json_objkeys.ts
1471
+ var JsonObjKeysCommand = class extends Command {
1472
+ constructor(cmd, opts) {
1473
+ super(["JSON.OBJKEYS", ...cmd], opts);
1474
+ }
1475
+ };
1476
+
1477
+ // pkg/commands/json_objlen.ts
1478
+ var JsonObjLenCommand = class extends Command {
1479
+ constructor(cmd, opts) {
1480
+ super(["JSON.OBJLEN", ...cmd], opts);
1481
+ }
1482
+ };
1483
+
1484
+ // pkg/commands/json_resp.ts
1485
+ var JsonRespCommand = class extends Command {
1486
+ constructor(cmd, opts) {
1487
+ super(["JSON.RESP", ...cmd], opts);
1488
+ }
1489
+ };
1490
+
1491
+ // pkg/commands/json_set.ts
1492
+ var JsonSetCommand = class extends Command {
1493
+ constructor(cmd, opts) {
1494
+ const command = ["JSON.SET", cmd[0], cmd[1], cmd[2]];
1495
+ if (cmd[3]) {
1496
+ if (cmd[3].nx) {
1497
+ command.push("NX");
1498
+ } else if (cmd[3].xx) {
1499
+ command.push("XX");
1500
+ }
1501
+ }
1502
+ super(command, opts);
1503
+ }
1504
+ };
1505
+
1506
+ // pkg/commands/json_strappend.ts
1507
+ var JsonStrAppendCommand = class extends Command {
1508
+ constructor(cmd, opts) {
1509
+ super(["JSON.STRAPPEND", ...cmd], opts);
1510
+ }
1511
+ };
1512
+
1513
+ // pkg/commands/json_strlen.ts
1514
+ var JsonStrLenCommand = class extends Command {
1515
+ constructor(cmd, opts) {
1516
+ super(["JSON.STRLEN", ...cmd], opts);
1517
+ }
1518
+ };
1519
+
1520
+ // pkg/commands/json_toggle.ts
1521
+ var JsonToggleCommand = class extends Command {
1522
+ constructor(cmd, opts) {
1523
+ super(["JSON.TOGGLE", ...cmd], opts);
1524
+ }
1525
+ };
1526
+
1527
+ // pkg/commands/json_type.ts
1528
+ var JsonTypeCommand = class extends Command {
1529
+ constructor(cmd, opts) {
1530
+ super(["JSON.TYPE", ...cmd], opts);
1531
+ }
1532
+ };
1533
+
1534
+ // pkg/commands/keys.ts
1535
+ var KeysCommand = class extends Command {
1536
+ constructor(cmd, opts) {
1537
+ super(["keys", ...cmd], opts);
1538
+ }
1539
+ };
1540
+
1541
+ // pkg/commands/lindex.ts
1542
+ var LIndexCommand = class extends Command {
1543
+ constructor(cmd, opts) {
1544
+ super(["lindex", ...cmd], opts);
1545
+ }
1546
+ };
1547
+
1548
+ // pkg/commands/linsert.ts
1549
+ var LInsertCommand = class extends Command {
1550
+ constructor(cmd, opts) {
1551
+ super(["linsert", ...cmd], opts);
1552
+ }
1553
+ };
1554
+
1555
+ // pkg/commands/llen.ts
1556
+ var LLenCommand = class extends Command {
1557
+ constructor(cmd, opts) {
1558
+ super(["llen", ...cmd], opts);
1559
+ }
1560
+ };
1561
+
1562
+ // pkg/commands/lmove.ts
1563
+ var LMoveCommand = class extends Command {
1564
+ constructor(cmd, opts) {
1565
+ super(["lmove", ...cmd], opts);
1566
+ }
1567
+ };
1568
+
1569
+ // pkg/commands/lmpop.ts
1570
+ var LmPopCommand = class extends Command {
1571
+ constructor(cmd, opts) {
1572
+ const [numkeys, keys, direction, count] = cmd;
1573
+ super(["LMPOP", numkeys, ...keys, direction, ...count ? ["COUNT", count] : []], opts);
1574
+ }
1575
+ };
1576
+
1577
+ // pkg/commands/lpop.ts
1578
+ var LPopCommand = class extends Command {
1579
+ constructor(cmd, opts) {
1580
+ super(["lpop", ...cmd], opts);
1581
+ }
1582
+ };
1583
+
1584
+ // pkg/commands/lpos.ts
1585
+ var LPosCommand = class extends Command {
1586
+ constructor(cmd, opts) {
1587
+ const args = ["lpos", cmd[0], cmd[1]];
1588
+ if (typeof cmd[2]?.rank === "number") {
1589
+ args.push("rank", cmd[2].rank);
1590
+ }
1591
+ if (typeof cmd[2]?.count === "number") {
1592
+ args.push("count", cmd[2].count);
1593
+ }
1594
+ if (typeof cmd[2]?.maxLen === "number") {
1595
+ args.push("maxLen", cmd[2].maxLen);
1596
+ }
1597
+ super(args, opts);
1598
+ }
1599
+ };
1600
+
1601
+ // pkg/commands/lpush.ts
1602
+ var LPushCommand = class extends Command {
1603
+ constructor(cmd, opts) {
1604
+ super(["lpush", ...cmd], opts);
1605
+ }
1606
+ };
1607
+
1608
+ // pkg/commands/lpushx.ts
1609
+ var LPushXCommand = class extends Command {
1610
+ constructor(cmd, opts) {
1611
+ super(["lpushx", ...cmd], opts);
1612
+ }
1613
+ };
1614
+
1615
+ // pkg/commands/lrange.ts
1616
+ var LRangeCommand = class extends Command {
1617
+ constructor(cmd, opts) {
1618
+ super(["lrange", ...cmd], opts);
1619
+ }
1620
+ };
1621
+
1622
+ // pkg/commands/lrem.ts
1623
+ var LRemCommand = class extends Command {
1624
+ constructor(cmd, opts) {
1625
+ super(["lrem", ...cmd], opts);
1626
+ }
1627
+ };
1628
+
1629
+ // pkg/commands/lset.ts
1630
+ var LSetCommand = class extends Command {
1631
+ constructor(cmd, opts) {
1632
+ super(["lset", ...cmd], opts);
1633
+ }
1634
+ };
1635
+
1636
+ // pkg/commands/ltrim.ts
1637
+ var LTrimCommand = class extends Command {
1638
+ constructor(cmd, opts) {
1639
+ super(["ltrim", ...cmd], opts);
1640
+ }
1641
+ };
1642
+
1643
+ // pkg/commands/mget.ts
1644
+ var MGetCommand = class extends Command {
1645
+ constructor(cmd, opts) {
1646
+ const keys = Array.isArray(cmd[0]) ? cmd[0] : cmd;
1647
+ super(["mget", ...keys], opts);
1648
+ }
1649
+ };
1650
+
1651
+ // pkg/commands/mset.ts
1652
+ var MSetCommand = class extends Command {
1653
+ constructor([kv], opts) {
1654
+ super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])], opts);
1655
+ }
1656
+ };
1657
+
1658
+ // pkg/commands/msetnx.ts
1659
+ var MSetNXCommand = class extends Command {
1660
+ constructor([kv], opts) {
1661
+ super(["msetnx", ...Object.entries(kv).flat()], opts);
1662
+ }
1663
+ };
1664
+
1665
+ // pkg/commands/persist.ts
1666
+ var PersistCommand = class extends Command {
1667
+ constructor(cmd, opts) {
1668
+ super(["persist", ...cmd], opts);
1669
+ }
1670
+ };
1671
+
1672
+ // pkg/commands/pexpire.ts
1673
+ var PExpireCommand = class extends Command {
1674
+ constructor(cmd, opts) {
1675
+ super(["pexpire", ...cmd], opts);
1676
+ }
1677
+ };
1678
+
1679
+ // pkg/commands/pexpireat.ts
1680
+ var PExpireAtCommand = class extends Command {
1681
+ constructor(cmd, opts) {
1682
+ super(["pexpireat", ...cmd], opts);
1683
+ }
1684
+ };
1685
+
1686
+ // pkg/commands/pfadd.ts
1687
+ var PfAddCommand = class extends Command {
1688
+ constructor(cmd, opts) {
1689
+ super(["pfadd", ...cmd], opts);
1690
+ }
1691
+ };
1692
+
1693
+ // pkg/commands/pfcount.ts
1694
+ var PfCountCommand = class extends Command {
1695
+ constructor(cmd, opts) {
1696
+ super(["pfcount", ...cmd], opts);
1697
+ }
1698
+ };
1699
+
1700
+ // pkg/commands/pfmerge.ts
1701
+ var PfMergeCommand = class extends Command {
1702
+ constructor(cmd, opts) {
1703
+ super(["pfmerge", ...cmd], opts);
1704
+ }
1705
+ };
1706
+
1707
+ // pkg/commands/ping.ts
1708
+ var PingCommand = class extends Command {
1709
+ constructor(cmd, opts) {
1710
+ const command = ["ping"];
1711
+ if (cmd?.[0] !== void 0) {
1712
+ command.push(cmd[0]);
1713
+ }
1714
+ super(command, opts);
1715
+ }
1716
+ };
1717
+
1718
+ // pkg/commands/psetex.ts
1719
+ var PSetEXCommand = class extends Command {
1720
+ constructor(cmd, opts) {
1721
+ super(["psetex", ...cmd], opts);
1722
+ }
1723
+ };
1724
+
1725
+ // pkg/commands/pttl.ts
1726
+ var PTtlCommand = class extends Command {
1727
+ constructor(cmd, opts) {
1728
+ super(["pttl", ...cmd], opts);
1729
+ }
1730
+ };
1731
+
1732
+ // pkg/commands/publish.ts
1733
+ var PublishCommand = class extends Command {
1734
+ constructor(cmd, opts) {
1735
+ super(["publish", ...cmd], opts);
1736
+ }
1737
+ };
1738
+
1739
+ // pkg/commands/randomkey.ts
1740
+ var RandomKeyCommand = class extends Command {
1741
+ constructor(opts) {
1742
+ super(["randomkey"], opts);
1743
+ }
1744
+ };
1745
+
1746
+ // pkg/commands/rename.ts
1747
+ var RenameCommand = class extends Command {
1748
+ constructor(cmd, opts) {
1749
+ super(["rename", ...cmd], opts);
1750
+ }
1751
+ };
1752
+
1753
+ // pkg/commands/renamenx.ts
1754
+ var RenameNXCommand = class extends Command {
1755
+ constructor(cmd, opts) {
1756
+ super(["renamenx", ...cmd], opts);
1757
+ }
1758
+ };
1759
+
1760
+ // pkg/commands/rpop.ts
1761
+ var RPopCommand = class extends Command {
1762
+ constructor(cmd, opts) {
1763
+ super(["rpop", ...cmd], opts);
1764
+ }
1765
+ };
1766
+
1767
+ // pkg/commands/rpush.ts
1768
+ var RPushCommand = class extends Command {
1769
+ constructor(cmd, opts) {
1770
+ super(["rpush", ...cmd], opts);
1771
+ }
1772
+ };
1773
+
1774
+ // pkg/commands/rpushx.ts
1775
+ var RPushXCommand = class extends Command {
1776
+ constructor(cmd, opts) {
1777
+ super(["rpushx", ...cmd], opts);
1778
+ }
1779
+ };
1780
+
1781
+ // pkg/commands/sadd.ts
1782
+ var SAddCommand = class extends Command {
1783
+ constructor(cmd, opts) {
1784
+ super(["sadd", ...cmd], opts);
1785
+ }
1786
+ };
1787
+
1788
+ // pkg/commands/scan.ts
1789
+ var ScanCommand = class extends Command {
1790
+ constructor([cursor, opts], cmdOpts) {
1791
+ const command = ["scan", cursor];
1792
+ if (opts?.match) {
1793
+ command.push("match", opts.match);
1794
+ }
1795
+ if (typeof opts?.count === "number") {
1796
+ command.push("count", opts.count);
1797
+ }
1798
+ if (opts && "withType" in opts && opts.withType === true) {
1799
+ command.push("withtype");
1800
+ } else if (opts && "type" in opts && opts.type && opts.type.length > 0) {
1801
+ command.push("type", opts.type);
1802
+ }
1803
+ super(command, {
1804
+ // @ts-expect-error ignore types here
1805
+ deserialize: opts?.withType ? deserializeScanWithTypesResponse : deserializeScanResponse,
1806
+ ...cmdOpts
1807
+ });
1808
+ }
1809
+ };
1810
+
1811
+ // pkg/commands/scard.ts
1812
+ var SCardCommand = class extends Command {
1813
+ constructor(cmd, opts) {
1814
+ super(["scard", ...cmd], opts);
1815
+ }
1816
+ };
1817
+
1818
+ // pkg/commands/script_exists.ts
1819
+ var ScriptExistsCommand = class extends Command {
1820
+ constructor(hashes, opts) {
1821
+ super(["script", "exists", ...hashes], {
1822
+ deserialize: (result) => result,
1823
+ ...opts
1824
+ });
1825
+ }
1826
+ };
1827
+
1828
+ // pkg/commands/script_flush.ts
1829
+ var ScriptFlushCommand = class extends Command {
1830
+ constructor([opts], cmdOpts) {
1831
+ const cmd = ["script", "flush"];
1832
+ if (opts?.sync) {
1833
+ cmd.push("sync");
1834
+ } else if (opts?.async) {
1835
+ cmd.push("async");
1836
+ }
1837
+ super(cmd, cmdOpts);
1838
+ }
1839
+ };
1840
+
1841
+ // pkg/commands/script_load.ts
1842
+ var ScriptLoadCommand = class extends Command {
1843
+ constructor(args, opts) {
1844
+ super(["script", "load", ...args], opts);
1845
+ }
1846
+ };
1847
+
1848
+ // pkg/commands/sdiff.ts
1849
+ var SDiffCommand = class extends Command {
1850
+ constructor(cmd, opts) {
1851
+ super(["sdiff", ...cmd], opts);
1852
+ }
1853
+ };
1854
+
1855
+ // pkg/commands/sdiffstore.ts
1856
+ var SDiffStoreCommand = class extends Command {
1857
+ constructor(cmd, opts) {
1858
+ super(["sdiffstore", ...cmd], opts);
1859
+ }
1860
+ };
1861
+
1862
+ // pkg/commands/set.ts
1863
+ var SetCommand = class extends Command {
1864
+ constructor([key, value, opts], cmdOpts) {
1865
+ const command = ["set", key, value];
1866
+ if (opts) {
1867
+ if ("nx" in opts && opts.nx) {
1868
+ command.push("nx");
1869
+ } else if ("xx" in opts && opts.xx) {
1870
+ command.push("xx");
1871
+ }
1872
+ if ("get" in opts && opts.get) {
1873
+ command.push("get");
1874
+ }
1875
+ if ("ex" in opts && typeof opts.ex === "number") {
1876
+ command.push("ex", opts.ex);
1877
+ } else if ("px" in opts && typeof opts.px === "number") {
1878
+ command.push("px", opts.px);
1879
+ } else if ("exat" in opts && typeof opts.exat === "number") {
1880
+ command.push("exat", opts.exat);
1881
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
1882
+ command.push("pxat", opts.pxat);
1883
+ } else if ("keepTtl" in opts && opts.keepTtl) {
1884
+ command.push("keepTtl");
1885
+ }
1886
+ }
1887
+ super(command, cmdOpts);
1888
+ }
1889
+ };
1890
+
1891
+ // pkg/commands/setbit.ts
1892
+ var SetBitCommand = class extends Command {
1893
+ constructor(cmd, opts) {
1894
+ super(["setbit", ...cmd], opts);
1895
+ }
1896
+ };
1897
+
1898
+ // pkg/commands/setex.ts
1899
+ var SetExCommand = class extends Command {
1900
+ constructor(cmd, opts) {
1901
+ super(["setex", ...cmd], opts);
1902
+ }
1903
+ };
1904
+
1905
+ // pkg/commands/setnx.ts
1906
+ var SetNxCommand = class extends Command {
1907
+ constructor(cmd, opts) {
1908
+ super(["setnx", ...cmd], opts);
1909
+ }
1910
+ };
1911
+
1912
+ // pkg/commands/setrange.ts
1913
+ var SetRangeCommand = class extends Command {
1914
+ constructor(cmd, opts) {
1915
+ super(["setrange", ...cmd], opts);
1916
+ }
1917
+ };
1918
+
1919
+ // pkg/commands/sinter.ts
1920
+ var SInterCommand = class extends Command {
1921
+ constructor(cmd, opts) {
1922
+ super(["sinter", ...cmd], opts);
1923
+ }
1924
+ };
1925
+
1926
+ // pkg/commands/sinterstore.ts
1927
+ var SInterStoreCommand = class extends Command {
1928
+ constructor(cmd, opts) {
1929
+ super(["sinterstore", ...cmd], opts);
1930
+ }
1931
+ };
1932
+
1933
+ // pkg/commands/sismember.ts
1934
+ var SIsMemberCommand = class extends Command {
1935
+ constructor(cmd, opts) {
1936
+ super(["sismember", ...cmd], opts);
1937
+ }
1938
+ };
1939
+
1940
+ // pkg/commands/smembers.ts
1941
+ var SMembersCommand = class extends Command {
1942
+ constructor(cmd, opts) {
1943
+ super(["smembers", ...cmd], opts);
1944
+ }
1945
+ };
1946
+
1947
+ // pkg/commands/smismember.ts
1948
+ var SMIsMemberCommand = class extends Command {
1949
+ constructor(cmd, opts) {
1950
+ super(["smismember", cmd[0], ...cmd[1]], opts);
1951
+ }
1952
+ };
1953
+
1954
+ // pkg/commands/smove.ts
1955
+ var SMoveCommand = class extends Command {
1956
+ constructor(cmd, opts) {
1957
+ super(["smove", ...cmd], opts);
1958
+ }
1959
+ };
1960
+
1961
+ // pkg/commands/spop.ts
1962
+ var SPopCommand = class extends Command {
1963
+ constructor([key, count], opts) {
1964
+ const command = ["spop", key];
1965
+ if (typeof count === "number") {
1966
+ command.push(count);
1967
+ }
1968
+ super(command, opts);
1969
+ }
1970
+ };
1971
+
1972
+ // pkg/commands/srandmember.ts
1973
+ var SRandMemberCommand = class extends Command {
1974
+ constructor([key, count], opts) {
1975
+ const command = ["srandmember", key];
1976
+ if (typeof count === "number") {
1977
+ command.push(count);
1978
+ }
1979
+ super(command, opts);
1980
+ }
1981
+ };
1982
+
1983
+ // pkg/commands/srem.ts
1984
+ var SRemCommand = class extends Command {
1985
+ constructor(cmd, opts) {
1986
+ super(["srem", ...cmd], opts);
1987
+ }
1988
+ };
1989
+
1990
+ // pkg/commands/sscan.ts
1991
+ var SScanCommand = class extends Command {
1992
+ constructor([key, cursor, opts], cmdOpts) {
1993
+ const command = ["sscan", key, cursor];
1994
+ if (opts?.match) {
1995
+ command.push("match", opts.match);
1996
+ }
1997
+ if (typeof opts?.count === "number") {
1998
+ command.push("count", opts.count);
1999
+ }
2000
+ super(command, {
2001
+ deserialize: deserializeScanResponse,
2002
+ ...cmdOpts
2003
+ });
2004
+ }
2005
+ };
2006
+
2007
+ // pkg/commands/strlen.ts
2008
+ var StrLenCommand = class extends Command {
2009
+ constructor(cmd, opts) {
2010
+ super(["strlen", ...cmd], opts);
2011
+ }
2012
+ };
2013
+
2014
+ // pkg/commands/sunion.ts
2015
+ var SUnionCommand = class extends Command {
2016
+ constructor(cmd, opts) {
2017
+ super(["sunion", ...cmd], opts);
2018
+ }
2019
+ };
2020
+
2021
+ // pkg/commands/sunionstore.ts
2022
+ var SUnionStoreCommand = class extends Command {
2023
+ constructor(cmd, opts) {
2024
+ super(["sunionstore", ...cmd], opts);
2025
+ }
2026
+ };
2027
+
2028
+ // pkg/commands/time.ts
2029
+ var TimeCommand = class extends Command {
2030
+ constructor(opts) {
2031
+ super(["time"], opts);
2032
+ }
2033
+ };
2034
+
2035
+ // pkg/commands/touch.ts
2036
+ var TouchCommand = class extends Command {
2037
+ constructor(cmd, opts) {
2038
+ super(["touch", ...cmd], opts);
2039
+ }
2040
+ };
2041
+
2042
+ // pkg/commands/ttl.ts
2043
+ var TtlCommand = class extends Command {
2044
+ constructor(cmd, opts) {
2045
+ super(["ttl", ...cmd], opts);
2046
+ }
2047
+ };
2048
+
2049
+ // pkg/commands/type.ts
2050
+ var TypeCommand = class extends Command {
2051
+ constructor(cmd, opts) {
2052
+ super(["type", ...cmd], opts);
2053
+ }
2054
+ };
2055
+
2056
+ // pkg/commands/unlink.ts
2057
+ var UnlinkCommand = class extends Command {
2058
+ constructor(cmd, opts) {
2059
+ super(["unlink", ...cmd], opts);
2060
+ }
2061
+ };
2062
+
2063
+ // pkg/commands/xack.ts
2064
+ var XAckCommand = class extends Command {
2065
+ constructor([key, group, id], opts) {
2066
+ const ids = Array.isArray(id) ? [...id] : [id];
2067
+ super(["XACK", key, group, ...ids], opts);
2068
+ }
2069
+ };
2070
+
2071
+ // pkg/commands/xadd.ts
2072
+ var XAddCommand = class extends Command {
2073
+ constructor([key, id, entries, opts], commandOptions) {
2074
+ const command = ["XADD", key];
2075
+ if (opts) {
2076
+ if (opts.nomkStream) {
2077
+ command.push("NOMKSTREAM");
2078
+ }
2079
+ if (opts.trim) {
2080
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
2081
+ if (opts.trim.limit !== void 0) {
2082
+ command.push("LIMIT", opts.trim.limit);
2083
+ }
2084
+ }
2085
+ }
2086
+ command.push(id);
2087
+ for (const [k, v] of Object.entries(entries)) {
2088
+ command.push(k, v);
2089
+ }
2090
+ super(command, commandOptions);
2091
+ }
2092
+ };
2093
+
2094
+ // pkg/commands/xautoclaim.ts
2095
+ var XAutoClaim = class extends Command {
2096
+ constructor([key, group, consumer, minIdleTime, start, options], opts) {
2097
+ const commands = [];
2098
+ if (options?.count) {
2099
+ commands.push("COUNT", options.count);
2100
+ }
2101
+ if (options?.justId) {
2102
+ commands.push("JUSTID");
2103
+ }
2104
+ super(["XAUTOCLAIM", key, group, consumer, minIdleTime, start, ...commands], opts);
2105
+ }
2106
+ };
2107
+
2108
+ // pkg/commands/xclaim.ts
2109
+ var XClaimCommand = class extends Command {
2110
+ constructor([key, group, consumer, minIdleTime, id, options], opts) {
2111
+ const ids = Array.isArray(id) ? [...id] : [id];
2112
+ const commands = [];
2113
+ if (options?.idleMS) {
2114
+ commands.push("IDLE", options.idleMS);
2115
+ }
2116
+ if (options?.idleMS) {
2117
+ commands.push("TIME", options.timeMS);
2118
+ }
2119
+ if (options?.retryCount) {
2120
+ commands.push("RETRYCOUNT", options.retryCount);
2121
+ }
2122
+ if (options?.force) {
2123
+ commands.push("FORCE");
2124
+ }
2125
+ if (options?.justId) {
2126
+ commands.push("JUSTID");
2127
+ }
2128
+ if (options?.lastId) {
2129
+ commands.push("LASTID", options.lastId);
2130
+ }
2131
+ super(["XCLAIM", key, group, consumer, minIdleTime, ...ids, ...commands], opts);
2132
+ }
2133
+ };
2134
+
2135
+ // pkg/commands/xdel.ts
2136
+ var XDelCommand = class extends Command {
2137
+ constructor([key, ids], opts) {
2138
+ const cmds = Array.isArray(ids) ? [...ids] : [ids];
2139
+ super(["XDEL", key, ...cmds], opts);
2140
+ }
2141
+ };
2142
+
2143
+ // pkg/commands/xgroup.ts
2144
+ var XGroupCommand = class extends Command {
2145
+ constructor([key, opts], commandOptions) {
2146
+ const command = ["XGROUP"];
2147
+ switch (opts.type) {
2148
+ case "CREATE": {
2149
+ command.push("CREATE", key, opts.group, opts.id);
2150
+ if (opts.options) {
2151
+ if (opts.options.MKSTREAM) {
2152
+ command.push("MKSTREAM");
2153
+ }
2154
+ if (opts.options.ENTRIESREAD !== void 0) {
2155
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
2156
+ }
2157
+ }
2158
+ break;
2159
+ }
2160
+ case "CREATECONSUMER": {
2161
+ command.push("CREATECONSUMER", key, opts.group, opts.consumer);
2162
+ break;
2163
+ }
2164
+ case "DELCONSUMER": {
2165
+ command.push("DELCONSUMER", key, opts.group, opts.consumer);
2166
+ break;
2167
+ }
2168
+ case "DESTROY": {
2169
+ command.push("DESTROY", key, opts.group);
2170
+ break;
2171
+ }
2172
+ case "SETID": {
2173
+ command.push("SETID", key, opts.group, opts.id);
2174
+ if (opts.options?.ENTRIESREAD !== void 0) {
2175
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
2176
+ }
2177
+ break;
2178
+ }
2179
+ default: {
2180
+ throw new Error("Invalid XGROUP");
2181
+ }
2182
+ }
2183
+ super(command, commandOptions);
2184
+ }
2185
+ };
2186
+
2187
+ // pkg/commands/xinfo.ts
2188
+ var XInfoCommand = class extends Command {
2189
+ constructor([key, options], opts) {
2190
+ const cmds = [];
2191
+ if (options.type === "CONSUMERS") {
2192
+ cmds.push("CONSUMERS", key, options.group);
2193
+ } else {
2194
+ cmds.push("GROUPS", key);
2195
+ }
2196
+ super(["XINFO", ...cmds], opts);
2197
+ }
2198
+ };
2199
+
2200
+ // pkg/commands/xlen.ts
2201
+ var XLenCommand = class extends Command {
2202
+ constructor(cmd, opts) {
2203
+ super(["XLEN", ...cmd], opts);
2204
+ }
2205
+ };
2206
+
2207
+ // pkg/commands/xpending.ts
2208
+ var XPendingCommand = class extends Command {
2209
+ constructor([key, group, start, end, count, options], opts) {
2210
+ const consumers = options?.consumer === void 0 ? [] : Array.isArray(options.consumer) ? [...options.consumer] : [options.consumer];
2211
+ super(
2212
+ [
2213
+ "XPENDING",
2214
+ key,
2215
+ group,
2216
+ ...options?.idleTime ? ["IDLE", options.idleTime] : [],
2217
+ start,
2218
+ end,
2219
+ count,
2220
+ ...consumers
2221
+ ],
2222
+ opts
2223
+ );
2224
+ }
2225
+ };
2226
+
2227
+ // pkg/commands/xrange.ts
2228
+ function deserialize6(result) {
2229
+ const obj = {};
2230
+ for (const e of result) {
2231
+ for (let i = 0; i < e.length; i += 2) {
2232
+ const streamId = e[i];
2233
+ const entries = e[i + 1];
2234
+ if (!(streamId in obj)) {
2235
+ obj[streamId] = {};
2236
+ }
2237
+ for (let j = 0; j < entries.length; j += 2) {
2238
+ const field = entries[j];
2239
+ const value = entries[j + 1];
2240
+ try {
2241
+ obj[streamId][field] = JSON.parse(value);
2242
+ } catch {
2243
+ obj[streamId][field] = value;
2244
+ }
2245
+ }
2246
+ }
2247
+ }
2248
+ return obj;
2249
+ }
2250
+ var XRangeCommand = class extends Command {
2251
+ constructor([key, start, end, count], opts) {
2252
+ const command = ["XRANGE", key, start, end];
2253
+ if (typeof count === "number") {
2254
+ command.push("COUNT", count);
2255
+ }
2256
+ super(command, {
2257
+ deserialize: (result) => deserialize6(result),
2258
+ ...opts
2259
+ });
2260
+ }
2261
+ };
2262
+
2263
+ // pkg/commands/xread.ts
2264
+ var UNBALANCED_XREAD_ERR = "ERR Unbalanced XREAD list of streams: for each stream key an ID or '$' must be specified";
2265
+ var XReadCommand = class extends Command {
2266
+ constructor([key, id, options], opts) {
2267
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
2268
+ throw new Error(UNBALANCED_XREAD_ERR);
2269
+ }
2270
+ const commands = [];
2271
+ if (typeof options?.count === "number") {
2272
+ commands.push("COUNT", options.count);
2273
+ }
2274
+ if (typeof options?.blockMS === "number") {
2275
+ commands.push("BLOCK", options.blockMS);
2276
+ }
2277
+ commands.push(
2278
+ "STREAMS",
2279
+ ...Array.isArray(key) ? [...key] : [key],
2280
+ ...Array.isArray(id) ? [...id] : [id]
2281
+ );
2282
+ super(["XREAD", ...commands], opts);
2283
+ }
2284
+ };
2285
+
2286
+ // pkg/commands/xreadgroup.ts
2287
+ var UNBALANCED_XREADGROUP_ERR = "ERR Unbalanced XREADGROUP list of streams: for each stream key an ID or '$' must be specified";
2288
+ var XReadGroupCommand = class extends Command {
2289
+ constructor([group, consumer, key, id, options], opts) {
2290
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
2291
+ throw new Error(UNBALANCED_XREADGROUP_ERR);
2292
+ }
2293
+ const commands = [];
2294
+ if (typeof options?.count === "number") {
2295
+ commands.push("COUNT", options.count);
2296
+ }
2297
+ if (typeof options?.blockMS === "number") {
2298
+ commands.push("BLOCK", options.blockMS);
2299
+ }
2300
+ if (typeof options?.NOACK === "boolean" && options.NOACK) {
2301
+ commands.push("NOACK");
2302
+ }
2303
+ commands.push(
2304
+ "STREAMS",
2305
+ ...Array.isArray(key) ? [...key] : [key],
2306
+ ...Array.isArray(id) ? [...id] : [id]
2307
+ );
2308
+ super(["XREADGROUP", "GROUP", group, consumer, ...commands], opts);
2309
+ }
2310
+ };
2311
+
2312
+ // pkg/commands/xrevrange.ts
2313
+ var XRevRangeCommand = class extends Command {
2314
+ constructor([key, end, start, count], opts) {
2315
+ const command = ["XREVRANGE", key, end, start];
2316
+ if (typeof count === "number") {
2317
+ command.push("COUNT", count);
2318
+ }
2319
+ super(command, {
2320
+ deserialize: (result) => deserialize7(result),
2321
+ ...opts
2322
+ });
2323
+ }
2324
+ };
2325
+ function deserialize7(result) {
2326
+ const obj = {};
2327
+ for (const e of result) {
2328
+ for (let i = 0; i < e.length; i += 2) {
2329
+ const streamId = e[i];
2330
+ const entries = e[i + 1];
2331
+ if (!(streamId in obj)) {
2332
+ obj[streamId] = {};
2333
+ }
2334
+ for (let j = 0; j < entries.length; j += 2) {
2335
+ const field = entries[j];
2336
+ const value = entries[j + 1];
2337
+ try {
2338
+ obj[streamId][field] = JSON.parse(value);
2339
+ } catch {
2340
+ obj[streamId][field] = value;
2341
+ }
2342
+ }
2343
+ }
2344
+ }
2345
+ return obj;
2346
+ }
2347
+
2348
+ // pkg/commands/xtrim.ts
2349
+ var XTrimCommand = class extends Command {
2350
+ constructor([key, options], opts) {
2351
+ const { limit, strategy, threshold, exactness = "~" } = options;
2352
+ super(["XTRIM", key, strategy, exactness, threshold, ...limit ? ["LIMIT", limit] : []], opts);
2353
+ }
2354
+ };
2355
+
2356
+ // pkg/commands/zadd.ts
2357
+ var ZAddCommand = class extends Command {
2358
+ constructor([key, arg1, ...arg2], opts) {
2359
+ const command = ["zadd", key];
2360
+ if ("nx" in arg1 && arg1.nx) {
2361
+ command.push("nx");
2362
+ } else if ("xx" in arg1 && arg1.xx) {
2363
+ command.push("xx");
2364
+ }
2365
+ if ("ch" in arg1 && arg1.ch) {
2366
+ command.push("ch");
2367
+ }
2368
+ if ("incr" in arg1 && arg1.incr) {
2369
+ command.push("incr");
2370
+ }
2371
+ if ("lt" in arg1 && arg1.lt) {
2372
+ command.push("lt");
2373
+ } else if ("gt" in arg1 && arg1.gt) {
2374
+ command.push("gt");
2375
+ }
2376
+ if ("score" in arg1 && "member" in arg1) {
2377
+ command.push(arg1.score, arg1.member);
2378
+ }
2379
+ command.push(...arg2.flatMap(({ score, member }) => [score, member]));
2380
+ super(command, opts);
2381
+ }
2382
+ };
2383
+
2384
+ // pkg/commands/zcard.ts
2385
+ var ZCardCommand = class extends Command {
2386
+ constructor(cmd, opts) {
2387
+ super(["zcard", ...cmd], opts);
2388
+ }
2389
+ };
2390
+
2391
+ // pkg/commands/zcount.ts
2392
+ var ZCountCommand = class extends Command {
2393
+ constructor(cmd, opts) {
2394
+ super(["zcount", ...cmd], opts);
2395
+ }
2396
+ };
2397
+
2398
+ // pkg/commands/zincrby.ts
2399
+ var ZIncrByCommand = class extends Command {
2400
+ constructor(cmd, opts) {
2401
+ super(["zincrby", ...cmd], opts);
2402
+ }
2403
+ };
2404
+
2405
+ // pkg/commands/zinterstore.ts
2406
+ var ZInterStoreCommand = class extends Command {
2407
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2408
+ const command = ["zinterstore", destination, numKeys];
2409
+ if (Array.isArray(keyOrKeys)) {
2410
+ command.push(...keyOrKeys);
2411
+ } else {
2412
+ command.push(keyOrKeys);
2413
+ }
2414
+ if (opts) {
2415
+ if ("weights" in opts && opts.weights) {
2416
+ command.push("weights", ...opts.weights);
2417
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2418
+ command.push("weights", opts.weight);
2419
+ }
2420
+ if ("aggregate" in opts) {
2421
+ command.push("aggregate", opts.aggregate);
2422
+ }
2423
+ }
2424
+ super(command, cmdOpts);
2425
+ }
2426
+ };
2427
+
2428
+ // pkg/commands/zlexcount.ts
2429
+ var ZLexCountCommand = class extends Command {
2430
+ constructor(cmd, opts) {
2431
+ super(["zlexcount", ...cmd], opts);
2432
+ }
2433
+ };
2434
+
2435
+ // pkg/commands/zpopmax.ts
2436
+ var ZPopMaxCommand = class extends Command {
2437
+ constructor([key, count], opts) {
2438
+ const command = ["zpopmax", key];
2439
+ if (typeof count === "number") {
2440
+ command.push(count);
2441
+ }
2442
+ super(command, opts);
2443
+ }
2444
+ };
2445
+
2446
+ // pkg/commands/zpopmin.ts
2447
+ var ZPopMinCommand = class extends Command {
2448
+ constructor([key, count], opts) {
2449
+ const command = ["zpopmin", key];
2450
+ if (typeof count === "number") {
2451
+ command.push(count);
2452
+ }
2453
+ super(command, opts);
2454
+ }
2455
+ };
2456
+
2457
+ // pkg/commands/zrange.ts
2458
+ var ZRangeCommand = class extends Command {
2459
+ constructor([key, min, max, opts], cmdOpts) {
2460
+ const command = ["zrange", key, min, max];
2461
+ if (opts?.byScore) {
2462
+ command.push("byscore");
2463
+ }
2464
+ if (opts?.byLex) {
2465
+ command.push("bylex");
2466
+ }
2467
+ if (opts?.rev) {
2468
+ command.push("rev");
2469
+ }
2470
+ if (opts?.count !== void 0 && opts.offset !== void 0) {
2471
+ command.push("limit", opts.offset, opts.count);
2472
+ }
2473
+ if (opts?.withScores) {
2474
+ command.push("withscores");
2475
+ }
2476
+ super(command, cmdOpts);
2477
+ }
2478
+ };
2479
+
2480
+ // pkg/commands/zrank.ts
2481
+ var ZRankCommand = class extends Command {
2482
+ constructor(cmd, opts) {
2483
+ super(["zrank", ...cmd], opts);
2484
+ }
2485
+ };
2486
+
2487
+ // pkg/commands/zrem.ts
2488
+ var ZRemCommand = class extends Command {
2489
+ constructor(cmd, opts) {
2490
+ super(["zrem", ...cmd], opts);
2491
+ }
2492
+ };
2493
+
2494
+ // pkg/commands/zremrangebylex.ts
2495
+ var ZRemRangeByLexCommand = class extends Command {
2496
+ constructor(cmd, opts) {
2497
+ super(["zremrangebylex", ...cmd], opts);
2498
+ }
2499
+ };
2500
+
2501
+ // pkg/commands/zremrangebyrank.ts
2502
+ var ZRemRangeByRankCommand = class extends Command {
2503
+ constructor(cmd, opts) {
2504
+ super(["zremrangebyrank", ...cmd], opts);
2505
+ }
2506
+ };
2507
+
2508
+ // pkg/commands/zremrangebyscore.ts
2509
+ var ZRemRangeByScoreCommand = class extends Command {
2510
+ constructor(cmd, opts) {
2511
+ super(["zremrangebyscore", ...cmd], opts);
2512
+ }
2513
+ };
2514
+
2515
+ // pkg/commands/zrevrank.ts
2516
+ var ZRevRankCommand = class extends Command {
2517
+ constructor(cmd, opts) {
2518
+ super(["zrevrank", ...cmd], opts);
2519
+ }
2520
+ };
2521
+
2522
+ // pkg/commands/zscan.ts
2523
+ var ZScanCommand = class extends Command {
2524
+ constructor([key, cursor, opts], cmdOpts) {
2525
+ const command = ["zscan", key, cursor];
2526
+ if (opts?.match) {
2527
+ command.push("match", opts.match);
2528
+ }
2529
+ if (typeof opts?.count === "number") {
2530
+ command.push("count", opts.count);
2531
+ }
2532
+ super(command, {
2533
+ deserialize: deserializeScanResponse,
2534
+ ...cmdOpts
2535
+ });
2536
+ }
2537
+ };
2538
+
2539
+ // pkg/commands/zscore.ts
2540
+ var ZScoreCommand = class extends Command {
2541
+ constructor(cmd, opts) {
2542
+ super(["zscore", ...cmd], opts);
2543
+ }
2544
+ };
2545
+
2546
+ // pkg/commands/zunion.ts
2547
+ var ZUnionCommand = class extends Command {
2548
+ constructor([numKeys, keyOrKeys, opts], cmdOpts) {
2549
+ const command = ["zunion", numKeys];
2550
+ if (Array.isArray(keyOrKeys)) {
2551
+ command.push(...keyOrKeys);
2552
+ } else {
2553
+ command.push(keyOrKeys);
2554
+ }
2555
+ if (opts) {
2556
+ if ("weights" in opts && opts.weights) {
2557
+ command.push("weights", ...opts.weights);
2558
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2559
+ command.push("weights", opts.weight);
2560
+ }
2561
+ if ("aggregate" in opts) {
2562
+ command.push("aggregate", opts.aggregate);
2563
+ }
2564
+ if (opts.withScores) {
2565
+ command.push("withscores");
2566
+ }
2567
+ }
2568
+ super(command, cmdOpts);
2569
+ }
2570
+ };
2571
+
2572
+ // pkg/commands/zunionstore.ts
2573
+ var ZUnionStoreCommand = class extends Command {
2574
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2575
+ const command = ["zunionstore", destination, numKeys];
2576
+ if (Array.isArray(keyOrKeys)) {
2577
+ command.push(...keyOrKeys);
2578
+ } else {
2579
+ command.push(keyOrKeys);
2580
+ }
2581
+ if (opts) {
2582
+ if ("weights" in opts && opts.weights) {
2583
+ command.push("weights", ...opts.weights);
2584
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2585
+ command.push("weights", opts.weight);
2586
+ }
2587
+ if ("aggregate" in opts) {
2588
+ command.push("aggregate", opts.aggregate);
2589
+ }
2590
+ }
2591
+ super(command, cmdOpts);
2592
+ }
2593
+ };
2594
+
2595
+ // pkg/commands/psubscribe.ts
2596
+ var PSubscribeCommand = class extends Command {
2597
+ constructor(cmd, opts) {
2598
+ const sseHeaders = {
2599
+ Accept: "text/event-stream",
2600
+ "Cache-Control": "no-cache",
2601
+ Connection: "keep-alive"
2602
+ };
2603
+ super([], {
2604
+ ...opts,
2605
+ headers: sseHeaders,
2606
+ path: ["psubscribe", ...cmd],
2607
+ streamOptions: {
2608
+ isStreaming: true,
2609
+ onMessage: opts?.streamOptions?.onMessage,
2610
+ signal: opts?.streamOptions?.signal
2611
+ }
2612
+ });
2613
+ }
2614
+ };
2615
+
2616
+ // pkg/commands/subscribe.ts
2617
+ var Subscriber = class extends EventTarget {
2618
+ subscriptions;
2619
+ client;
2620
+ listeners;
2621
+ opts;
2622
+ constructor(client, channels, isPattern = false, opts) {
2623
+ super();
2624
+ this.client = client;
2625
+ this.subscriptions = /* @__PURE__ */ new Map();
2626
+ this.listeners = /* @__PURE__ */ new Map();
2627
+ this.opts = opts;
2628
+ for (const channel of channels) {
2629
+ if (isPattern) {
2630
+ this.subscribeToPattern(channel);
2631
+ } else {
2632
+ this.subscribeToChannel(channel);
2633
+ }
2634
+ }
2635
+ }
2636
+ subscribeToChannel(channel) {
2637
+ const controller = new AbortController();
2638
+ const command = new SubscribeCommand([channel], {
2639
+ streamOptions: {
2640
+ signal: controller.signal,
2641
+ onMessage: (data) => this.handleMessage(data, false)
2642
+ }
2643
+ });
2644
+ command.exec(this.client).catch((error) => {
2645
+ if (error.name !== "AbortError") {
2646
+ this.dispatchToListeners("error", error);
2647
+ }
2648
+ });
2649
+ this.subscriptions.set(channel, {
2650
+ command,
2651
+ controller,
2652
+ isPattern: false
2653
+ });
2654
+ }
2655
+ subscribeToPattern(pattern) {
2656
+ const controller = new AbortController();
2657
+ const command = new PSubscribeCommand([pattern], {
2658
+ streamOptions: {
2659
+ signal: controller.signal,
2660
+ onMessage: (data) => this.handleMessage(data, true)
2661
+ }
2662
+ });
2663
+ command.exec(this.client).catch((error) => {
2664
+ if (error.name !== "AbortError") {
2665
+ this.dispatchToListeners("error", error);
2666
+ }
2667
+ });
2668
+ this.subscriptions.set(pattern, {
2669
+ command,
2670
+ controller,
2671
+ isPattern: true
2672
+ });
2673
+ }
2674
+ handleMessage(data, isPattern) {
2675
+ const messageData = data.replace(/^data:\s*/, "");
2676
+ const firstCommaIndex = messageData.indexOf(",");
2677
+ const secondCommaIndex = messageData.indexOf(",", firstCommaIndex + 1);
2678
+ const thirdCommaIndex = isPattern ? messageData.indexOf(",", secondCommaIndex + 1) : -1;
2679
+ if (firstCommaIndex !== -1 && secondCommaIndex !== -1) {
2680
+ const type = messageData.slice(0, firstCommaIndex);
2681
+ if (isPattern && type === "pmessage" && thirdCommaIndex !== -1) {
2682
+ const pattern = messageData.slice(firstCommaIndex + 1, secondCommaIndex);
2683
+ const channel = messageData.slice(secondCommaIndex + 1, thirdCommaIndex);
2684
+ const messageStr = messageData.slice(thirdCommaIndex + 1);
2685
+ try {
2686
+ const message = this.opts?.automaticDeserialization === false ? messageStr : JSON.parse(messageStr);
2687
+ this.dispatchToListeners("pmessage", { pattern, channel, message });
2688
+ this.dispatchToListeners(`pmessage:${pattern}`, { pattern, channel, message });
2689
+ } catch (error) {
2690
+ this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
2691
+ }
2692
+ } else {
2693
+ const channel = messageData.slice(firstCommaIndex + 1, secondCommaIndex);
2694
+ const messageStr = messageData.slice(secondCommaIndex + 1);
2695
+ try {
2696
+ if (type === "subscribe" || type === "psubscribe" || type === "unsubscribe" || type === "punsubscribe") {
2697
+ const count = Number.parseInt(messageStr);
2698
+ this.dispatchToListeners(type, count);
2699
+ } else {
2700
+ const message = this.opts?.automaticDeserialization === false ? messageStr : parseWithTryCatch(messageStr);
2701
+ this.dispatchToListeners(type, { channel, message });
2702
+ this.dispatchToListeners(`${type}:${channel}`, { channel, message });
2703
+ }
2704
+ } catch (error) {
2705
+ this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
2706
+ }
2707
+ }
2708
+ }
2709
+ }
2710
+ dispatchToListeners(type, data) {
2711
+ const listeners = this.listeners.get(type);
2712
+ if (listeners) {
2713
+ for (const listener of listeners) {
2714
+ listener(data);
2715
+ }
2716
+ }
2717
+ }
2718
+ on(type, listener) {
2719
+ if (!this.listeners.has(type)) {
2720
+ this.listeners.set(type, /* @__PURE__ */ new Set());
2721
+ }
2722
+ this.listeners.get(type)?.add(listener);
2723
+ }
2724
+ removeAllListeners() {
2725
+ this.listeners.clear();
2726
+ }
2727
+ async unsubscribe(channels) {
2728
+ if (channels) {
2729
+ for (const channel of channels) {
2730
+ const subscription = this.subscriptions.get(channel);
2731
+ if (subscription) {
2732
+ try {
2733
+ subscription.controller.abort();
2734
+ } catch {
2735
+ }
2736
+ this.subscriptions.delete(channel);
2737
+ }
2738
+ }
2739
+ } else {
2740
+ for (const subscription of this.subscriptions.values()) {
2741
+ try {
2742
+ subscription.controller.abort();
2743
+ } catch {
2744
+ }
2745
+ }
2746
+ this.subscriptions.clear();
2747
+ this.removeAllListeners();
2748
+ }
2749
+ }
2750
+ getSubscribedChannels() {
2751
+ return [...this.subscriptions.keys()];
2752
+ }
2753
+ };
2754
+ var SubscribeCommand = class extends Command {
2755
+ constructor(cmd, opts) {
2756
+ const sseHeaders = {
2757
+ Accept: "text/event-stream",
2758
+ "Cache-Control": "no-cache",
2759
+ Connection: "keep-alive"
2760
+ };
2761
+ super([], {
2762
+ ...opts,
2763
+ headers: sseHeaders,
2764
+ path: ["subscribe", ...cmd],
2765
+ streamOptions: {
2766
+ isStreaming: true,
2767
+ onMessage: opts?.streamOptions?.onMessage,
2768
+ signal: opts?.streamOptions?.signal
2769
+ }
2770
+ });
2771
+ }
2772
+ };
2773
+ var parseWithTryCatch = (str) => {
2774
+ try {
2775
+ return JSON.parse(str);
2776
+ } catch {
2777
+ return str;
2778
+ }
2779
+ };
2780
+
2781
+ // pkg/commands/zdiffstore.ts
2782
+ var ZDiffStoreCommand = class extends Command {
2783
+ constructor(cmd, opts) {
2784
+ super(["zdiffstore", ...cmd], opts);
2785
+ }
2786
+ };
2787
+
2788
+ // pkg/commands/zmscore.ts
2789
+ var ZMScoreCommand = class extends Command {
2790
+ constructor(cmd, opts) {
2791
+ const [key, members] = cmd;
2792
+ super(["zmscore", key, ...members], opts);
2793
+ }
2794
+ };
2795
+
2796
+ // pkg/pipeline.ts
2797
+ var Pipeline = class {
2798
+ client;
2799
+ commands;
2800
+ commandOptions;
2801
+ multiExec;
2802
+ constructor(opts) {
2803
+ this.client = opts.client;
2804
+ this.commands = [];
2805
+ this.commandOptions = opts.commandOptions;
2806
+ this.multiExec = opts.multiExec ?? false;
2807
+ if (this.commandOptions?.latencyLogging) {
2808
+ const originalExec = this.exec.bind(this);
2809
+ this.exec = async (options) => {
2810
+ const start = performance.now();
2811
+ const result = await (options ? originalExec(options) : originalExec());
2812
+ const end = performance.now();
2813
+ const loggerResult = (end - start).toFixed(2);
2814
+ console.log(
2815
+ `Latency for \x1B[38;2;19;185;39m${this.multiExec ? ["MULTI-EXEC"] : ["PIPELINE"].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
2816
+ );
2817
+ return result;
2818
+ };
2819
+ }
2820
+ }
2821
+ exec = async (options) => {
2822
+ if (this.commands.length === 0) {
2823
+ throw new Error("Pipeline is empty");
2824
+ }
2825
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
2826
+ const res = await this.client.request({
2827
+ path,
2828
+ body: Object.values(this.commands).map((c) => c.command)
2829
+ });
2830
+ return options?.keepErrors ? res.map(({ error, result }, i) => {
2831
+ return {
2832
+ error,
2833
+ result: this.commands[i].deserialize(result)
2834
+ };
2835
+ }) : res.map(({ error, result }, i) => {
2836
+ if (error) {
2837
+ throw new UpstashError(
2838
+ `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`
2839
+ );
2840
+ }
2841
+ return this.commands[i].deserialize(result);
2842
+ });
2843
+ };
2844
+ /**
2845
+ * Returns the length of pipeline before the execution
2846
+ */
2847
+ length() {
2848
+ return this.commands.length;
2849
+ }
2850
+ /**
2851
+ * Pushes a command into the pipeline and returns a chainable instance of the
2852
+ * pipeline
2853
+ */
2854
+ chain(command) {
2855
+ this.commands.push(command);
2856
+ return this;
2857
+ }
2858
+ /**
2859
+ * @see https://redis.io/commands/append
2860
+ */
2861
+ append = (...args) => this.chain(new AppendCommand(args, this.commandOptions));
2862
+ /**
2863
+ * @see https://redis.io/commands/bitcount
2864
+ */
2865
+ bitcount = (...args) => this.chain(new BitCountCommand(args, this.commandOptions));
2866
+ /**
2867
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
2868
+ *
2869
+ * @example
2870
+ * ```typescript
2871
+ * redis.set("mykey", 0);
2872
+ * const result = await redis.pipeline()
2873
+ * .bitfield("mykey")
2874
+ * .set("u4", 0, 16)
2875
+ * .incr("u4", "#1", 1)
2876
+ * .exec();
2877
+ * console.log(result); // [[0, 1]]
2878
+ * ```
2879
+ *
2880
+ * @see https://redis.io/commands/bitfield
2881
+ */
2882
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.commandOptions, this.chain.bind(this));
2883
+ /**
2884
+ * @see https://redis.io/commands/bitop
2885
+ */
2886
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => this.chain(
2887
+ new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.commandOptions)
2888
+ );
2889
+ /**
2890
+ * @see https://redis.io/commands/bitpos
2891
+ */
2892
+ bitpos = (...args) => this.chain(new BitPosCommand(args, this.commandOptions));
2893
+ /**
2894
+ * @see https://redis.io/commands/copy
2895
+ */
2896
+ copy = (...args) => this.chain(new CopyCommand(args, this.commandOptions));
2897
+ /**
2898
+ * @see https://redis.io/commands/zdiffstore
2899
+ */
2900
+ zdiffstore = (...args) => this.chain(new ZDiffStoreCommand(args, this.commandOptions));
2901
+ /**
2902
+ * @see https://redis.io/commands/dbsize
2903
+ */
2904
+ dbsize = () => this.chain(new DBSizeCommand(this.commandOptions));
2905
+ /**
2906
+ * @see https://redis.io/commands/decr
2907
+ */
2908
+ decr = (...args) => this.chain(new DecrCommand(args, this.commandOptions));
2909
+ /**
2910
+ * @see https://redis.io/commands/decrby
2911
+ */
2912
+ decrby = (...args) => this.chain(new DecrByCommand(args, this.commandOptions));
2913
+ /**
2914
+ * @see https://redis.io/commands/del
2915
+ */
2916
+ del = (...args) => this.chain(new DelCommand(args, this.commandOptions));
2917
+ /**
2918
+ * @see https://redis.io/commands/echo
2919
+ */
2920
+ echo = (...args) => this.chain(new EchoCommand(args, this.commandOptions));
2921
+ /**
2922
+ * @see https://redis.io/commands/eval_ro
2923
+ */
2924
+ evalRo = (...args) => this.chain(new EvalROCommand(args, this.commandOptions));
2925
+ /**
2926
+ * @see https://redis.io/commands/eval
2927
+ */
2928
+ eval = (...args) => this.chain(new EvalCommand(args, this.commandOptions));
2929
+ /**
2930
+ * @see https://redis.io/commands/evalsha_ro
2931
+ */
2932
+ evalshaRo = (...args) => this.chain(new EvalshaROCommand(args, this.commandOptions));
2933
+ /**
2934
+ * @see https://redis.io/commands/evalsha
2935
+ */
2936
+ evalsha = (...args) => this.chain(new EvalshaCommand(args, this.commandOptions));
2937
+ /**
2938
+ * @see https://redis.io/commands/exists
2939
+ */
2940
+ exists = (...args) => this.chain(new ExistsCommand(args, this.commandOptions));
2941
+ /**
2942
+ * @see https://redis.io/commands/expire
2943
+ */
2944
+ expire = (...args) => this.chain(new ExpireCommand(args, this.commandOptions));
2945
+ /**
2946
+ * @see https://redis.io/commands/expireat
2947
+ */
2948
+ expireat = (...args) => this.chain(new ExpireAtCommand(args, this.commandOptions));
2949
+ /**
2950
+ * @see https://redis.io/commands/flushall
2951
+ */
2952
+ flushall = (args) => this.chain(new FlushAllCommand(args, this.commandOptions));
2953
+ /**
2954
+ * @see https://redis.io/commands/flushdb
2955
+ */
2956
+ flushdb = (...args) => this.chain(new FlushDBCommand(args, this.commandOptions));
2957
+ /**
2958
+ * @see https://redis.io/commands/geoadd
2959
+ */
2960
+ geoadd = (...args) => this.chain(new GeoAddCommand(args, this.commandOptions));
2961
+ /**
2962
+ * @see https://redis.io/commands/geodist
2963
+ */
2964
+ geodist = (...args) => this.chain(new GeoDistCommand(args, this.commandOptions));
2965
+ /**
2966
+ * @see https://redis.io/commands/geopos
2967
+ */
2968
+ geopos = (...args) => this.chain(new GeoPosCommand(args, this.commandOptions));
2969
+ /**
2970
+ * @see https://redis.io/commands/geohash
2971
+ */
2972
+ geohash = (...args) => this.chain(new GeoHashCommand(args, this.commandOptions));
2973
+ /**
2974
+ * @see https://redis.io/commands/geosearch
2975
+ */
2976
+ geosearch = (...args) => this.chain(new GeoSearchCommand(args, this.commandOptions));
2977
+ /**
2978
+ * @see https://redis.io/commands/geosearchstore
2979
+ */
2980
+ geosearchstore = (...args) => this.chain(new GeoSearchStoreCommand(args, this.commandOptions));
2981
+ /**
2982
+ * @see https://redis.io/commands/get
2983
+ */
2984
+ get = (...args) => this.chain(new GetCommand(args, this.commandOptions));
2985
+ /**
2986
+ * @see https://redis.io/commands/getbit
2987
+ */
2988
+ getbit = (...args) => this.chain(new GetBitCommand(args, this.commandOptions));
2989
+ /**
2990
+ * @see https://redis.io/commands/getdel
2991
+ */
2992
+ getdel = (...args) => this.chain(new GetDelCommand(args, this.commandOptions));
2993
+ /**
2994
+ * @see https://redis.io/commands/getex
2995
+ */
2996
+ getex = (...args) => this.chain(new GetExCommand(args, this.commandOptions));
2997
+ /**
2998
+ * @see https://redis.io/commands/getrange
2999
+ */
3000
+ getrange = (...args) => this.chain(new GetRangeCommand(args, this.commandOptions));
3001
+ /**
3002
+ * @see https://redis.io/commands/getset
3003
+ */
3004
+ getset = (key, value) => this.chain(new GetSetCommand([key, value], this.commandOptions));
3005
+ /**
3006
+ * @see https://redis.io/commands/hdel
3007
+ */
3008
+ hdel = (...args) => this.chain(new HDelCommand(args, this.commandOptions));
3009
+ /**
3010
+ * @see https://redis.io/commands/hexists
3011
+ */
3012
+ hexists = (...args) => this.chain(new HExistsCommand(args, this.commandOptions));
3013
+ /**
3014
+ * @see https://redis.io/commands/hexpire
3015
+ */
3016
+ hexpire = (...args) => this.chain(new HExpireCommand(args, this.commandOptions));
3017
+ /**
3018
+ * @see https://redis.io/commands/hexpireat
3019
+ */
3020
+ hexpireat = (...args) => this.chain(new HExpireAtCommand(args, this.commandOptions));
3021
+ /**
3022
+ * @see https://redis.io/commands/hexpiretime
3023
+ */
3024
+ hexpiretime = (...args) => this.chain(new HExpireTimeCommand(args, this.commandOptions));
3025
+ /**
3026
+ * @see https://redis.io/commands/httl
3027
+ */
3028
+ httl = (...args) => this.chain(new HTtlCommand(args, this.commandOptions));
3029
+ /**
3030
+ * @see https://redis.io/commands/hpexpire
3031
+ */
3032
+ hpexpire = (...args) => this.chain(new HPExpireCommand(args, this.commandOptions));
3033
+ /**
3034
+ * @see https://redis.io/commands/hpexpireat
3035
+ */
3036
+ hpexpireat = (...args) => this.chain(new HPExpireAtCommand(args, this.commandOptions));
3037
+ /**
3038
+ * @see https://redis.io/commands/hpexpiretime
3039
+ */
3040
+ hpexpiretime = (...args) => this.chain(new HPExpireTimeCommand(args, this.commandOptions));
3041
+ /**
3042
+ * @see https://redis.io/commands/hpttl
3043
+ */
3044
+ hpttl = (...args) => this.chain(new HPTtlCommand(args, this.commandOptions));
3045
+ /**
3046
+ * @see https://redis.io/commands/hpersist
3047
+ */
3048
+ hpersist = (...args) => this.chain(new HPersistCommand(args, this.commandOptions));
3049
+ /**
3050
+ * @see https://redis.io/commands/hget
3051
+ */
3052
+ hget = (...args) => this.chain(new HGetCommand(args, this.commandOptions));
3053
+ /**
3054
+ * @see https://redis.io/commands/hgetall
3055
+ */
3056
+ hgetall = (...args) => this.chain(new HGetAllCommand(args, this.commandOptions));
3057
+ /**
3058
+ * @see https://redis.io/commands/hincrby
3059
+ */
3060
+ hincrby = (...args) => this.chain(new HIncrByCommand(args, this.commandOptions));
3061
+ /**
3062
+ * @see https://redis.io/commands/hincrbyfloat
3063
+ */
3064
+ hincrbyfloat = (...args) => this.chain(new HIncrByFloatCommand(args, this.commandOptions));
3065
+ /**
3066
+ * @see https://redis.io/commands/hkeys
3067
+ */
3068
+ hkeys = (...args) => this.chain(new HKeysCommand(args, this.commandOptions));
3069
+ /**
3070
+ * @see https://redis.io/commands/hlen
3071
+ */
3072
+ hlen = (...args) => this.chain(new HLenCommand(args, this.commandOptions));
3073
+ /**
3074
+ * @see https://redis.io/commands/hmget
3075
+ */
3076
+ hmget = (...args) => this.chain(new HMGetCommand(args, this.commandOptions));
3077
+ /**
3078
+ * @see https://redis.io/commands/hmset
3079
+ */
3080
+ hmset = (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions));
3081
+ /**
3082
+ * @see https://redis.io/commands/hrandfield
3083
+ */
3084
+ hrandfield = (key, count, withValues) => this.chain(new HRandFieldCommand([key, count, withValues], this.commandOptions));
3085
+ /**
3086
+ * @see https://redis.io/commands/hscan
3087
+ */
3088
+ hscan = (...args) => this.chain(new HScanCommand(args, this.commandOptions));
3089
+ /**
3090
+ * @see https://redis.io/commands/hset
3091
+ */
3092
+ hset = (key, kv) => this.chain(new HSetCommand([key, kv], this.commandOptions));
3093
+ /**
3094
+ * @see https://redis.io/commands/hsetnx
3095
+ */
3096
+ hsetnx = (key, field, value) => this.chain(new HSetNXCommand([key, field, value], this.commandOptions));
3097
+ /**
3098
+ * @see https://redis.io/commands/hstrlen
3099
+ */
3100
+ hstrlen = (...args) => this.chain(new HStrLenCommand(args, this.commandOptions));
3101
+ /**
3102
+ * @see https://redis.io/commands/hvals
3103
+ */
3104
+ hvals = (...args) => this.chain(new HValsCommand(args, this.commandOptions));
3105
+ /**
3106
+ * @see https://redis.io/commands/incr
3107
+ */
3108
+ incr = (...args) => this.chain(new IncrCommand(args, this.commandOptions));
3109
+ /**
3110
+ * @see https://redis.io/commands/incrby
3111
+ */
3112
+ incrby = (...args) => this.chain(new IncrByCommand(args, this.commandOptions));
3113
+ /**
3114
+ * @see https://redis.io/commands/incrbyfloat
3115
+ */
3116
+ incrbyfloat = (...args) => this.chain(new IncrByFloatCommand(args, this.commandOptions));
3117
+ /**
3118
+ * @see https://redis.io/commands/keys
3119
+ */
3120
+ keys = (...args) => this.chain(new KeysCommand(args, this.commandOptions));
3121
+ /**
3122
+ * @see https://redis.io/commands/lindex
3123
+ */
3124
+ lindex = (...args) => this.chain(new LIndexCommand(args, this.commandOptions));
3125
+ /**
3126
+ * @see https://redis.io/commands/linsert
3127
+ */
3128
+ linsert = (key, direction, pivot, value) => this.chain(new LInsertCommand([key, direction, pivot, value], this.commandOptions));
3129
+ /**
3130
+ * @see https://redis.io/commands/llen
3131
+ */
3132
+ llen = (...args) => this.chain(new LLenCommand(args, this.commandOptions));
3133
+ /**
3134
+ * @see https://redis.io/commands/lmove
3135
+ */
3136
+ lmove = (...args) => this.chain(new LMoveCommand(args, this.commandOptions));
3137
+ /**
3138
+ * @see https://redis.io/commands/lpop
3139
+ */
3140
+ lpop = (...args) => this.chain(new LPopCommand(args, this.commandOptions));
3141
+ /**
3142
+ * @see https://redis.io/commands/lmpop
3143
+ */
3144
+ lmpop = (...args) => this.chain(new LmPopCommand(args, this.commandOptions));
3145
+ /**
3146
+ * @see https://redis.io/commands/lpos
3147
+ */
3148
+ lpos = (...args) => this.chain(new LPosCommand(args, this.commandOptions));
3149
+ /**
3150
+ * @see https://redis.io/commands/lpush
3151
+ */
3152
+ lpush = (key, ...elements) => this.chain(new LPushCommand([key, ...elements], this.commandOptions));
3153
+ /**
3154
+ * @see https://redis.io/commands/lpushx
3155
+ */
3156
+ lpushx = (key, ...elements) => this.chain(new LPushXCommand([key, ...elements], this.commandOptions));
3157
+ /**
3158
+ * @see https://redis.io/commands/lrange
3159
+ */
3160
+ lrange = (...args) => this.chain(new LRangeCommand(args, this.commandOptions));
3161
+ /**
3162
+ * @see https://redis.io/commands/lrem
3163
+ */
3164
+ lrem = (key, count, value) => this.chain(new LRemCommand([key, count, value], this.commandOptions));
3165
+ /**
3166
+ * @see https://redis.io/commands/lset
3167
+ */
3168
+ lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
3169
+ /**
3170
+ * @see https://redis.io/commands/ltrim
3171
+ */
3172
+ ltrim = (...args) => this.chain(new LTrimCommand(args, this.commandOptions));
3173
+ /**
3174
+ * @see https://redis.io/commands/mget
3175
+ */
3176
+ mget = (...args) => this.chain(new MGetCommand(args, this.commandOptions));
3177
+ /**
3178
+ * @see https://redis.io/commands/mset
3179
+ */
3180
+ mset = (kv) => this.chain(new MSetCommand([kv], this.commandOptions));
3181
+ /**
3182
+ * @see https://redis.io/commands/msetnx
3183
+ */
3184
+ msetnx = (kv) => this.chain(new MSetNXCommand([kv], this.commandOptions));
3185
+ /**
3186
+ * @see https://redis.io/commands/persist
3187
+ */
3188
+ persist = (...args) => this.chain(new PersistCommand(args, this.commandOptions));
3189
+ /**
3190
+ * @see https://redis.io/commands/pexpire
3191
+ */
3192
+ pexpire = (...args) => this.chain(new PExpireCommand(args, this.commandOptions));
3193
+ /**
3194
+ * @see https://redis.io/commands/pexpireat
3195
+ */
3196
+ pexpireat = (...args) => this.chain(new PExpireAtCommand(args, this.commandOptions));
3197
+ /**
3198
+ * @see https://redis.io/commands/pfadd
3199
+ */
3200
+ pfadd = (...args) => this.chain(new PfAddCommand(args, this.commandOptions));
3201
+ /**
3202
+ * @see https://redis.io/commands/pfcount
3203
+ */
3204
+ pfcount = (...args) => this.chain(new PfCountCommand(args, this.commandOptions));
3205
+ /**
3206
+ * @see https://redis.io/commands/pfmerge
3207
+ */
3208
+ pfmerge = (...args) => this.chain(new PfMergeCommand(args, this.commandOptions));
3209
+ /**
3210
+ * @see https://redis.io/commands/ping
3211
+ */
3212
+ ping = (args) => this.chain(new PingCommand(args, this.commandOptions));
3213
+ /**
3214
+ * @see https://redis.io/commands/psetex
3215
+ */
3216
+ psetex = (key, ttl, value) => this.chain(new PSetEXCommand([key, ttl, value], this.commandOptions));
3217
+ /**
3218
+ * @see https://redis.io/commands/pttl
3219
+ */
3220
+ pttl = (...args) => this.chain(new PTtlCommand(args, this.commandOptions));
3221
+ /**
3222
+ * @see https://redis.io/commands/publish
3223
+ */
3224
+ publish = (...args) => this.chain(new PublishCommand(args, this.commandOptions));
3225
+ /**
3226
+ * @see https://redis.io/commands/randomkey
3227
+ */
3228
+ randomkey = () => this.chain(new RandomKeyCommand(this.commandOptions));
3229
+ /**
3230
+ * @see https://redis.io/commands/rename
3231
+ */
3232
+ rename = (...args) => this.chain(new RenameCommand(args, this.commandOptions));
3233
+ /**
3234
+ * @see https://redis.io/commands/renamenx
3235
+ */
3236
+ renamenx = (...args) => this.chain(new RenameNXCommand(args, this.commandOptions));
3237
+ /**
3238
+ * @see https://redis.io/commands/rpop
3239
+ */
3240
+ rpop = (...args) => this.chain(new RPopCommand(args, this.commandOptions));
3241
+ /**
3242
+ * @see https://redis.io/commands/rpush
3243
+ */
3244
+ rpush = (key, ...elements) => this.chain(new RPushCommand([key, ...elements], this.commandOptions));
3245
+ /**
3246
+ * @see https://redis.io/commands/rpushx
3247
+ */
3248
+ rpushx = (key, ...elements) => this.chain(new RPushXCommand([key, ...elements], this.commandOptions));
3249
+ /**
3250
+ * @see https://redis.io/commands/sadd
3251
+ */
3252
+ sadd = (key, member, ...members) => this.chain(new SAddCommand([key, member, ...members], this.commandOptions));
3253
+ /**
3254
+ * @see https://redis.io/commands/scan
3255
+ */
3256
+ scan = (...args) => this.chain(new ScanCommand(args, this.commandOptions));
3257
+ /**
3258
+ * @see https://redis.io/commands/scard
3259
+ */
3260
+ scard = (...args) => this.chain(new SCardCommand(args, this.commandOptions));
3261
+ /**
3262
+ * @see https://redis.io/commands/script-exists
3263
+ */
3264
+ scriptExists = (...args) => this.chain(new ScriptExistsCommand(args, this.commandOptions));
3265
+ /**
3266
+ * @see https://redis.io/commands/script-flush
3267
+ */
3268
+ scriptFlush = (...args) => this.chain(new ScriptFlushCommand(args, this.commandOptions));
3269
+ /**
3270
+ * @see https://redis.io/commands/script-load
3271
+ */
3272
+ scriptLoad = (...args) => this.chain(new ScriptLoadCommand(args, this.commandOptions));
3273
+ /*)*
3274
+ * @see https://redis.io/commands/sdiff
3275
+ */
3276
+ sdiff = (...args) => this.chain(new SDiffCommand(args, this.commandOptions));
3277
+ /**
3278
+ * @see https://redis.io/commands/sdiffstore
3279
+ */
3280
+ sdiffstore = (...args) => this.chain(new SDiffStoreCommand(args, this.commandOptions));
3281
+ /**
3282
+ * @see https://redis.io/commands/set
3283
+ */
3284
+ set = (key, value, opts) => this.chain(new SetCommand([key, value, opts], this.commandOptions));
3285
+ /**
3286
+ * @see https://redis.io/commands/setbit
3287
+ */
3288
+ setbit = (...args) => this.chain(new SetBitCommand(args, this.commandOptions));
3289
+ /**
3290
+ * @see https://redis.io/commands/setex
3291
+ */
3292
+ setex = (key, ttl, value) => this.chain(new SetExCommand([key, ttl, value], this.commandOptions));
3293
+ /**
3294
+ * @see https://redis.io/commands/setnx
3295
+ */
3296
+ setnx = (key, value) => this.chain(new SetNxCommand([key, value], this.commandOptions));
3297
+ /**
3298
+ * @see https://redis.io/commands/setrange
3299
+ */
3300
+ setrange = (...args) => this.chain(new SetRangeCommand(args, this.commandOptions));
3301
+ /**
3302
+ * @see https://redis.io/commands/sinter
3303
+ */
3304
+ sinter = (...args) => this.chain(new SInterCommand(args, this.commandOptions));
3305
+ /**
3306
+ * @see https://redis.io/commands/sinterstore
3307
+ */
3308
+ sinterstore = (...args) => this.chain(new SInterStoreCommand(args, this.commandOptions));
3309
+ /**
3310
+ * @see https://redis.io/commands/sismember
3311
+ */
3312
+ sismember = (key, member) => this.chain(new SIsMemberCommand([key, member], this.commandOptions));
3313
+ /**
3314
+ * @see https://redis.io/commands/smembers
3315
+ */
3316
+ smembers = (...args) => this.chain(new SMembersCommand(args, this.commandOptions));
3317
+ /**
3318
+ * @see https://redis.io/commands/smismember
3319
+ */
3320
+ smismember = (key, members) => this.chain(new SMIsMemberCommand([key, members], this.commandOptions));
3321
+ /**
3322
+ * @see https://redis.io/commands/smove
3323
+ */
3324
+ smove = (source, destination, member) => this.chain(new SMoveCommand([source, destination, member], this.commandOptions));
3325
+ /**
3326
+ * @see https://redis.io/commands/spop
3327
+ */
3328
+ spop = (...args) => this.chain(new SPopCommand(args, this.commandOptions));
3329
+ /**
3330
+ * @see https://redis.io/commands/srandmember
3331
+ */
3332
+ srandmember = (...args) => this.chain(new SRandMemberCommand(args, this.commandOptions));
3333
+ /**
3334
+ * @see https://redis.io/commands/srem
3335
+ */
3336
+ srem = (key, ...members) => this.chain(new SRemCommand([key, ...members], this.commandOptions));
3337
+ /**
3338
+ * @see https://redis.io/commands/sscan
3339
+ */
3340
+ sscan = (...args) => this.chain(new SScanCommand(args, this.commandOptions));
3341
+ /**
3342
+ * @see https://redis.io/commands/strlen
3343
+ */
3344
+ strlen = (...args) => this.chain(new StrLenCommand(args, this.commandOptions));
3345
+ /**
3346
+ * @see https://redis.io/commands/sunion
3347
+ */
3348
+ sunion = (...args) => this.chain(new SUnionCommand(args, this.commandOptions));
3349
+ /**
3350
+ * @see https://redis.io/commands/sunionstore
3351
+ */
3352
+ sunionstore = (...args) => this.chain(new SUnionStoreCommand(args, this.commandOptions));
3353
+ /**
3354
+ * @see https://redis.io/commands/time
3355
+ */
3356
+ time = () => this.chain(new TimeCommand(this.commandOptions));
3357
+ /**
3358
+ * @see https://redis.io/commands/touch
3359
+ */
3360
+ touch = (...args) => this.chain(new TouchCommand(args, this.commandOptions));
3361
+ /**
3362
+ * @see https://redis.io/commands/ttl
3363
+ */
3364
+ ttl = (...args) => this.chain(new TtlCommand(args, this.commandOptions));
3365
+ /**
3366
+ * @see https://redis.io/commands/type
3367
+ */
3368
+ type = (...args) => this.chain(new TypeCommand(args, this.commandOptions));
3369
+ /**
3370
+ * @see https://redis.io/commands/unlink
3371
+ */
3372
+ unlink = (...args) => this.chain(new UnlinkCommand(args, this.commandOptions));
3373
+ /**
3374
+ * @see https://redis.io/commands/zadd
3375
+ */
3376
+ zadd = (...args) => {
3377
+ if ("score" in args[1]) {
3378
+ return this.chain(
3379
+ new ZAddCommand([args[0], args[1], ...args.slice(2)], this.commandOptions)
3380
+ );
3381
+ }
3382
+ return this.chain(
3383
+ new ZAddCommand(
3384
+ [args[0], args[1], ...args.slice(2)],
3385
+ this.commandOptions
3386
+ )
3387
+ );
3388
+ };
3389
+ /**
3390
+ * @see https://redis.io/commands/xadd
3391
+ */
3392
+ xadd = (...args) => this.chain(new XAddCommand(args, this.commandOptions));
3393
+ /**
3394
+ * @see https://redis.io/commands/xack
3395
+ */
3396
+ xack = (...args) => this.chain(new XAckCommand(args, this.commandOptions));
3397
+ /**
3398
+ * @see https://redis.io/commands/xdel
3399
+ */
3400
+ xdel = (...args) => this.chain(new XDelCommand(args, this.commandOptions));
3401
+ /**
3402
+ * @see https://redis.io/commands/xgroup
3403
+ */
3404
+ xgroup = (...args) => this.chain(new XGroupCommand(args, this.commandOptions));
3405
+ /**
3406
+ * @see https://redis.io/commands/xread
3407
+ */
3408
+ xread = (...args) => this.chain(new XReadCommand(args, this.commandOptions));
3409
+ /**
3410
+ * @see https://redis.io/commands/xreadgroup
3411
+ */
3412
+ xreadgroup = (...args) => this.chain(new XReadGroupCommand(args, this.commandOptions));
3413
+ /**
3414
+ * @see https://redis.io/commands/xinfo
3415
+ */
3416
+ xinfo = (...args) => this.chain(new XInfoCommand(args, this.commandOptions));
3417
+ /**
3418
+ * @see https://redis.io/commands/xlen
3419
+ */
3420
+ xlen = (...args) => this.chain(new XLenCommand(args, this.commandOptions));
3421
+ /**
3422
+ * @see https://redis.io/commands/xpending
3423
+ */
3424
+ xpending = (...args) => this.chain(new XPendingCommand(args, this.commandOptions));
3425
+ /**
3426
+ * @see https://redis.io/commands/xclaim
3427
+ */
3428
+ xclaim = (...args) => this.chain(new XClaimCommand(args, this.commandOptions));
3429
+ /**
3430
+ * @see https://redis.io/commands/xautoclaim
3431
+ */
3432
+ xautoclaim = (...args) => this.chain(new XAutoClaim(args, this.commandOptions));
3433
+ /**
3434
+ * @see https://redis.io/commands/xtrim
3435
+ */
3436
+ xtrim = (...args) => this.chain(new XTrimCommand(args, this.commandOptions));
3437
+ /**
3438
+ * @see https://redis.io/commands/xrange
3439
+ */
3440
+ xrange = (...args) => this.chain(new XRangeCommand(args, this.commandOptions));
3441
+ /**
3442
+ * @see https://redis.io/commands/xrevrange
3443
+ */
3444
+ xrevrange = (...args) => this.chain(new XRevRangeCommand(args, this.commandOptions));
3445
+ /**
3446
+ * @see https://redis.io/commands/zcard
3447
+ */
3448
+ zcard = (...args) => this.chain(new ZCardCommand(args, this.commandOptions));
3449
+ /**
3450
+ * @see https://redis.io/commands/zcount
3451
+ */
3452
+ zcount = (...args) => this.chain(new ZCountCommand(args, this.commandOptions));
3453
+ /**
3454
+ * @see https://redis.io/commands/zincrby
3455
+ */
3456
+ zincrby = (key, increment, member) => this.chain(new ZIncrByCommand([key, increment, member], this.commandOptions));
3457
+ /**
3458
+ * @see https://redis.io/commands/zinterstore
3459
+ */
3460
+ zinterstore = (...args) => this.chain(new ZInterStoreCommand(args, this.commandOptions));
3461
+ /**
3462
+ * @see https://redis.io/commands/zlexcount
3463
+ */
3464
+ zlexcount = (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions));
3465
+ /**
3466
+ * @see https://redis.io/commands/zmscore
3467
+ */
3468
+ zmscore = (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions));
3469
+ /**
3470
+ * @see https://redis.io/commands/zpopmax
3471
+ */
3472
+ zpopmax = (...args) => this.chain(new ZPopMaxCommand(args, this.commandOptions));
3473
+ /**
3474
+ * @see https://redis.io/commands/zpopmin
3475
+ */
3476
+ zpopmin = (...args) => this.chain(new ZPopMinCommand(args, this.commandOptions));
3477
+ /**
3478
+ * @see https://redis.io/commands/zrange
3479
+ */
3480
+ zrange = (...args) => this.chain(new ZRangeCommand(args, this.commandOptions));
3481
+ /**
3482
+ * @see https://redis.io/commands/zrank
3483
+ */
3484
+ zrank = (key, member) => this.chain(new ZRankCommand([key, member], this.commandOptions));
3485
+ /**
3486
+ * @see https://redis.io/commands/zrem
3487
+ */
3488
+ zrem = (key, ...members) => this.chain(new ZRemCommand([key, ...members], this.commandOptions));
3489
+ /**
3490
+ * @see https://redis.io/commands/zremrangebylex
3491
+ */
3492
+ zremrangebylex = (...args) => this.chain(new ZRemRangeByLexCommand(args, this.commandOptions));
3493
+ /**
3494
+ * @see https://redis.io/commands/zremrangebyrank
3495
+ */
3496
+ zremrangebyrank = (...args) => this.chain(new ZRemRangeByRankCommand(args, this.commandOptions));
3497
+ /**
3498
+ * @see https://redis.io/commands/zremrangebyscore
3499
+ */
3500
+ zremrangebyscore = (...args) => this.chain(new ZRemRangeByScoreCommand(args, this.commandOptions));
3501
+ /**
3502
+ * @see https://redis.io/commands/zrevrank
3503
+ */
3504
+ zrevrank = (key, member) => this.chain(new ZRevRankCommand([key, member], this.commandOptions));
3505
+ /**
3506
+ * @see https://redis.io/commands/zscan
3507
+ */
3508
+ zscan = (...args) => this.chain(new ZScanCommand(args, this.commandOptions));
3509
+ /**
3510
+ * @see https://redis.io/commands/zscore
3511
+ */
3512
+ zscore = (key, member) => this.chain(new ZScoreCommand([key, member], this.commandOptions));
3513
+ /**
3514
+ * @see https://redis.io/commands/zunionstore
3515
+ */
3516
+ zunionstore = (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions));
3517
+ /**
3518
+ * @see https://redis.io/commands/zunion
3519
+ */
3520
+ zunion = (...args) => this.chain(new ZUnionCommand(args, this.commandOptions));
3521
+ /**
3522
+ * @see https://redis.io/commands/?group=json
3523
+ */
3524
+ get json() {
3525
+ return {
3526
+ /**
3527
+ * @see https://redis.io/commands/json.arrappend
3528
+ */
3529
+ arrappend: (...args) => this.chain(new JsonArrAppendCommand(args, this.commandOptions)),
3530
+ /**
3531
+ * @see https://redis.io/commands/json.arrindex
3532
+ */
3533
+ arrindex: (...args) => this.chain(new JsonArrIndexCommand(args, this.commandOptions)),
3534
+ /**
3535
+ * @see https://redis.io/commands/json.arrinsert
3536
+ */
3537
+ arrinsert: (...args) => this.chain(new JsonArrInsertCommand(args, this.commandOptions)),
3538
+ /**
3539
+ * @see https://redis.io/commands/json.arrlen
3540
+ */
3541
+ arrlen: (...args) => this.chain(new JsonArrLenCommand(args, this.commandOptions)),
3542
+ /**
3543
+ * @see https://redis.io/commands/json.arrpop
3544
+ */
3545
+ arrpop: (...args) => this.chain(new JsonArrPopCommand(args, this.commandOptions)),
3546
+ /**
3547
+ * @see https://redis.io/commands/json.arrtrim
3548
+ */
3549
+ arrtrim: (...args) => this.chain(new JsonArrTrimCommand(args, this.commandOptions)),
3550
+ /**
3551
+ * @see https://redis.io/commands/json.clear
3552
+ */
3553
+ clear: (...args) => this.chain(new JsonClearCommand(args, this.commandOptions)),
3554
+ /**
3555
+ * @see https://redis.io/commands/json.del
3556
+ */
3557
+ del: (...args) => this.chain(new JsonDelCommand(args, this.commandOptions)),
3558
+ /**
3559
+ * @see https://redis.io/commands/json.forget
3560
+ */
3561
+ forget: (...args) => this.chain(new JsonForgetCommand(args, this.commandOptions)),
3562
+ /**
3563
+ * @see https://redis.io/commands/json.get
3564
+ */
3565
+ get: (...args) => this.chain(new JsonGetCommand(args, this.commandOptions)),
3566
+ /**
3567
+ * @see https://redis.io/commands/json.merge
3568
+ */
3569
+ merge: (...args) => this.chain(new JsonMergeCommand(args, this.commandOptions)),
3570
+ /**
3571
+ * @see https://redis.io/commands/json.mget
3572
+ */
3573
+ mget: (...args) => this.chain(new JsonMGetCommand(args, this.commandOptions)),
3574
+ /**
3575
+ * @see https://redis.io/commands/json.mset
3576
+ */
3577
+ mset: (...args) => this.chain(new JsonMSetCommand(args, this.commandOptions)),
3578
+ /**
3579
+ * @see https://redis.io/commands/json.numincrby
3580
+ */
3581
+ numincrby: (...args) => this.chain(new JsonNumIncrByCommand(args, this.commandOptions)),
3582
+ /**
3583
+ * @see https://redis.io/commands/json.nummultby
3584
+ */
3585
+ nummultby: (...args) => this.chain(new JsonNumMultByCommand(args, this.commandOptions)),
3586
+ /**
3587
+ * @see https://redis.io/commands/json.objkeys
3588
+ */
3589
+ objkeys: (...args) => this.chain(new JsonObjKeysCommand(args, this.commandOptions)),
3590
+ /**
3591
+ * @see https://redis.io/commands/json.objlen
3592
+ */
3593
+ objlen: (...args) => this.chain(new JsonObjLenCommand(args, this.commandOptions)),
3594
+ /**
3595
+ * @see https://redis.io/commands/json.resp
3596
+ */
3597
+ resp: (...args) => this.chain(new JsonRespCommand(args, this.commandOptions)),
3598
+ /**
3599
+ * @see https://redis.io/commands/json.set
3600
+ */
3601
+ set: (...args) => this.chain(new JsonSetCommand(args, this.commandOptions)),
3602
+ /**
3603
+ * @see https://redis.io/commands/json.strappend
3604
+ */
3605
+ strappend: (...args) => this.chain(new JsonStrAppendCommand(args, this.commandOptions)),
3606
+ /**
3607
+ * @see https://redis.io/commands/json.strlen
3608
+ */
3609
+ strlen: (...args) => this.chain(new JsonStrLenCommand(args, this.commandOptions)),
3610
+ /**
3611
+ * @see https://redis.io/commands/json.toggle
3612
+ */
3613
+ toggle: (...args) => this.chain(new JsonToggleCommand(args, this.commandOptions)),
3614
+ /**
3615
+ * @see https://redis.io/commands/json.type
3616
+ */
3617
+ type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
3618
+ };
3619
+ }
3620
+ get functions() {
3621
+ return {
3622
+ /**
3623
+ * @see https://redis.io/docs/latest/commands/function-load/
3624
+ */
3625
+ load: (...args) => this.chain(new FunctionLoadCommand(args, this.commandOptions)),
3626
+ /**
3627
+ * @see https://redis.io/docs/latest/commands/function-list/
3628
+ */
3629
+ list: (...args) => this.chain(new FunctionListCommand(args, this.commandOptions)),
3630
+ /**
3631
+ * @see https://redis.io/docs/latest/commands/function-delete/
3632
+ */
3633
+ delete: (...args) => this.chain(new FunctionDeleteCommand(args, this.commandOptions)),
3634
+ /**
3635
+ * @see https://redis.io/docs/latest/commands/function-flush/
3636
+ */
3637
+ flush: () => this.chain(new FunctionFlushCommand(this.commandOptions)),
3638
+ /**
3639
+ * @see https://redis.io/docs/latest/commands/function-stats/
3640
+ */
3641
+ stats: () => this.chain(new FunctionStatsCommand(this.commandOptions)),
3642
+ /**
3643
+ * @see https://redis.io/docs/latest/commands/fcall/
3644
+ */
3645
+ call: (...args) => this.chain(new FCallCommand(args, this.commandOptions)),
3646
+ /**
3647
+ * @see https://redis.io/docs/latest/commands/fcall_ro/
3648
+ */
3649
+ callRo: (...args) => this.chain(new FCallRoCommand(args, this.commandOptions))
3650
+ };
3651
+ }
3652
+ };
3653
+
3654
+ // pkg/script.ts
3655
+ var import_uncrypto = require("uncrypto");
3656
+ var Script = class {
3657
+ script;
3658
+ /**
3659
+ * @deprecated This property is initialized to an empty string and will be set in the init method
3660
+ * asynchronously. Do not use this property immidiately after the constructor.
3661
+ *
3662
+ * This property is only exposed for backwards compatibility and will be removed in the
3663
+ * future major release.
3664
+ */
3665
+ sha1;
3666
+ redis;
3667
+ constructor(redis, script) {
3668
+ this.redis = redis;
3669
+ this.script = script;
3670
+ this.sha1 = "";
3671
+ void this.init(script);
3672
+ }
3673
+ /**
3674
+ * Initialize the script by computing its SHA-1 hash.
3675
+ */
3676
+ async init(script) {
3677
+ if (this.sha1) return;
3678
+ this.sha1 = await this.digest(script);
3679
+ }
3680
+ /**
3681
+ * Send an `EVAL` command to redis.
3682
+ */
3683
+ async eval(keys, args) {
3684
+ await this.init(this.script);
3685
+ return await this.redis.eval(this.script, keys, args);
3686
+ }
3687
+ /**
3688
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
3689
+ */
3690
+ async evalsha(keys, args) {
3691
+ await this.init(this.script);
3692
+ return await this.redis.evalsha(this.sha1, keys, args);
3693
+ }
3694
+ /**
3695
+ * Optimistically try to run `EVALSHA` first.
3696
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
3697
+ *
3698
+ * Following calls will be able to use the cached script
3699
+ */
3700
+ async exec(keys, args) {
3701
+ await this.init(this.script);
3702
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (error) => {
3703
+ if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
3704
+ return await this.redis.eval(this.script, keys, args);
3705
+ }
3706
+ throw error;
3707
+ });
3708
+ return res;
3709
+ }
3710
+ /**
3711
+ * Compute the sha1 hash of the script and return its hex representation.
3712
+ */
3713
+ async digest(s) {
3714
+ const data = new TextEncoder().encode(s);
3715
+ const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
3716
+ const hashArray = [...new Uint8Array(hashBuffer)];
3717
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
3718
+ }
3719
+ };
3720
+
3721
+ // pkg/scriptRo.ts
3722
+ var import_uncrypto2 = require("uncrypto");
3723
+ var ScriptRO = class {
3724
+ script;
3725
+ /**
3726
+ * @deprecated This property is initialized to an empty string and will be set in the init method
3727
+ * asynchronously. Do not use this property immidiately after the constructor.
3728
+ *
3729
+ * This property is only exposed for backwards compatibility and will be removed in the
3730
+ * future major release.
3731
+ */
3732
+ sha1;
3733
+ redis;
3734
+ constructor(redis, script) {
3735
+ this.redis = redis;
3736
+ this.sha1 = "";
3737
+ this.script = script;
3738
+ void this.init(script);
3739
+ }
3740
+ async init(script) {
3741
+ if (this.sha1) return;
3742
+ this.sha1 = await this.digest(script);
3743
+ }
3744
+ /**
3745
+ * Send an `EVAL_RO` command to redis.
3746
+ */
3747
+ async evalRo(keys, args) {
3748
+ await this.init(this.script);
3749
+ return await this.redis.evalRo(this.script, keys, args);
3750
+ }
3751
+ /**
3752
+ * Calculates the sha1 hash of the script and then calls `EVALSHA_RO`.
3753
+ */
3754
+ async evalshaRo(keys, args) {
3755
+ await this.init(this.script);
3756
+ return await this.redis.evalshaRo(this.sha1, keys, args);
3757
+ }
3758
+ /**
3759
+ * Optimistically try to run `EVALSHA_RO` first.
3760
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL_RO`.
3761
+ *
3762
+ * Following calls will be able to use the cached script
3763
+ */
3764
+ async exec(keys, args) {
3765
+ await this.init(this.script);
3766
+ const res = await this.redis.evalshaRo(this.sha1, keys, args).catch(async (error) => {
3767
+ if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
3768
+ return await this.redis.evalRo(this.script, keys, args);
3769
+ }
3770
+ throw error;
3771
+ });
3772
+ return res;
3773
+ }
3774
+ /**
3775
+ * Compute the sha1 hash of the script and return its hex representation.
3776
+ */
3777
+ async digest(s) {
3778
+ const data = new TextEncoder().encode(s);
3779
+ const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
3780
+ const hashArray = [...new Uint8Array(hashBuffer)];
3781
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
3782
+ }
3783
+ };
3784
+
3785
+ // pkg/redis.ts
3786
+ var Redis = class {
3787
+ client;
3788
+ opts;
3789
+ enableTelemetry;
3790
+ enableAutoPipelining;
3791
+ /**
3792
+ * Create a new redis client
3793
+ *
3794
+ * @example
3795
+ * ```typescript
3796
+ * const redis = new Redis({
3797
+ * url: "<UPSTASH_REDIS_REST_URL>",
3798
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
3799
+ * });
3800
+ * ```
3801
+ */
3802
+ constructor(client, opts) {
3803
+ this.client = client;
3804
+ this.opts = opts;
3805
+ this.enableTelemetry = opts?.enableTelemetry ?? true;
3806
+ if (opts?.readYourWrites === false) {
3807
+ this.client.readYourWrites = false;
3808
+ }
3809
+ this.enableAutoPipelining = opts?.enableAutoPipelining ?? true;
3810
+ }
3811
+ get readYourWritesSyncToken() {
3812
+ return this.client.upstashSyncToken;
3813
+ }
3814
+ set readYourWritesSyncToken(session) {
3815
+ this.client.upstashSyncToken = session;
3816
+ }
3817
+ get json() {
3818
+ return {
3819
+ /**
3820
+ * @see https://redis.io/commands/json.arrappend
3821
+ */
3822
+ arrappend: (...args) => new JsonArrAppendCommand(args, this.opts).exec(this.client),
3823
+ /**
3824
+ * @see https://redis.io/commands/json.arrindex
3825
+ */
3826
+ arrindex: (...args) => new JsonArrIndexCommand(args, this.opts).exec(this.client),
3827
+ /**
3828
+ * @see https://redis.io/commands/json.arrinsert
3829
+ */
3830
+ arrinsert: (...args) => new JsonArrInsertCommand(args, this.opts).exec(this.client),
3831
+ /**
3832
+ * @see https://redis.io/commands/json.arrlen
3833
+ */
3834
+ arrlen: (...args) => new JsonArrLenCommand(args, this.opts).exec(this.client),
3835
+ /**
3836
+ * @see https://redis.io/commands/json.arrpop
3837
+ */
3838
+ arrpop: (...args) => new JsonArrPopCommand(args, this.opts).exec(this.client),
3839
+ /**
3840
+ * @see https://redis.io/commands/json.arrtrim
3841
+ */
3842
+ arrtrim: (...args) => new JsonArrTrimCommand(args, this.opts).exec(this.client),
3843
+ /**
3844
+ * @see https://redis.io/commands/json.clear
3845
+ */
3846
+ clear: (...args) => new JsonClearCommand(args, this.opts).exec(this.client),
3847
+ /**
3848
+ * @see https://redis.io/commands/json.del
3849
+ */
3850
+ del: (...args) => new JsonDelCommand(args, this.opts).exec(this.client),
3851
+ /**
3852
+ * @see https://redis.io/commands/json.forget
3853
+ */
3854
+ forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
3855
+ /**
3856
+ * @see https://redis.io/commands/json.get
3857
+ */
3858
+ get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
3859
+ /**
3860
+ * @see https://redis.io/commands/json.merge
3861
+ */
3862
+ merge: (...args) => new JsonMergeCommand(args, this.opts).exec(this.client),
3863
+ /**
3864
+ * @see https://redis.io/commands/json.mget
3865
+ */
3866
+ mget: (...args) => new JsonMGetCommand(args, this.opts).exec(this.client),
3867
+ /**
3868
+ * @see https://redis.io/commands/json.mset
3869
+ */
3870
+ mset: (...args) => new JsonMSetCommand(args, this.opts).exec(this.client),
3871
+ /**
3872
+ * @see https://redis.io/commands/json.numincrby
3873
+ */
3874
+ numincrby: (...args) => new JsonNumIncrByCommand(args, this.opts).exec(this.client),
3875
+ /**
3876
+ * @see https://redis.io/commands/json.nummultby
3877
+ */
3878
+ nummultby: (...args) => new JsonNumMultByCommand(args, this.opts).exec(this.client),
3879
+ /**
3880
+ * @see https://redis.io/commands/json.objkeys
3881
+ */
3882
+ objkeys: (...args) => new JsonObjKeysCommand(args, this.opts).exec(this.client),
3883
+ /**
3884
+ * @see https://redis.io/commands/json.objlen
3885
+ */
3886
+ objlen: (...args) => new JsonObjLenCommand(args, this.opts).exec(this.client),
3887
+ /**
3888
+ * @see https://redis.io/commands/json.resp
3889
+ */
3890
+ resp: (...args) => new JsonRespCommand(args, this.opts).exec(this.client),
3891
+ /**
3892
+ * @see https://redis.io/commands/json.set
3893
+ */
3894
+ set: (...args) => new JsonSetCommand(args, this.opts).exec(this.client),
3895
+ /**
3896
+ * @see https://redis.io/commands/json.strappend
3897
+ */
3898
+ strappend: (...args) => new JsonStrAppendCommand(args, this.opts).exec(this.client),
3899
+ /**
3900
+ * @see https://redis.io/commands/json.strlen
3901
+ */
3902
+ strlen: (...args) => new JsonStrLenCommand(args, this.opts).exec(this.client),
3903
+ /**
3904
+ * @see https://redis.io/commands/json.toggle
3905
+ */
3906
+ toggle: (...args) => new JsonToggleCommand(args, this.opts).exec(this.client),
3907
+ /**
3908
+ * @see https://redis.io/commands/json.type
3909
+ */
3910
+ type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
3911
+ };
3912
+ }
3913
+ get functions() {
3914
+ return {
3915
+ /**
3916
+ * @see https://redis.io/docs/latest/commands/function-load/
3917
+ */
3918
+ load: (...args) => new FunctionLoadCommand(args, this.opts).exec(this.client),
3919
+ /**
3920
+ * @see https://redis.io/docs/latest/commands/function-list/
3921
+ */
3922
+ list: (...args) => new FunctionListCommand(args, this.opts).exec(this.client),
3923
+ /**
3924
+ * @see https://redis.io/docs/latest/commands/function-delete/
3925
+ */
3926
+ delete: (...args) => new FunctionDeleteCommand(args, this.opts).exec(this.client),
3927
+ /**
3928
+ * @see https://redis.io/docs/latest/commands/function-flush/
3929
+ */
3930
+ flush: () => new FunctionFlushCommand(this.opts).exec(this.client),
3931
+ /**
3932
+ * @see https://redis.io/docs/latest/commands/function-stats/
3933
+ *
3934
+ * Note: `running_script` field is not supported and therefore not included in the type.
3935
+ */
3936
+ stats: () => new FunctionStatsCommand(this.opts).exec(this.client),
3937
+ /**
3938
+ * @see https://redis.io/docs/latest/commands/fcall/
3939
+ */
3940
+ call: (...args) => new FCallCommand(args, this.opts).exec(this.client),
3941
+ /**
3942
+ * @see https://redis.io/docs/latest/commands/fcall_ro/
3943
+ */
3944
+ callRo: (...args) => new FCallRoCommand(args, this.opts).exec(this.client)
3945
+ };
3946
+ }
3947
+ /**
3948
+ * Wrap a new middleware around the HTTP client.
3949
+ */
3950
+ use = (middleware) => {
3951
+ const makeRequest = this.client.request.bind(this.client);
3952
+ this.client.request = (req) => middleware(req, makeRequest);
3953
+ };
3954
+ /**
3955
+ * Technically this is not private, we can hide it from intellisense by doing this
3956
+ */
3957
+ addTelemetry = (telemetry) => {
3958
+ if (!this.enableTelemetry) {
3959
+ return;
3960
+ }
3961
+ try {
3962
+ this.client.mergeTelemetry(telemetry);
3963
+ } catch {
3964
+ }
3965
+ };
3966
+ /**
3967
+ * Creates a new script.
3968
+ *
3969
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
3970
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
3971
+ * the entire script. Afterwards, the script is cached on the server.
3972
+ *
3973
+ * @param script - The script to create
3974
+ * @param opts - Optional options to pass to the script `{ readonly?: boolean }`
3975
+ * @returns A new script
3976
+ *
3977
+ * @example
3978
+ * ```ts
3979
+ * const redis = new Redis({...})
3980
+ *
3981
+ * const script = redis.createScript<string>("return ARGV[1];")
3982
+ * const arg1 = await script.eval([], ["Hello World"])
3983
+ * expect(arg1, "Hello World")
3984
+ * ```
3985
+ * @example
3986
+ * ```ts
3987
+ * const redis = new Redis({...})
3988
+ *
3989
+ * const script = redis.createScript<string>("return ARGV[1];", { readonly: true })
3990
+ * const arg1 = await script.evalRo([], ["Hello World"])
3991
+ * expect(arg1, "Hello World")
3992
+ * ```
3993
+ */
3994
+ createScript(script, opts) {
3995
+ return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
3996
+ }
3997
+ /**
3998
+ * Create a new pipeline that allows you to send requests in bulk.
3999
+ *
4000
+ * @see {@link Pipeline}
4001
+ */
4002
+ pipeline = () => new Pipeline({
4003
+ client: this.client,
4004
+ commandOptions: this.opts,
4005
+ multiExec: false
4006
+ });
4007
+ autoPipeline = () => {
4008
+ return createAutoPipelineProxy(this);
4009
+ };
4010
+ /**
4011
+ * Create a new transaction to allow executing multiple steps atomically.
4012
+ *
4013
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
4014
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
4015
+ * guarantees that the commands are executed as a single isolated operation.
4016
+ *
4017
+ * @see {@link Pipeline}
4018
+ */
4019
+ multi = () => new Pipeline({
4020
+ client: this.client,
4021
+ commandOptions: this.opts,
4022
+ multiExec: true
4023
+ });
4024
+ /**
4025
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
4026
+ *
4027
+ * @example
4028
+ * ```typescript
4029
+ * redis.set("mykey", 0);
4030
+ * const result = await redis.bitfield("mykey")
4031
+ * .set("u4", 0, 16)
4032
+ * .incr("u4", "#1", 1)
4033
+ * .exec();
4034
+ * console.log(result); // [0, 1]
4035
+ * ```
4036
+ *
4037
+ * @see https://redis.io/commands/bitfield
4038
+ */
4039
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.opts);
4040
+ /**
4041
+ * @see https://redis.io/commands/append
4042
+ */
4043
+ append = (...args) => new AppendCommand(args, this.opts).exec(this.client);
4044
+ /**
4045
+ * @see https://redis.io/commands/bitcount
4046
+ */
4047
+ bitcount = (...args) => new BitCountCommand(args, this.opts).exec(this.client);
4048
+ /**
4049
+ * @see https://redis.io/commands/bitop
4050
+ */
4051
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.opts).exec(
4052
+ this.client
4053
+ );
4054
+ /**
4055
+ * @see https://redis.io/commands/bitpos
4056
+ */
4057
+ bitpos = (...args) => new BitPosCommand(args, this.opts).exec(this.client);
4058
+ /**
4059
+ * @see https://redis.io/commands/copy
4060
+ */
4061
+ copy = (...args) => new CopyCommand(args, this.opts).exec(this.client);
4062
+ /**
4063
+ * @see https://redis.io/commands/dbsize
4064
+ */
4065
+ dbsize = () => new DBSizeCommand(this.opts).exec(this.client);
4066
+ /**
4067
+ * @see https://redis.io/commands/decr
4068
+ */
4069
+ decr = (...args) => new DecrCommand(args, this.opts).exec(this.client);
4070
+ /**
4071
+ * @see https://redis.io/commands/decrby
4072
+ */
4073
+ decrby = (...args) => new DecrByCommand(args, this.opts).exec(this.client);
4074
+ /**
4075
+ * @see https://redis.io/commands/del
4076
+ */
4077
+ del = (...args) => new DelCommand(args, this.opts).exec(this.client);
4078
+ /**
4079
+ * @see https://redis.io/commands/echo
4080
+ */
4081
+ echo = (...args) => new EchoCommand(args, this.opts).exec(this.client);
4082
+ /**
4083
+ * @see https://redis.io/commands/eval_ro
4084
+ */
4085
+ evalRo = (...args) => new EvalROCommand(args, this.opts).exec(this.client);
4086
+ /**
4087
+ * @see https://redis.io/commands/eval
4088
+ */
4089
+ eval = (...args) => new EvalCommand(args, this.opts).exec(this.client);
4090
+ /**
4091
+ * @see https://redis.io/commands/evalsha_ro
4092
+ */
4093
+ evalshaRo = (...args) => new EvalshaROCommand(args, this.opts).exec(this.client);
4094
+ /**
4095
+ * @see https://redis.io/commands/evalsha
4096
+ */
4097
+ evalsha = (...args) => new EvalshaCommand(args, this.opts).exec(this.client);
4098
+ /**
4099
+ * Generic method to execute any Redis command.
4100
+ */
4101
+ exec = (args) => new ExecCommand(args, this.opts).exec(this.client);
4102
+ /**
4103
+ * @see https://redis.io/commands/exists
4104
+ */
4105
+ exists = (...args) => new ExistsCommand(args, this.opts).exec(this.client);
4106
+ /**
4107
+ * @see https://redis.io/commands/expire
4108
+ */
4109
+ expire = (...args) => new ExpireCommand(args, this.opts).exec(this.client);
4110
+ /**
4111
+ * @see https://redis.io/commands/expireat
4112
+ */
4113
+ expireat = (...args) => new ExpireAtCommand(args, this.opts).exec(this.client);
4114
+ /**
4115
+ * @see https://redis.io/commands/flushall
4116
+ */
4117
+ flushall = (args) => new FlushAllCommand(args, this.opts).exec(this.client);
4118
+ /**
4119
+ * @see https://redis.io/commands/flushdb
4120
+ */
4121
+ flushdb = (...args) => new FlushDBCommand(args, this.opts).exec(this.client);
4122
+ /**
4123
+ * @see https://redis.io/commands/geoadd
4124
+ */
4125
+ geoadd = (...args) => new GeoAddCommand(args, this.opts).exec(this.client);
4126
+ /**
4127
+ * @see https://redis.io/commands/geopos
4128
+ */
4129
+ geopos = (...args) => new GeoPosCommand(args, this.opts).exec(this.client);
4130
+ /**
4131
+ * @see https://redis.io/commands/geodist
4132
+ */
4133
+ geodist = (...args) => new GeoDistCommand(args, this.opts).exec(this.client);
4134
+ /**
4135
+ * @see https://redis.io/commands/geohash
4136
+ */
4137
+ geohash = (...args) => new GeoHashCommand(args, this.opts).exec(this.client);
4138
+ /**
4139
+ * @see https://redis.io/commands/geosearch
4140
+ */
4141
+ geosearch = (...args) => new GeoSearchCommand(args, this.opts).exec(this.client);
4142
+ /**
4143
+ * @see https://redis.io/commands/geosearchstore
4144
+ */
4145
+ geosearchstore = (...args) => new GeoSearchStoreCommand(args, this.opts).exec(this.client);
4146
+ /**
4147
+ * @see https://redis.io/commands/get
4148
+ */
4149
+ get = (...args) => new GetCommand(args, this.opts).exec(this.client);
4150
+ /**
4151
+ * @see https://redis.io/commands/getbit
4152
+ */
4153
+ getbit = (...args) => new GetBitCommand(args, this.opts).exec(this.client);
4154
+ /**
4155
+ * @see https://redis.io/commands/getdel
4156
+ */
4157
+ getdel = (...args) => new GetDelCommand(args, this.opts).exec(this.client);
4158
+ /**
4159
+ * @see https://redis.io/commands/getex
4160
+ */
4161
+ getex = (...args) => new GetExCommand(args, this.opts).exec(this.client);
4162
+ /**
4163
+ * @see https://redis.io/commands/getrange
4164
+ */
4165
+ getrange = (...args) => new GetRangeCommand(args, this.opts).exec(this.client);
4166
+ /**
4167
+ * @see https://redis.io/commands/getset
4168
+ */
4169
+ getset = (key, value) => new GetSetCommand([key, value], this.opts).exec(this.client);
4170
+ /**
4171
+ * @see https://redis.io/commands/hdel
4172
+ */
4173
+ hdel = (...args) => new HDelCommand(args, this.opts).exec(this.client);
4174
+ /**
4175
+ * @see https://redis.io/commands/hexists
4176
+ */
4177
+ hexists = (...args) => new HExistsCommand(args, this.opts).exec(this.client);
4178
+ /**
4179
+ * @see https://redis.io/commands/hexpire
4180
+ */
4181
+ hexpire = (...args) => new HExpireCommand(args, this.opts).exec(this.client);
4182
+ /**
4183
+ * @see https://redis.io/commands/hexpireat
4184
+ */
4185
+ hexpireat = (...args) => new HExpireAtCommand(args, this.opts).exec(this.client);
4186
+ /**
4187
+ * @see https://redis.io/commands/hexpiretime
4188
+ */
4189
+ hexpiretime = (...args) => new HExpireTimeCommand(args, this.opts).exec(this.client);
4190
+ /**
4191
+ * @see https://redis.io/commands/httl
4192
+ */
4193
+ httl = (...args) => new HTtlCommand(args, this.opts).exec(this.client);
4194
+ /**
4195
+ * @see https://redis.io/commands/hpexpire
4196
+ */
4197
+ hpexpire = (...args) => new HPExpireCommand(args, this.opts).exec(this.client);
4198
+ /**
4199
+ * @see https://redis.io/commands/hpexpireat
4200
+ */
4201
+ hpexpireat = (...args) => new HPExpireAtCommand(args, this.opts).exec(this.client);
4202
+ /**
4203
+ * @see https://redis.io/commands/hpexpiretime
4204
+ */
4205
+ hpexpiretime = (...args) => new HPExpireTimeCommand(args, this.opts).exec(this.client);
4206
+ /**
4207
+ * @see https://redis.io/commands/hpttl
4208
+ */
4209
+ hpttl = (...args) => new HPTtlCommand(args, this.opts).exec(this.client);
4210
+ /**
4211
+ * @see https://redis.io/commands/hpersist
4212
+ */
4213
+ hpersist = (...args) => new HPersistCommand(args, this.opts).exec(this.client);
4214
+ /**
4215
+ * @see https://redis.io/commands/hget
4216
+ */
4217
+ hget = (...args) => new HGetCommand(args, this.opts).exec(this.client);
4218
+ /**
4219
+ * @see https://redis.io/commands/hgetall
4220
+ */
4221
+ hgetall = (...args) => new HGetAllCommand(args, this.opts).exec(this.client);
4222
+ /**
4223
+ * @see https://redis.io/commands/hincrby
4224
+ */
4225
+ hincrby = (...args) => new HIncrByCommand(args, this.opts).exec(this.client);
4226
+ /**
4227
+ * @see https://redis.io/commands/hincrbyfloat
4228
+ */
4229
+ hincrbyfloat = (...args) => new HIncrByFloatCommand(args, this.opts).exec(this.client);
4230
+ /**
4231
+ * @see https://redis.io/commands/hkeys
4232
+ */
4233
+ hkeys = (...args) => new HKeysCommand(args, this.opts).exec(this.client);
4234
+ /**
4235
+ * @see https://redis.io/commands/hlen
4236
+ */
4237
+ hlen = (...args) => new HLenCommand(args, this.opts).exec(this.client);
4238
+ /**
4239
+ * @see https://redis.io/commands/hmget
4240
+ */
4241
+ hmget = (...args) => new HMGetCommand(args, this.opts).exec(this.client);
4242
+ /**
4243
+ * @see https://redis.io/commands/hmset
4244
+ */
4245
+ hmset = (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client);
4246
+ /**
4247
+ * @see https://redis.io/commands/hrandfield
4248
+ */
4249
+ hrandfield = (key, count, withValues) => new HRandFieldCommand([key, count, withValues], this.opts).exec(this.client);
4250
+ /**
4251
+ * @see https://redis.io/commands/hscan
4252
+ */
4253
+ hscan = (...args) => new HScanCommand(args, this.opts).exec(this.client);
4254
+ /**
4255
+ * @see https://redis.io/commands/hset
4256
+ */
4257
+ hset = (key, kv) => new HSetCommand([key, kv], this.opts).exec(this.client);
4258
+ /**
4259
+ * @see https://redis.io/commands/hsetnx
4260
+ */
4261
+ hsetnx = (key, field, value) => new HSetNXCommand([key, field, value], this.opts).exec(this.client);
4262
+ /**
4263
+ * @see https://redis.io/commands/hstrlen
4264
+ */
4265
+ hstrlen = (...args) => new HStrLenCommand(args, this.opts).exec(this.client);
4266
+ /**
4267
+ * @see https://redis.io/commands/hvals
4268
+ */
4269
+ hvals = (...args) => new HValsCommand(args, this.opts).exec(this.client);
4270
+ /**
4271
+ * @see https://redis.io/commands/incr
4272
+ */
4273
+ incr = (...args) => new IncrCommand(args, this.opts).exec(this.client);
4274
+ /**
4275
+ * @see https://redis.io/commands/incrby
4276
+ */
4277
+ incrby = (...args) => new IncrByCommand(args, this.opts).exec(this.client);
4278
+ /**
4279
+ * @see https://redis.io/commands/incrbyfloat
4280
+ */
4281
+ incrbyfloat = (...args) => new IncrByFloatCommand(args, this.opts).exec(this.client);
4282
+ /**
4283
+ * @see https://redis.io/commands/keys
4284
+ */
4285
+ keys = (...args) => new KeysCommand(args, this.opts).exec(this.client);
4286
+ /**
4287
+ * @see https://redis.io/commands/lindex
4288
+ */
4289
+ lindex = (...args) => new LIndexCommand(args, this.opts).exec(this.client);
4290
+ /**
4291
+ * @see https://redis.io/commands/linsert
4292
+ */
4293
+ linsert = (key, direction, pivot, value) => new LInsertCommand([key, direction, pivot, value], this.opts).exec(this.client);
4294
+ /**
4295
+ * @see https://redis.io/commands/llen
4296
+ */
4297
+ llen = (...args) => new LLenCommand(args, this.opts).exec(this.client);
4298
+ /**
4299
+ * @see https://redis.io/commands/lmove
4300
+ */
4301
+ lmove = (...args) => new LMoveCommand(args, this.opts).exec(this.client);
4302
+ /**
4303
+ * @see https://redis.io/commands/lpop
4304
+ */
4305
+ lpop = (...args) => new LPopCommand(args, this.opts).exec(this.client);
4306
+ /**
4307
+ * @see https://redis.io/commands/lmpop
4308
+ */
4309
+ lmpop = (...args) => new LmPopCommand(args, this.opts).exec(this.client);
4310
+ /**
4311
+ * @see https://redis.io/commands/lpos
4312
+ */
4313
+ lpos = (...args) => new LPosCommand(args, this.opts).exec(this.client);
4314
+ /**
4315
+ * @see https://redis.io/commands/lpush
4316
+ */
4317
+ lpush = (key, ...elements) => new LPushCommand([key, ...elements], this.opts).exec(this.client);
4318
+ /**
4319
+ * @see https://redis.io/commands/lpushx
4320
+ */
4321
+ lpushx = (key, ...elements) => new LPushXCommand([key, ...elements], this.opts).exec(this.client);
4322
+ /**
4323
+ * @see https://redis.io/commands/lrange
4324
+ */
4325
+ lrange = (...args) => new LRangeCommand(args, this.opts).exec(this.client);
4326
+ /**
4327
+ * @see https://redis.io/commands/lrem
4328
+ */
4329
+ lrem = (key, count, value) => new LRemCommand([key, count, value], this.opts).exec(this.client);
4330
+ /**
4331
+ * @see https://redis.io/commands/lset
4332
+ */
4333
+ lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
4334
+ /**
4335
+ * @see https://redis.io/commands/ltrim
4336
+ */
4337
+ ltrim = (...args) => new LTrimCommand(args, this.opts).exec(this.client);
4338
+ /**
4339
+ * @see https://redis.io/commands/mget
4340
+ */
4341
+ mget = (...args) => new MGetCommand(args, this.opts).exec(this.client);
4342
+ /**
4343
+ * @see https://redis.io/commands/mset
4344
+ */
4345
+ mset = (kv) => new MSetCommand([kv], this.opts).exec(this.client);
4346
+ /**
4347
+ * @see https://redis.io/commands/msetnx
4348
+ */
4349
+ msetnx = (kv) => new MSetNXCommand([kv], this.opts).exec(this.client);
4350
+ /**
4351
+ * @see https://redis.io/commands/persist
4352
+ */
4353
+ persist = (...args) => new PersistCommand(args, this.opts).exec(this.client);
4354
+ /**
4355
+ * @see https://redis.io/commands/pexpire
4356
+ */
4357
+ pexpire = (...args) => new PExpireCommand(args, this.opts).exec(this.client);
4358
+ /**
4359
+ * @see https://redis.io/commands/pexpireat
4360
+ */
4361
+ pexpireat = (...args) => new PExpireAtCommand(args, this.opts).exec(this.client);
4362
+ /**
4363
+ * @see https://redis.io/commands/pfadd
4364
+ */
4365
+ pfadd = (...args) => new PfAddCommand(args, this.opts).exec(this.client);
4366
+ /**
4367
+ * @see https://redis.io/commands/pfcount
4368
+ */
4369
+ pfcount = (...args) => new PfCountCommand(args, this.opts).exec(this.client);
4370
+ /**
4371
+ * @see https://redis.io/commands/pfmerge
4372
+ */
4373
+ pfmerge = (...args) => new PfMergeCommand(args, this.opts).exec(this.client);
4374
+ /**
4375
+ * @see https://redis.io/commands/ping
4376
+ */
4377
+ ping = (args) => new PingCommand(args, this.opts).exec(this.client);
4378
+ /**
4379
+ * @see https://redis.io/commands/psetex
4380
+ */
4381
+ psetex = (key, ttl, value) => new PSetEXCommand([key, ttl, value], this.opts).exec(this.client);
4382
+ /**
4383
+ * @see https://redis.io/commands/psubscribe
4384
+ */
4385
+ psubscribe = (patterns) => {
4386
+ const patternArray = Array.isArray(patterns) ? patterns : [patterns];
4387
+ return new Subscriber(this.client, patternArray, true, this.opts);
4388
+ };
4389
+ /**
4390
+ * @see https://redis.io/commands/pttl
4391
+ */
4392
+ pttl = (...args) => new PTtlCommand(args, this.opts).exec(this.client);
4393
+ /**
4394
+ * @see https://redis.io/commands/publish
4395
+ */
4396
+ publish = (...args) => new PublishCommand(args, this.opts).exec(this.client);
4397
+ /**
4398
+ * @see https://redis.io/commands/randomkey
4399
+ */
4400
+ randomkey = () => new RandomKeyCommand().exec(this.client);
4401
+ /**
4402
+ * @see https://redis.io/commands/rename
4403
+ */
4404
+ rename = (...args) => new RenameCommand(args, this.opts).exec(this.client);
4405
+ /**
4406
+ * @see https://redis.io/commands/renamenx
4407
+ */
4408
+ renamenx = (...args) => new RenameNXCommand(args, this.opts).exec(this.client);
4409
+ /**
4410
+ * @see https://redis.io/commands/rpop
4411
+ */
4412
+ rpop = (...args) => new RPopCommand(args, this.opts).exec(this.client);
4413
+ /**
4414
+ * @see https://redis.io/commands/rpush
4415
+ */
4416
+ rpush = (key, ...elements) => new RPushCommand([key, ...elements], this.opts).exec(this.client);
4417
+ /**
4418
+ * @see https://redis.io/commands/rpushx
4419
+ */
4420
+ rpushx = (key, ...elements) => new RPushXCommand([key, ...elements], this.opts).exec(this.client);
4421
+ /**
4422
+ * @see https://redis.io/commands/sadd
4423
+ */
4424
+ sadd = (key, member, ...members) => new SAddCommand([key, member, ...members], this.opts).exec(this.client);
4425
+ scan(cursor, opts) {
4426
+ return new ScanCommand([cursor, opts], this.opts).exec(this.client);
4427
+ }
4428
+ /**
4429
+ * @see https://redis.io/commands/scard
4430
+ */
4431
+ scard = (...args) => new SCardCommand(args, this.opts).exec(this.client);
4432
+ /**
4433
+ * @see https://redis.io/commands/script-exists
4434
+ */
4435
+ scriptExists = (...args) => new ScriptExistsCommand(args, this.opts).exec(this.client);
4436
+ /**
4437
+ * @see https://redis.io/commands/script-flush
4438
+ */
4439
+ scriptFlush = (...args) => new ScriptFlushCommand(args, this.opts).exec(this.client);
4440
+ /**
4441
+ * @see https://redis.io/commands/script-load
4442
+ */
4443
+ scriptLoad = (...args) => new ScriptLoadCommand(args, this.opts).exec(this.client);
4444
+ /**
4445
+ * @see https://redis.io/commands/sdiff
4446
+ */
4447
+ sdiff = (...args) => new SDiffCommand(args, this.opts).exec(this.client);
4448
+ /**
4449
+ * @see https://redis.io/commands/sdiffstore
4450
+ */
4451
+ sdiffstore = (...args) => new SDiffStoreCommand(args, this.opts).exec(this.client);
4452
+ /**
4453
+ * @see https://redis.io/commands/set
4454
+ */
4455
+ set = (key, value, opts) => new SetCommand([key, value, opts], this.opts).exec(this.client);
4456
+ /**
4457
+ * @see https://redis.io/commands/setbit
4458
+ */
4459
+ setbit = (...args) => new SetBitCommand(args, this.opts).exec(this.client);
4460
+ /**
4461
+ * @see https://redis.io/commands/setex
4462
+ */
4463
+ setex = (key, ttl, value) => new SetExCommand([key, ttl, value], this.opts).exec(this.client);
4464
+ /**
4465
+ * @see https://redis.io/commands/setnx
4466
+ */
4467
+ setnx = (key, value) => new SetNxCommand([key, value], this.opts).exec(this.client);
4468
+ /**
4469
+ * @see https://redis.io/commands/setrange
4470
+ */
4471
+ setrange = (...args) => new SetRangeCommand(args, this.opts).exec(this.client);
4472
+ /**
4473
+ * @see https://redis.io/commands/sinter
4474
+ */
4475
+ sinter = (...args) => new SInterCommand(args, this.opts).exec(this.client);
4476
+ /**
4477
+ * @see https://redis.io/commands/sinterstore
4478
+ */
4479
+ sinterstore = (...args) => new SInterStoreCommand(args, this.opts).exec(this.client);
4480
+ /**
4481
+ * @see https://redis.io/commands/sismember
4482
+ */
4483
+ sismember = (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client);
4484
+ /**
4485
+ * @see https://redis.io/commands/smismember
4486
+ */
4487
+ smismember = (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(this.client);
4488
+ /**
4489
+ * @see https://redis.io/commands/smembers
4490
+ */
4491
+ smembers = (...args) => new SMembersCommand(args, this.opts).exec(this.client);
4492
+ /**
4493
+ * @see https://redis.io/commands/smove
4494
+ */
4495
+ smove = (source, destination, member) => new SMoveCommand([source, destination, member], this.opts).exec(this.client);
4496
+ /**
4497
+ * @see https://redis.io/commands/spop
4498
+ */
4499
+ spop = (...args) => new SPopCommand(args, this.opts).exec(this.client);
4500
+ /**
4501
+ * @see https://redis.io/commands/srandmember
4502
+ */
4503
+ srandmember = (...args) => new SRandMemberCommand(args, this.opts).exec(this.client);
4504
+ /**
4505
+ * @see https://redis.io/commands/srem
4506
+ */
4507
+ srem = (key, ...members) => new SRemCommand([key, ...members], this.opts).exec(this.client);
4508
+ /**
4509
+ * @see https://redis.io/commands/sscan
4510
+ */
4511
+ sscan = (...args) => new SScanCommand(args, this.opts).exec(this.client);
4512
+ /**
4513
+ * @see https://redis.io/commands/strlen
4514
+ */
4515
+ strlen = (...args) => new StrLenCommand(args, this.opts).exec(this.client);
4516
+ /**
4517
+ * @see https://redis.io/commands/subscribe
4518
+ */
4519
+ subscribe = (channels) => {
4520
+ const channelArray = Array.isArray(channels) ? channels : [channels];
4521
+ return new Subscriber(this.client, channelArray, false, this.opts);
4522
+ };
4523
+ /**
4524
+ * @see https://redis.io/commands/sunion
4525
+ */
4526
+ sunion = (...args) => new SUnionCommand(args, this.opts).exec(this.client);
4527
+ /**
4528
+ * @see https://redis.io/commands/sunionstore
4529
+ */
4530
+ sunionstore = (...args) => new SUnionStoreCommand(args, this.opts).exec(this.client);
4531
+ /**
4532
+ * @see https://redis.io/commands/time
4533
+ */
4534
+ time = () => new TimeCommand().exec(this.client);
4535
+ /**
4536
+ * @see https://redis.io/commands/touch
4537
+ */
4538
+ touch = (...args) => new TouchCommand(args, this.opts).exec(this.client);
4539
+ /**
4540
+ * @see https://redis.io/commands/ttl
4541
+ */
4542
+ ttl = (...args) => new TtlCommand(args, this.opts).exec(this.client);
4543
+ /**
4544
+ * @see https://redis.io/commands/type
4545
+ */
4546
+ type = (...args) => new TypeCommand(args, this.opts).exec(this.client);
4547
+ /**
4548
+ * @see https://redis.io/commands/unlink
4549
+ */
4550
+ unlink = (...args) => new UnlinkCommand(args, this.opts).exec(this.client);
4551
+ /**
4552
+ * @see https://redis.io/commands/xadd
4553
+ */
4554
+ xadd = (...args) => new XAddCommand(args, this.opts).exec(this.client);
4555
+ /**
4556
+ * @see https://redis.io/commands/xack
4557
+ */
4558
+ xack = (...args) => new XAckCommand(args, this.opts).exec(this.client);
4559
+ /**
4560
+ * @see https://redis.io/commands/xdel
4561
+ */
4562
+ xdel = (...args) => new XDelCommand(args, this.opts).exec(this.client);
4563
+ /**
4564
+ * @see https://redis.io/commands/xgroup
4565
+ */
4566
+ xgroup = (...args) => new XGroupCommand(args, this.opts).exec(this.client);
4567
+ /**
4568
+ * @see https://redis.io/commands/xread
4569
+ */
4570
+ xread = (...args) => new XReadCommand(args, this.opts).exec(this.client);
4571
+ /**
4572
+ * @see https://redis.io/commands/xreadgroup
4573
+ */
4574
+ xreadgroup = (...args) => new XReadGroupCommand(args, this.opts).exec(this.client);
4575
+ /**
4576
+ * @see https://redis.io/commands/xinfo
4577
+ */
4578
+ xinfo = (...args) => new XInfoCommand(args, this.opts).exec(this.client);
4579
+ /**
4580
+ * @see https://redis.io/commands/xlen
4581
+ */
4582
+ xlen = (...args) => new XLenCommand(args, this.opts).exec(this.client);
4583
+ /**
4584
+ * @see https://redis.io/commands/xpending
4585
+ */
4586
+ xpending = (...args) => new XPendingCommand(args, this.opts).exec(this.client);
4587
+ /**
4588
+ * @see https://redis.io/commands/xclaim
4589
+ */
4590
+ xclaim = (...args) => new XClaimCommand(args, this.opts).exec(this.client);
4591
+ /**
4592
+ * @see https://redis.io/commands/xautoclaim
4593
+ */
4594
+ xautoclaim = (...args) => new XAutoClaim(args, this.opts).exec(this.client);
4595
+ /**
4596
+ * @see https://redis.io/commands/xtrim
4597
+ */
4598
+ xtrim = (...args) => new XTrimCommand(args, this.opts).exec(this.client);
4599
+ /**
4600
+ * @see https://redis.io/commands/xrange
4601
+ */
4602
+ xrange = (...args) => new XRangeCommand(args, this.opts).exec(this.client);
4603
+ /**
4604
+ * @see https://redis.io/commands/xrevrange
4605
+ */
4606
+ xrevrange = (...args) => new XRevRangeCommand(args, this.opts).exec(this.client);
4607
+ /**
4608
+ * @see https://redis.io/commands/zadd
4609
+ */
4610
+ zadd = (...args) => {
4611
+ if ("score" in args[1]) {
4612
+ return new ZAddCommand([args[0], args[1], ...args.slice(2)], this.opts).exec(
4613
+ this.client
4614
+ );
4615
+ }
4616
+ return new ZAddCommand(
4617
+ [args[0], args[1], ...args.slice(2)],
4618
+ this.opts
4619
+ ).exec(this.client);
4620
+ };
4621
+ /**
4622
+ * @see https://redis.io/commands/zcard
4623
+ */
4624
+ zcard = (...args) => new ZCardCommand(args, this.opts).exec(this.client);
4625
+ /**
4626
+ * @see https://redis.io/commands/zcount
4627
+ */
4628
+ zcount = (...args) => new ZCountCommand(args, this.opts).exec(this.client);
4629
+ /**
4630
+ * @see https://redis.io/commands/zdiffstore
4631
+ */
4632
+ zdiffstore = (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client);
4633
+ /**
4634
+ * @see https://redis.io/commands/zincrby
4635
+ */
4636
+ zincrby = (key, increment, member) => new ZIncrByCommand([key, increment, member], this.opts).exec(this.client);
4637
+ /**
4638
+ * @see https://redis.io/commands/zinterstore
4639
+ */
4640
+ zinterstore = (...args) => new ZInterStoreCommand(args, this.opts).exec(this.client);
4641
+ /**
4642
+ * @see https://redis.io/commands/zlexcount
4643
+ */
4644
+ zlexcount = (...args) => new ZLexCountCommand(args, this.opts).exec(this.client);
4645
+ /**
4646
+ * @see https://redis.io/commands/zmscore
4647
+ */
4648
+ zmscore = (...args) => new ZMScoreCommand(args, this.opts).exec(this.client);
4649
+ /**
4650
+ * @see https://redis.io/commands/zpopmax
4651
+ */
4652
+ zpopmax = (...args) => new ZPopMaxCommand(args, this.opts).exec(this.client);
4653
+ /**
4654
+ * @see https://redis.io/commands/zpopmin
4655
+ */
4656
+ zpopmin = (...args) => new ZPopMinCommand(args, this.opts).exec(this.client);
4657
+ /**
4658
+ * @see https://redis.io/commands/zrange
4659
+ */
4660
+ zrange = (...args) => new ZRangeCommand(args, this.opts).exec(this.client);
4661
+ /**
4662
+ * @see https://redis.io/commands/zrank
4663
+ */
4664
+ zrank = (key, member) => new ZRankCommand([key, member], this.opts).exec(this.client);
4665
+ /**
4666
+ * @see https://redis.io/commands/zrem
4667
+ */
4668
+ zrem = (key, ...members) => new ZRemCommand([key, ...members], this.opts).exec(this.client);
4669
+ /**
4670
+ * @see https://redis.io/commands/zremrangebylex
4671
+ */
4672
+ zremrangebylex = (...args) => new ZRemRangeByLexCommand(args, this.opts).exec(this.client);
4673
+ /**
4674
+ * @see https://redis.io/commands/zremrangebyrank
4675
+ */
4676
+ zremrangebyrank = (...args) => new ZRemRangeByRankCommand(args, this.opts).exec(this.client);
4677
+ /**
4678
+ * @see https://redis.io/commands/zremrangebyscore
4679
+ */
4680
+ zremrangebyscore = (...args) => new ZRemRangeByScoreCommand(args, this.opts).exec(this.client);
4681
+ /**
4682
+ * @see https://redis.io/commands/zrevrank
4683
+ */
4684
+ zrevrank = (key, member) => new ZRevRankCommand([key, member], this.opts).exec(this.client);
4685
+ /**
4686
+ * @see https://redis.io/commands/zscan
4687
+ */
4688
+ zscan = (...args) => new ZScanCommand(args, this.opts).exec(this.client);
4689
+ /**
4690
+ * @see https://redis.io/commands/zscore
4691
+ */
4692
+ zscore = (key, member) => new ZScoreCommand([key, member], this.opts).exec(this.client);
4693
+ /**
4694
+ * @see https://redis.io/commands/zunion
4695
+ */
4696
+ zunion = (...args) => new ZUnionCommand(args, this.opts).exec(this.client);
4697
+ /**
4698
+ * @see https://redis.io/commands/zunionstore
4699
+ */
4700
+ zunionstore = (...args) => new ZUnionStoreCommand(args, this.opts).exec(this.client);
4701
+ };
4702
+
4703
+ // version.ts
4704
+ var VERSION = "v1.30.2";
4705
+
4706
+ // platforms/cloudflare.ts
4707
+ var Redis2 = class _Redis extends Redis {
4708
+ /**
4709
+ * Create a new redis client
4710
+ *
4711
+ * @example
4712
+ * ```typescript
4713
+ * const redis = new Redis({
4714
+ * url: "<UPSTASH_REDIS_REST_URL>",
4715
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
4716
+ * });
4717
+ * ```
4718
+ */
4719
+ constructor(config, env) {
4720
+ if (!config.url) {
4721
+ console.warn(
4722
+ `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`
4723
+ );
4724
+ } else if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
4725
+ console.warn(
4726
+ "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!"
4727
+ );
4728
+ }
4729
+ if (!config.token) {
4730
+ console.warn(
4731
+ `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`
4732
+ );
4733
+ } else if (config.token.startsWith(" ") || config.token.endsWith(" ") || /\r|\n/.test(config.token)) {
4734
+ console.warn(
4735
+ "[Upstash Redis] The redis token contains whitespace or newline, which can cause errors!"
4736
+ );
4737
+ }
4738
+ const client = new HttpClient({
4739
+ retry: config.retry,
4740
+ baseUrl: config.url,
4741
+ headers: { authorization: `Bearer ${config.token}` },
4742
+ responseEncoding: config.responseEncoding,
4743
+ signal: config.signal,
4744
+ keepAlive: config.keepAlive,
4745
+ readYourWrites: config.readYourWrites
4746
+ });
4747
+ super(client, {
4748
+ enableTelemetry: config.enableTelemetry ?? !env?.UPSTASH_DISABLE_TELEMETRY,
4749
+ automaticDeserialization: config.automaticDeserialization,
4750
+ latencyLogging: config.latencyLogging,
4751
+ enableAutoPipelining: config.enableAutoPipelining
4752
+ });
4753
+ this.addTelemetry({
4754
+ platform: "cloudflare",
4755
+ sdk: `@upstash/redis@${VERSION}`
4756
+ });
4757
+ if (this.enableAutoPipelining) {
4758
+ return this.autoPipeline();
4759
+ }
4760
+ }
4761
+ /*
4762
+ * Create a new Upstash Redis instance from environment variables on cloudflare.
4763
+ *
4764
+ * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
4765
+ * the global namespace
4766
+ *
4767
+ * If you are using a module worker, please pass in the `env` object.
4768
+ * ```ts
4769
+ * const redis = Redis.fromEnv(env)
4770
+ * ```
4771
+ */
4772
+ static fromEnv(env, opts) {
4773
+ const url = env?.UPSTASH_REDIS_REST_URL ?? // @ts-expect-error These will be defined by cloudflare
4774
+ (typeof UPSTASH_REDIS_REST_URL === "string" ? (
4775
+ // @ts-expect-error These will be defined by cloudflare
4776
+ UPSTASH_REDIS_REST_URL
4777
+ ) : void 0);
4778
+ const token = env?.UPSTASH_REDIS_REST_TOKEN ?? // @ts-expect-error These will be defined by cloudflare
4779
+ (typeof UPSTASH_REDIS_REST_TOKEN === "string" ? (
4780
+ // @ts-expect-error These will be defined by cloudflare
4781
+ UPSTASH_REDIS_REST_TOKEN
4782
+ ) : void 0);
4783
+ const messageInfo = !url && !token ? "Unable to find environment variables: `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`" : url ? token ? void 0 : "Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`" : "Unable to find environment variable: `UPSTASH_REDIS_REST_URL`";
4784
+ if (messageInfo) {
4785
+ console.warn(
4786
+ `[Upstash Redis] ${messageInfo}. Please add it via \`wrangler secret put ${url ? "UPSTASH_REDIS_REST_TOKEN" : "UPSTASH_REDIS_REST_URL"}\` and provide it as an argument to the \`Redis.fromEnv\` function`
4787
+ );
4788
+ }
4789
+ return new _Redis({ ...opts, url, token }, env);
4790
+ }
4791
+ };
4792
+ // Annotate the CommonJS export names for ESM import in node:
4793
+ 0 && (module.exports = {
4794
+ Redis,
4795
+ errors
4796
+ });