@upstash/redis 0.0.0-ci.120db276

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 (381) hide show
  1. package/.releaserc +14 -0
  2. package/LICENSE +21 -0
  3. package/README.md +361 -0
  4. package/esm/package.json +3 -0
  5. package/esm/pkg/commands/append.js +9 -0
  6. package/esm/pkg/commands/bitcount.js +16 -0
  7. package/esm/pkg/commands/bitop.js +9 -0
  8. package/esm/pkg/commands/bitpos.js +9 -0
  9. package/esm/pkg/commands/command.js +57 -0
  10. package/esm/pkg/commands/dbsize.js +9 -0
  11. package/esm/pkg/commands/decr.js +9 -0
  12. package/esm/pkg/commands/decrby.js +9 -0
  13. package/esm/pkg/commands/del.js +9 -0
  14. package/esm/pkg/commands/echo.js +9 -0
  15. package/esm/pkg/commands/eval.js +9 -0
  16. package/esm/pkg/commands/evalsha.js +9 -0
  17. package/esm/pkg/commands/exists.js +9 -0
  18. package/esm/pkg/commands/expire.js +9 -0
  19. package/esm/pkg/commands/expireat.js +9 -0
  20. package/esm/pkg/commands/flushall.js +13 -0
  21. package/esm/pkg/commands/flushdb.js +13 -0
  22. package/esm/pkg/commands/get.js +9 -0
  23. package/esm/pkg/commands/getbit.js +9 -0
  24. package/esm/pkg/commands/getrange.js +9 -0
  25. package/esm/pkg/commands/getset.js +9 -0
  26. package/esm/pkg/commands/hdel.js +9 -0
  27. package/esm/pkg/commands/hexists.js +9 -0
  28. package/esm/pkg/commands/hget.js +9 -0
  29. package/esm/pkg/commands/hgetall.js +33 -0
  30. package/esm/pkg/commands/hincrby.js +9 -0
  31. package/esm/pkg/commands/hincrbyfloat.js +9 -0
  32. package/esm/pkg/commands/hkeys.js +9 -0
  33. package/esm/pkg/commands/hlen.js +9 -0
  34. package/esm/pkg/commands/hmget.js +35 -0
  35. package/esm/pkg/commands/hmset.js +13 -0
  36. package/esm/pkg/commands/hscan.js +16 -0
  37. package/esm/pkg/commands/hset.js +13 -0
  38. package/esm/pkg/commands/hsetnx.js +9 -0
  39. package/esm/pkg/commands/hstrlen.js +9 -0
  40. package/esm/pkg/commands/hvals.js +9 -0
  41. package/esm/pkg/commands/incr.js +9 -0
  42. package/esm/pkg/commands/incrby.js +9 -0
  43. package/esm/pkg/commands/incrbyfloat.js +9 -0
  44. package/esm/pkg/commands/keys.js +9 -0
  45. package/esm/pkg/commands/lindex.js +6 -0
  46. package/esm/pkg/commands/linsert.js +6 -0
  47. package/esm/pkg/commands/llen.js +9 -0
  48. package/esm/pkg/commands/lpop.js +9 -0
  49. package/esm/pkg/commands/lpush.js +9 -0
  50. package/esm/pkg/commands/lpushx.js +9 -0
  51. package/esm/pkg/commands/lrange.js +6 -0
  52. package/esm/pkg/commands/lrem.js +6 -0
  53. package/esm/pkg/commands/lset.js +6 -0
  54. package/esm/pkg/commands/ltrim.js +6 -0
  55. package/esm/pkg/commands/mget.js +9 -0
  56. package/esm/pkg/commands/mod.js +114 -0
  57. package/esm/pkg/commands/mset.js +12 -0
  58. package/esm/pkg/commands/msetnx.js +9 -0
  59. package/esm/pkg/commands/persist.js +9 -0
  60. package/esm/pkg/commands/pexpire.js +9 -0
  61. package/esm/pkg/commands/pexpireat.js +9 -0
  62. package/esm/pkg/commands/ping.js +13 -0
  63. package/esm/pkg/commands/psetex.js +9 -0
  64. package/esm/pkg/commands/pttl.js +9 -0
  65. package/esm/pkg/commands/publish.js +9 -0
  66. package/esm/pkg/commands/randomkey.js +9 -0
  67. package/esm/pkg/commands/rename.js +9 -0
  68. package/esm/pkg/commands/renamenx.js +9 -0
  69. package/esm/pkg/commands/rpop.js +9 -0
  70. package/esm/pkg/commands/rpush.js +9 -0
  71. package/esm/pkg/commands/rpushx.js +9 -0
  72. package/esm/pkg/commands/sadd.js +9 -0
  73. package/esm/pkg/commands/scan.js +16 -0
  74. package/esm/pkg/commands/scard.js +9 -0
  75. package/esm/pkg/commands/script_exists.js +12 -0
  76. package/esm/pkg/commands/script_flush.js +16 -0
  77. package/esm/pkg/commands/script_load.js +9 -0
  78. package/esm/pkg/commands/sdiff.js +9 -0
  79. package/esm/pkg/commands/sdiffstore.js +9 -0
  80. package/esm/pkg/commands/set.js +24 -0
  81. package/esm/pkg/commands/setbit.js +9 -0
  82. package/esm/pkg/commands/setex.js +9 -0
  83. package/esm/pkg/commands/setnx.js +9 -0
  84. package/esm/pkg/commands/setrange.js +9 -0
  85. package/esm/pkg/commands/sinter.js +9 -0
  86. package/esm/pkg/commands/sinterstore.js +9 -0
  87. package/esm/pkg/commands/sismember.js +9 -0
  88. package/esm/pkg/commands/smembers.js +9 -0
  89. package/esm/pkg/commands/smove.js +9 -0
  90. package/esm/pkg/commands/spop.js +13 -0
  91. package/esm/pkg/commands/srandmember.js +13 -0
  92. package/esm/pkg/commands/srem.js +9 -0
  93. package/esm/pkg/commands/sscan.js +16 -0
  94. package/esm/pkg/commands/strlen.js +9 -0
  95. package/esm/pkg/commands/sunion.js +9 -0
  96. package/esm/pkg/commands/sunionstore.js +9 -0
  97. package/esm/pkg/commands/time.js +9 -0
  98. package/esm/pkg/commands/touch.js +9 -0
  99. package/esm/pkg/commands/ttl.js +9 -0
  100. package/esm/pkg/commands/type.js +9 -0
  101. package/esm/pkg/commands/unlink.js +9 -0
  102. package/esm/pkg/commands/zadd.js +26 -0
  103. package/esm/pkg/commands/zcard.js +9 -0
  104. package/esm/pkg/commands/zcount.js +9 -0
  105. package/esm/pkg/commands/zincrby.js +9 -0
  106. package/esm/pkg/commands/zinterstore.js +27 -0
  107. package/esm/pkg/commands/zlexcount.js +9 -0
  108. package/esm/pkg/commands/zpopmax.js +13 -0
  109. package/esm/pkg/commands/zpopmin.js +13 -0
  110. package/esm/pkg/commands/zrange.js +20 -0
  111. package/esm/pkg/commands/zrank.js +9 -0
  112. package/esm/pkg/commands/zrem.js +9 -0
  113. package/esm/pkg/commands/zremrangebylex.js +9 -0
  114. package/esm/pkg/commands/zremrangebyrank.js +9 -0
  115. package/esm/pkg/commands/zremrangebyscore.js +9 -0
  116. package/esm/pkg/commands/zrevrank.js +9 -0
  117. package/esm/pkg/commands/zscan.js +16 -0
  118. package/esm/pkg/commands/zscore.js +9 -0
  119. package/esm/pkg/commands/zunionstore.js +27 -0
  120. package/esm/pkg/error.js +9 -0
  121. package/esm/pkg/http.js +77 -0
  122. package/esm/pkg/pipeline.js +1125 -0
  123. package/esm/pkg/redis.js +1067 -0
  124. package/esm/pkg/types.js +1 -0
  125. package/esm/pkg/util.js +31 -0
  126. package/esm/platforms/cloudflare.js +62 -0
  127. package/esm/platforms/fastly.js +40 -0
  128. package/esm/platforms/node_with_fetch.js +60 -0
  129. package/esm/platforms/nodejs.js +59 -0
  130. package/package.json +101 -0
  131. package/script/package.json +3 -0
  132. package/script/pkg/commands/append.js +13 -0
  133. package/script/pkg/commands/bitcount.js +20 -0
  134. package/script/pkg/commands/bitop.js +13 -0
  135. package/script/pkg/commands/bitpos.js +13 -0
  136. package/script/pkg/commands/command.js +61 -0
  137. package/script/pkg/commands/dbsize.js +13 -0
  138. package/script/pkg/commands/decr.js +13 -0
  139. package/script/pkg/commands/decrby.js +13 -0
  140. package/script/pkg/commands/del.js +13 -0
  141. package/script/pkg/commands/echo.js +13 -0
  142. package/script/pkg/commands/eval.js +13 -0
  143. package/script/pkg/commands/evalsha.js +13 -0
  144. package/script/pkg/commands/exists.js +13 -0
  145. package/script/pkg/commands/expire.js +13 -0
  146. package/script/pkg/commands/expireat.js +13 -0
  147. package/script/pkg/commands/flushall.js +17 -0
  148. package/script/pkg/commands/flushdb.js +17 -0
  149. package/script/pkg/commands/get.js +13 -0
  150. package/script/pkg/commands/getbit.js +13 -0
  151. package/script/pkg/commands/getrange.js +13 -0
  152. package/script/pkg/commands/getset.js +13 -0
  153. package/script/pkg/commands/hdel.js +13 -0
  154. package/script/pkg/commands/hexists.js +13 -0
  155. package/script/pkg/commands/hget.js +13 -0
  156. package/script/pkg/commands/hgetall.js +37 -0
  157. package/script/pkg/commands/hincrby.js +13 -0
  158. package/script/pkg/commands/hincrbyfloat.js +13 -0
  159. package/script/pkg/commands/hkeys.js +13 -0
  160. package/script/pkg/commands/hlen.js +13 -0
  161. package/script/pkg/commands/hmget.js +39 -0
  162. package/script/pkg/commands/hmset.js +17 -0
  163. package/script/pkg/commands/hscan.js +20 -0
  164. package/script/pkg/commands/hset.js +17 -0
  165. package/script/pkg/commands/hsetnx.js +13 -0
  166. package/script/pkg/commands/hstrlen.js +13 -0
  167. package/script/pkg/commands/hvals.js +13 -0
  168. package/script/pkg/commands/incr.js +13 -0
  169. package/script/pkg/commands/incrby.js +13 -0
  170. package/script/pkg/commands/incrbyfloat.js +13 -0
  171. package/script/pkg/commands/keys.js +13 -0
  172. package/script/pkg/commands/lindex.js +10 -0
  173. package/script/pkg/commands/linsert.js +10 -0
  174. package/script/pkg/commands/llen.js +13 -0
  175. package/script/pkg/commands/lpop.js +13 -0
  176. package/script/pkg/commands/lpush.js +13 -0
  177. package/script/pkg/commands/lpushx.js +13 -0
  178. package/script/pkg/commands/lrange.js +10 -0
  179. package/script/pkg/commands/lrem.js +10 -0
  180. package/script/pkg/commands/lset.js +10 -0
  181. package/script/pkg/commands/ltrim.js +10 -0
  182. package/script/pkg/commands/mget.js +13 -0
  183. package/script/pkg/commands/mod.js +130 -0
  184. package/script/pkg/commands/mset.js +16 -0
  185. package/script/pkg/commands/msetnx.js +13 -0
  186. package/script/pkg/commands/persist.js +13 -0
  187. package/script/pkg/commands/pexpire.js +13 -0
  188. package/script/pkg/commands/pexpireat.js +13 -0
  189. package/script/pkg/commands/ping.js +17 -0
  190. package/script/pkg/commands/psetex.js +13 -0
  191. package/script/pkg/commands/pttl.js +13 -0
  192. package/script/pkg/commands/publish.js +13 -0
  193. package/script/pkg/commands/randomkey.js +13 -0
  194. package/script/pkg/commands/rename.js +13 -0
  195. package/script/pkg/commands/renamenx.js +13 -0
  196. package/script/pkg/commands/rpop.js +13 -0
  197. package/script/pkg/commands/rpush.js +13 -0
  198. package/script/pkg/commands/rpushx.js +13 -0
  199. package/script/pkg/commands/sadd.js +13 -0
  200. package/script/pkg/commands/scan.js +20 -0
  201. package/script/pkg/commands/scard.js +13 -0
  202. package/script/pkg/commands/script_exists.js +16 -0
  203. package/script/pkg/commands/script_flush.js +20 -0
  204. package/script/pkg/commands/script_load.js +13 -0
  205. package/script/pkg/commands/sdiff.js +13 -0
  206. package/script/pkg/commands/sdiffstore.js +13 -0
  207. package/script/pkg/commands/set.js +28 -0
  208. package/script/pkg/commands/setbit.js +13 -0
  209. package/script/pkg/commands/setex.js +13 -0
  210. package/script/pkg/commands/setnx.js +13 -0
  211. package/script/pkg/commands/setrange.js +13 -0
  212. package/script/pkg/commands/sinter.js +13 -0
  213. package/script/pkg/commands/sinterstore.js +13 -0
  214. package/script/pkg/commands/sismember.js +13 -0
  215. package/script/pkg/commands/smembers.js +13 -0
  216. package/script/pkg/commands/smove.js +13 -0
  217. package/script/pkg/commands/spop.js +17 -0
  218. package/script/pkg/commands/srandmember.js +17 -0
  219. package/script/pkg/commands/srem.js +13 -0
  220. package/script/pkg/commands/sscan.js +20 -0
  221. package/script/pkg/commands/strlen.js +13 -0
  222. package/script/pkg/commands/sunion.js +13 -0
  223. package/script/pkg/commands/sunionstore.js +13 -0
  224. package/script/pkg/commands/time.js +13 -0
  225. package/script/pkg/commands/touch.js +13 -0
  226. package/script/pkg/commands/ttl.js +13 -0
  227. package/script/pkg/commands/type.js +13 -0
  228. package/script/pkg/commands/unlink.js +13 -0
  229. package/script/pkg/commands/zadd.js +30 -0
  230. package/script/pkg/commands/zcard.js +13 -0
  231. package/script/pkg/commands/zcount.js +13 -0
  232. package/script/pkg/commands/zincrby.js +13 -0
  233. package/script/pkg/commands/zinterstore.js +31 -0
  234. package/script/pkg/commands/zlexcount.js +13 -0
  235. package/script/pkg/commands/zpopmax.js +17 -0
  236. package/script/pkg/commands/zpopmin.js +17 -0
  237. package/script/pkg/commands/zrange.js +24 -0
  238. package/script/pkg/commands/zrank.js +13 -0
  239. package/script/pkg/commands/zrem.js +13 -0
  240. package/script/pkg/commands/zremrangebylex.js +13 -0
  241. package/script/pkg/commands/zremrangebyrank.js +13 -0
  242. package/script/pkg/commands/zremrangebyscore.js +13 -0
  243. package/script/pkg/commands/zrevrank.js +13 -0
  244. package/script/pkg/commands/zscan.js +20 -0
  245. package/script/pkg/commands/zscore.js +13 -0
  246. package/script/pkg/commands/zunionstore.js +31 -0
  247. package/script/pkg/error.js +13 -0
  248. package/script/pkg/http.js +81 -0
  249. package/script/pkg/pipeline.js +1129 -0
  250. package/script/pkg/redis.js +1071 -0
  251. package/script/pkg/types.js +2 -0
  252. package/script/pkg/util.js +35 -0
  253. package/script/platforms/cloudflare.js +89 -0
  254. package/script/platforms/fastly.js +67 -0
  255. package/script/platforms/node_with_fetch.js +87 -0
  256. package/script/platforms/nodejs.js +86 -0
  257. package/types/pkg/commands/append.d.ts +7 -0
  258. package/types/pkg/commands/bitcount.d.ts +8 -0
  259. package/types/pkg/commands/bitop.d.ts +13 -0
  260. package/types/pkg/commands/bitpos.d.ts +7 -0
  261. package/types/pkg/commands/command.d.ts +37 -0
  262. package/types/pkg/commands/dbsize.d.ts +7 -0
  263. package/types/pkg/commands/decr.d.ts +7 -0
  264. package/types/pkg/commands/decrby.d.ts +7 -0
  265. package/types/pkg/commands/del.d.ts +7 -0
  266. package/types/pkg/commands/echo.d.ts +7 -0
  267. package/types/pkg/commands/eval.d.ts +7 -0
  268. package/types/pkg/commands/evalsha.d.ts +7 -0
  269. package/types/pkg/commands/exists.d.ts +7 -0
  270. package/types/pkg/commands/expire.d.ts +7 -0
  271. package/types/pkg/commands/expireat.d.ts +7 -0
  272. package/types/pkg/commands/flushall.d.ts +9 -0
  273. package/types/pkg/commands/flushdb.d.ts +9 -0
  274. package/types/pkg/commands/get.d.ts +7 -0
  275. package/types/pkg/commands/getbit.d.ts +7 -0
  276. package/types/pkg/commands/getrange.d.ts +7 -0
  277. package/types/pkg/commands/getset.d.ts +7 -0
  278. package/types/pkg/commands/hdel.d.ts +7 -0
  279. package/types/pkg/commands/hexists.d.ts +7 -0
  280. package/types/pkg/commands/hget.d.ts +7 -0
  281. package/types/pkg/commands/hgetall.d.ts +7 -0
  282. package/types/pkg/commands/hincrby.d.ts +7 -0
  283. package/types/pkg/commands/hincrbyfloat.d.ts +7 -0
  284. package/types/pkg/commands/hkeys.d.ts +7 -0
  285. package/types/pkg/commands/hlen.d.ts +7 -0
  286. package/types/pkg/commands/hmget.d.ts +15 -0
  287. package/types/pkg/commands/hmset.d.ts +9 -0
  288. package/types/pkg/commands/hscan.d.ts +24 -0
  289. package/types/pkg/commands/hset.d.ts +9 -0
  290. package/types/pkg/commands/hsetnx.d.ts +7 -0
  291. package/types/pkg/commands/hstrlen.d.ts +7 -0
  292. package/types/pkg/commands/hvals.d.ts +7 -0
  293. package/types/pkg/commands/incr.d.ts +7 -0
  294. package/types/pkg/commands/incrby.d.ts +7 -0
  295. package/types/pkg/commands/incrbyfloat.d.ts +7 -0
  296. package/types/pkg/commands/keys.d.ts +7 -0
  297. package/types/pkg/commands/lindex.d.ts +4 -0
  298. package/types/pkg/commands/linsert.d.ts +9 -0
  299. package/types/pkg/commands/llen.d.ts +7 -0
  300. package/types/pkg/commands/lpop.d.ts +7 -0
  301. package/types/pkg/commands/lpush.d.ts +7 -0
  302. package/types/pkg/commands/lpushx.d.ts +7 -0
  303. package/types/pkg/commands/lrange.d.ts +4 -0
  304. package/types/pkg/commands/lrem.d.ts +4 -0
  305. package/types/pkg/commands/lset.d.ts +4 -0
  306. package/types/pkg/commands/ltrim.d.ts +4 -0
  307. package/types/pkg/commands/mget.d.ts +7 -0
  308. package/types/pkg/commands/mod.d.ts +114 -0
  309. package/types/pkg/commands/mset.d.ts +9 -0
  310. package/types/pkg/commands/msetnx.d.ts +9 -0
  311. package/types/pkg/commands/persist.d.ts +7 -0
  312. package/types/pkg/commands/pexpire.d.ts +7 -0
  313. package/types/pkg/commands/pexpireat.d.ts +7 -0
  314. package/types/pkg/commands/ping.d.ts +7 -0
  315. package/types/pkg/commands/psetex.d.ts +7 -0
  316. package/types/pkg/commands/pttl.d.ts +7 -0
  317. package/types/pkg/commands/publish.d.ts +7 -0
  318. package/types/pkg/commands/randomkey.d.ts +7 -0
  319. package/types/pkg/commands/rename.d.ts +7 -0
  320. package/types/pkg/commands/renamenx.d.ts +7 -0
  321. package/types/pkg/commands/rpop.d.ts +7 -0
  322. package/types/pkg/commands/rpush.d.ts +7 -0
  323. package/types/pkg/commands/rpushx.d.ts +7 -0
  324. package/types/pkg/commands/sadd.d.ts +7 -0
  325. package/types/pkg/commands/scan.d.ts +17 -0
  326. package/types/pkg/commands/scard.d.ts +7 -0
  327. package/types/pkg/commands/script_exists.d.ts +7 -0
  328. package/types/pkg/commands/script_flush.d.ts +14 -0
  329. package/types/pkg/commands/script_load.d.ts +7 -0
  330. package/types/pkg/commands/sdiff.d.ts +7 -0
  331. package/types/pkg/commands/sdiffstore.d.ts +7 -0
  332. package/types/pkg/commands/set.d.ts +26 -0
  333. package/types/pkg/commands/setbit.d.ts +7 -0
  334. package/types/pkg/commands/setex.d.ts +7 -0
  335. package/types/pkg/commands/setnx.d.ts +7 -0
  336. package/types/pkg/commands/setrange.d.ts +7 -0
  337. package/types/pkg/commands/sinter.d.ts +7 -0
  338. package/types/pkg/commands/sinterstore.d.ts +7 -0
  339. package/types/pkg/commands/sismember.d.ts +7 -0
  340. package/types/pkg/commands/smembers.d.ts +7 -0
  341. package/types/pkg/commands/smove.d.ts +7 -0
  342. package/types/pkg/commands/spop.d.ts +7 -0
  343. package/types/pkg/commands/srandmember.d.ts +7 -0
  344. package/types/pkg/commands/srem.d.ts +7 -0
  345. package/types/pkg/commands/sscan.d.ts +24 -0
  346. package/types/pkg/commands/strlen.d.ts +7 -0
  347. package/types/pkg/commands/sunion.d.ts +7 -0
  348. package/types/pkg/commands/sunionstore.d.ts +7 -0
  349. package/types/pkg/commands/time.d.ts +7 -0
  350. package/types/pkg/commands/touch.d.ts +7 -0
  351. package/types/pkg/commands/ttl.d.ts +7 -0
  352. package/types/pkg/commands/type.d.ts +8 -0
  353. package/types/pkg/commands/unlink.d.ts +7 -0
  354. package/types/pkg/commands/zadd.d.ts +35 -0
  355. package/types/pkg/commands/zcard.d.ts +7 -0
  356. package/types/pkg/commands/zcount.d.ts +7 -0
  357. package/types/pkg/commands/zincrby.d.ts +7 -0
  358. package/types/pkg/commands/zinterstore.d.ts +30 -0
  359. package/types/pkg/commands/zlexcount.d.ts +7 -0
  360. package/types/pkg/commands/zpopmax.d.ts +7 -0
  361. package/types/pkg/commands/zpopmin.d.ts +7 -0
  362. package/types/pkg/commands/zrange.d.ts +35 -0
  363. package/types/pkg/commands/zrank.d.ts +7 -0
  364. package/types/pkg/commands/zrem.d.ts +7 -0
  365. package/types/pkg/commands/zremrangebylex.d.ts +7 -0
  366. package/types/pkg/commands/zremrangebyrank.d.ts +7 -0
  367. package/types/pkg/commands/zremrangebyscore.d.ts +7 -0
  368. package/types/pkg/commands/zrevrank.d.ts +7 -0
  369. package/types/pkg/commands/zscan.d.ts +24 -0
  370. package/types/pkg/commands/zscore.d.ts +7 -0
  371. package/types/pkg/commands/zunionstore.d.ts +30 -0
  372. package/types/pkg/error.d.ts +6 -0
  373. package/types/pkg/http.d.ts +54 -0
  374. package/types/pkg/pipeline.d.ts +540 -0
  375. package/types/pkg/redis.d.ts +516 -0
  376. package/types/pkg/types.d.ts +1 -0
  377. package/types/pkg/util.d.ts +1 -0
  378. package/types/platforms/cloudflare.d.ts +42 -0
  379. package/types/platforms/fastly.d.ts +45 -0
  380. package/types/platforms/node_with_fetch.d.ts +82 -0
  381. package/types/platforms/nodejs.d.ts +81 -0
package/.releaserc ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "branches": [
3
+ {
4
+ "name": "release"
5
+ },
6
+ {
7
+ "name": "main",
8
+ "channel": "next",
9
+ "prerelease": "next"
10
+ }
11
+ ],
12
+ "dryRun": false,
13
+ "ci": true
14
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Upstash, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,361 @@
1
+ # Upstash Redis
2
+
3
+ `@upstash/redis` is an HTTP/REST based Redis client for typescript, built on top
4
+ of [Upstash REST API](https://docs.upstash.com/features/restapi).
5
+
6
+ [![Tests](https://github.com/upstash/upstash-redis/actions/workflows/tests.yaml/badge.svg)](https://github.com/upstash/upstash-redis/actions/workflows/tests.yaml)
7
+ ![npm (scoped)](https://img.shields.io/npm/v/@upstash/redis)
8
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@upstash/redis)
9
+
10
+ It is the only connectionless (HTTP based) Redis client and designed for:
11
+
12
+ - Serverless functions (AWS Lambda ...)
13
+ - Cloudflare Workers (see
14
+ [the example](https://github.com/upstash/upstash-redis/tree/master/examples/cloudflare-workers))
15
+ - Fastly Compute@Edge (see
16
+ [the example](https://github.com/upstash/upstash-redis/tree/master/examples/fastly))
17
+ - Next.js, Jamstack ...
18
+ - Client side web/mobile applications
19
+ - WebAssembly
20
+ - and other environments where HTTP is preferred over TCP.
21
+
22
+ See
23
+ [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-api-compatibility)
24
+ supported.
25
+
26
+ ## Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
27
+
28
+ If you are running on nodejs v17 and earlier, `fetch` will not be natively
29
+ supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
30
+ for you. But if you are running on bare node, you need to either specify a
31
+ polyfill yourself or change the import path to:
32
+
33
+ ```typescript
34
+ import { Redis } from "@upstash/redis/with-fetch";
35
+ ```
36
+
37
+ ## Upgrading from v0.2.0?
38
+
39
+ Please read the
40
+ [migration guide](https://github.com/upstash/upstash-redis#migrating-to-v1). For
41
+ further explanation we wrote a
42
+ [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
43
+
44
+ ## Quick Start
45
+
46
+ ### Install
47
+
48
+ #### npm
49
+
50
+ ```bash
51
+ npm install @upstash/redis
52
+ ```
53
+
54
+ #### Deno
55
+
56
+ ```ts
57
+ import { Redis } from "https://deno.land/x/upstash_redis/mod.ts";
58
+ ```
59
+
60
+ ### Create database
61
+
62
+ Create a new redis database on [upstash](https://console.upstash.com/)
63
+
64
+ ### Environments
65
+
66
+ We support various platforms, such as nodejs, cloudflare and fastly. Platforms
67
+ differ slightly when it comes to environment variables and their `fetch` api.
68
+ Please use the correct import when deploying to special platforms.
69
+
70
+ #### Node.js
71
+
72
+ Examples: Vercel, Netlify, AWS Lambda
73
+
74
+ If you are running on nodejs you can set `UPSTASH_REDIS_REST_URL` and
75
+ `UPSTASH_REDIS_REST_TOKEN` as environment variable and create a redis instance
76
+ like this:
77
+
78
+ ```ts
79
+ import { Redis } from "@upstash/redis"
80
+
81
+ const redis = new Redis({
82
+ url: <UPSTASH_REDIS_REST_URL>,
83
+ token: <UPSTASH_REDIS_REST_TOKEN>,
84
+ })
85
+
86
+ // or load directly from env
87
+ const redis = Redis.fromEnv()
88
+ ```
89
+
90
+ If you are running on nodejs v17 and earlier, `fetch` will not be natively
91
+ supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
92
+ for you. But if you are running on bare node, you need to either specify a
93
+ polyfill yourself or change the import path to:
94
+
95
+ ```typescript
96
+ import { Redis } from "@upstash/redis/with-fetch";
97
+ ```
98
+
99
+ - [Code example](https://github.com/upstash/upstash-redis/blob/main/examples/nodejs)
100
+
101
+ #### Cloudflare Workers
102
+
103
+ Cloudflare handles environment variables differently than nodejs. Please add
104
+ `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` using
105
+ `wrangler secret put ...` or in the cloudflare dashboard.
106
+
107
+ Afterwards you can create a redis instance:
108
+
109
+ ```ts
110
+ import { Redis } from "@upstash/redis/cloudflare"
111
+
112
+ const redis = new Redis({
113
+ url: <UPSTASH_REDIS_REST_URL>,
114
+ token: <UPSTASH_REDIS_REST_TOKEN>,
115
+ })
116
+
117
+
118
+ // or load directly from global env
119
+
120
+ // service worker
121
+ const redis = Redis.fromEnv()
122
+
123
+
124
+ // module worker
125
+ export default {
126
+ async fetch(request: Request, env: Bindings) {
127
+ const redis = Redis.fromEnv(env)
128
+ // ...
129
+ }
130
+ }
131
+ ```
132
+
133
+ - [Code example service worker](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers)
134
+ - [Code example module worker](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers-modules)
135
+ - [Documentation](https://docs.upstash.com/redis/tutorials/cloudflare_workers_with_redis)
136
+
137
+ #### Fastly
138
+
139
+ Fastly introduces a concept called
140
+ [backend](https://developer.fastly.com/reference/api/services/backend/). You
141
+ need to configure a backend in your `fastly.toml`. An example can be found
142
+ [here](https://github.com/upstash/upstash-redis/blob/main/examples/fastly/fastly.toml).
143
+ Until the fastly api stabilizes we recommend creating an instance manually:
144
+
145
+ ```ts
146
+ import { Redis } from "@upstash/redis/fastly"
147
+
148
+ const redis = new Redis({
149
+ url: <UPSTASH_REDIS_REST_URL>,
150
+ token: <UPSTASH_REDIS_REST_TOKEN>,
151
+ backend: <BACKEND_NAME>,
152
+ })
153
+ ```
154
+
155
+ - [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/fastly)
156
+ - [Documentation](https://blog.upstash.com/fastly-compute-edge-with-redi)
157
+
158
+ #### Deno
159
+
160
+ Examples: [Deno Deploy](https://deno.com/deploy),
161
+ [Netlify Edge](https://www.netlify.com/products/edge/)
162
+
163
+ ```ts
164
+ import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"
165
+
166
+ const redis = new Redis({
167
+ url: <UPSTASH_REDIS_REST_URL>,
168
+ token: <UPSTASH_REDIS_REST_TOKEN>,
169
+ })
170
+
171
+ // or
172
+ const redis = Redis.fromEnv();
173
+ ```
174
+
175
+ ### Working with types
176
+
177
+ Most commands allow you to provide a type to make working with typescript
178
+ easier.
179
+
180
+ ```ts
181
+ const data = await redis.get<MyCustomType>("key");
182
+ // data is typed as `MyCustomType`
183
+ ```
184
+
185
+ ## Migrating to v1
186
+
187
+ ### Explicit authentication
188
+
189
+ The library is no longer automatically trying to load connection secrets from
190
+ environment variables. You must either supply them yourself:
191
+
192
+ ```ts
193
+ import { Redis } from "@upstash/redis"
194
+
195
+ const redis = new Redis({
196
+ url: <UPSTASH_REDIS_REST_URL>,
197
+ token: <UPSTASH_REDIS_REST_TOKEN>,
198
+ })
199
+ ```
200
+
201
+ Or use one of the static constructors to load from environment variables:
202
+
203
+ ```ts
204
+ // Nodejs
205
+ import { Redis } from "@upstash/redis";
206
+ const redis = Redis.fromEnv();
207
+ ```
208
+
209
+ ```ts
210
+ // or when deploying to cloudflare workers
211
+ import { Redis } from "@upstash/redis/cloudflare";
212
+ const redis = Redis.fromEnv();
213
+ ```
214
+
215
+ ### Error handling
216
+
217
+ Errors are now thrown automatically instead of being returned to you.
218
+
219
+ ```ts
220
+ // old
221
+ const { data, error } = await set("key", "value");
222
+ if (error) {
223
+ throw new Error(error);
224
+ }
225
+
226
+ // new
227
+ const data = await redis.set("key", "value"); // error is thrown automatically
228
+ ```
229
+
230
+ ## Pipeline
231
+
232
+ `v1.0.0` introduces redis pipelines. Pipelining commands allows you to send a
233
+ single http request with multiple commands.
234
+
235
+ ```ts
236
+ import { Redis } from "@upstash/redis";
237
+
238
+ const redis = new Redis({
239
+ /* auth */
240
+ });
241
+
242
+ const p = redis.pipeline();
243
+
244
+ // Now you can chain multiple commands to create your pipeline:
245
+
246
+ p.set("key", 2);
247
+ p.incr("key");
248
+
249
+ // or inline:
250
+ p.hset("key2", "field", { hello: "world" }).hvals("key2");
251
+
252
+ // Execute the pipeline once you are done building it:
253
+ // `exec` returns an array where each element represents the response of a command in the pipeline.
254
+ // You can optionally provide a type like this to get a typed response.
255
+ const res = await p.exec<[Type1, Type2, Type3]>();
256
+ ```
257
+
258
+ For more information about pipelines using REST see
259
+ [here](https://blog.upstash.com/pipeline).
260
+
261
+ ### Advanced
262
+
263
+ A low level `Command` class can be imported from `@upstash/redis` in case you
264
+ need more control about types and or (de)serialization.
265
+
266
+ By default all objects you are storing in redis are serialized using
267
+ `JSON.stringify` and recursively deserialized as well. Here's an example how you
268
+ could customize that behaviour. Keep in mind that you need to provide a `fetch`
269
+ polyfill if you are running on nodejs. We recommend
270
+ [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch).
271
+
272
+ ```ts
273
+ import { Command } from "@upstash/redis/commands"
274
+ import { HttpClient } from "@upstash/redis/http"
275
+
276
+ /**
277
+ * TData represents what the user will enter or receive,
278
+ * TResult is the raw data returned from upstash, which may need to be
279
+ * transformed or parsed.
280
+ */
281
+ const deserialize: (raw: TResult) => TData = ...
282
+
283
+ class CustomGetCommand<TData, TResult> extends Command<TData | null, TResult | null> {
284
+ constructor(key: string, ) {
285
+ super(["get", key], { deserialize })
286
+ }
287
+ }
288
+
289
+ const client = new HttpClient({
290
+ baseUrl: <UPSTASH_REDIS_REST_URL>,
291
+ headers: {
292
+ authorization: `Bearer ${<UPSTASH_REDIS_REST_TOKEN>}`,
293
+ },
294
+ })
295
+
296
+ const res = new CustomGetCommand("key").exec(client)
297
+ ```
298
+
299
+ ### Additional information
300
+
301
+ #### `keepalive`
302
+
303
+ `@upstash/redis` is capable of reusing connections where possible to minimize
304
+ latency. Connections can be reused if the client is stored in memory and not
305
+ initialized with every new function invocation. The easiest way to achieve this
306
+ is by creating the client outside of your handler and adding an https agent:
307
+
308
+ ```ts
309
+ // Nextjs api route
310
+ import { Redis } from "@upstash/redis";
311
+ import https from "https";
312
+
313
+ const redis = Redis.fromEnv({
314
+ agent: new https.Agent({ keepAlive: true }),
315
+ });
316
+
317
+ export default async function (req, res) {
318
+ // use redis here
319
+ }
320
+ ```
321
+
322
+ Whenever your hot lambda receives a new request the client is already
323
+ initialized and the previously established connection to upstash is reused.
324
+
325
+ #### Javascript MAX_SAFE_INTEGER
326
+
327
+ Javascript can not handle numbers larger than `2^53 -1` safely and would return
328
+ wrong results when trying to deserialize them. In these cases the default
329
+ deserializer will return them as string instead. This might cause a mismatch
330
+ with your custom types.
331
+
332
+ ```ts
333
+ await redis.set("key", "101600000000150081467");
334
+ const res = await redis<number>("get");
335
+ ```
336
+
337
+ In this example `res` will still be a string despite the type annotation. Please
338
+ keep that in mind and adjust accordingly.
339
+
340
+ ## Docs
341
+
342
+ See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
343
+ details.
344
+
345
+ ## Contributing
346
+
347
+ ### [Install Deno](https://deno.land/#installation)
348
+
349
+ ### Database
350
+
351
+ Create a new redis database on [upstash](https://console.upstash.com/) and copy
352
+ the url and token
353
+
354
+ ### Running tests
355
+
356
+ ```sh
357
+ UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
358
+ ```
359
+
360
+ ```
361
+ ```
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/append
4
+ */
5
+ export class AppendCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["append", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,16 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/bitcount
4
+ */
5
+ export class BitCountCommand extends Command {
6
+ constructor([key, start, end], opts) {
7
+ const command = ["bitcount", key];
8
+ if (typeof start === "number") {
9
+ command.push(start);
10
+ }
11
+ if (typeof end === "number") {
12
+ command.push(end);
13
+ }
14
+ super(command, opts);
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/bitop
4
+ */
5
+ export class BitOpCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["bitop", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/bitpos
4
+ */
5
+ export class BitPosCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["bitpos", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,57 @@
1
+ import { UpstashError } from "../error.js";
2
+ import { parseResponse } from "../util.js";
3
+ const defaultSerializer = (c) => typeof c === "string" ? c : JSON.stringify(c);
4
+ /**
5
+ * Command offers default (de)serialization and the exec method to all commands.
6
+ *
7
+ * TData represents what the user will enter or receive,
8
+ * TResult is the raw data returned from upstash, which may need to be transformed or parsed.
9
+ */
10
+ export class Command {
11
+ /**
12
+ * Create a new command instance.
13
+ *
14
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
15
+ */
16
+ constructor(command, opts) {
17
+ Object.defineProperty(this, "command", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "serialize", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "deserialize", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ this.serialize = defaultSerializer;
36
+ this.deserialize = typeof opts?.automaticDeserialization === "undefined" ||
37
+ opts.automaticDeserialization
38
+ ? opts?.deserialize ?? parseResponse
39
+ : (x) => x;
40
+ this.command = command.map(this.serialize);
41
+ }
42
+ /**
43
+ * Execute the command using a client.
44
+ */
45
+ async exec(client) {
46
+ const { result, error } = await client.request({
47
+ body: this.command,
48
+ });
49
+ if (error) {
50
+ throw new UpstashError(error);
51
+ }
52
+ if (typeof result === "undefined") {
53
+ throw new Error(`Request did not return a result`);
54
+ }
55
+ return this.deserialize(result);
56
+ }
57
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/dbsize
4
+ */
5
+ export class DBSizeCommand extends Command {
6
+ constructor(opts) {
7
+ super(["dbsize"], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/decr
4
+ */
5
+ export class DecrCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["decr", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/decrby
4
+ */
5
+ export class DecrByCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["decrby", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/del
4
+ */
5
+ export class DelCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["del", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/echo
4
+ */
5
+ export class EchoCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["echo", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/eval
4
+ */
5
+ export class EvalCommand extends Command {
6
+ constructor([script, keys, args], opts) {
7
+ super(["eval", script, keys.length, ...keys, ...(args ?? [])], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/evalsha
4
+ */
5
+ export class EvalshaCommand extends Command {
6
+ constructor([sha, keys, args], opts) {
7
+ super(["evalsha", sha, keys.length, ...keys, ...(args ?? [])], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/exists
4
+ */
5
+ export class ExistsCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["exists", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/expire
4
+ */
5
+ export class ExpireCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["expire", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/expireat
4
+ */
5
+ export class ExpireAtCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["expireat", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/flushall
4
+ */
5
+ export class FlushAllCommand extends Command {
6
+ constructor(args, opts) {
7
+ const command = ["flushall"];
8
+ if (args && args.length > 0 && args[0].async) {
9
+ command.push("async");
10
+ }
11
+ super(command, opts);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/flushdb
4
+ */
5
+ export class FlushDBCommand extends Command {
6
+ constructor([opts], cmdOpts) {
7
+ const command = ["flushdb"];
8
+ if (opts?.async) {
9
+ command.push("async");
10
+ }
11
+ super(command, cmdOpts);
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/get
4
+ */
5
+ export class GetCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["get", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getbit
4
+ */
5
+ export class GetBitCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["getbit", ...cmd], opts);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getrange
4
+ */
5
+ export class GetRangeCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["getrange", ...cmd], opts);
8
+ }
9
+ }