@upstash/redis 0.0.0-ci.babdc47f97e036e2863dfed16300cda2b97bf6ad-20240322001434 → 0.0.0-ci.bb93ac2803c2e927dc8bf1a1b3c5aa2a14034eb6-20240930061920
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.
- package/.env.example +2 -0
- package/.github/workflows/release.yml +53 -0
- package/.github/workflows/tests.yaml +609 -0
- package/.gitignore +175 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +2 -0
- package/.husky/pre-push +1 -0
- package/.prettierignore +1 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +20 -0
- package/README.md +1 -2
- package/bun.lockb +0 -0
- package/commitlint.config.js +46 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +136 -0
- package/dist/chunk-TEVCO3ZO.mjs +3797 -0
- package/dist/cloudflare.d.mts +55 -0
- package/dist/cloudflare.d.ts +55 -0
- package/dist/cloudflare.js +3907 -0
- package/dist/cloudflare.mjs +91 -0
- package/dist/fastly.d.mts +48 -0
- package/dist/fastly.d.ts +48 -0
- package/dist/fastly.js +3880 -0
- package/dist/fastly.mjs +64 -0
- package/dist/nodejs.d.mts +73 -0
- package/dist/nodejs.d.ts +73 -0
- package/dist/nodejs.js +3926 -0
- package/dist/nodejs.mjs +110 -0
- package/dist/package.json +1 -0
- package/{zmscore-5d82e632.d.ts → dist/zmscore-BhX8yEQc.d.mts} +249 -184
- package/dist/zmscore-BhX8yEQc.d.ts +3486 -0
- package/eslint.config.mjs +102 -0
- package/examples/auto-pipeline/.eslintrc.json +3 -0
- package/examples/auto-pipeline/README.md +77 -0
- package/examples/auto-pipeline/app/components/DataComponent.tsx +49 -0
- package/examples/auto-pipeline/app/data/getEvents.ts +18 -0
- package/examples/auto-pipeline/app/data/getUsers.ts +18 -0
- package/examples/auto-pipeline/app/data/redis.ts +12 -0
- package/examples/auto-pipeline/app/favicon.ico +0 -0
- package/examples/auto-pipeline/app/globals.css +0 -0
- package/examples/auto-pipeline/app/layout.tsx +22 -0
- package/examples/auto-pipeline/app/page.tsx +15 -0
- package/examples/auto-pipeline/next.config.mjs +4 -0
- package/examples/auto-pipeline/package.json +27 -0
- package/examples/auto-pipeline/postcss.config.mjs +8 -0
- package/examples/auto-pipeline/public/next.svg +1 -0
- package/examples/auto-pipeline/public/vercel.svg +1 -0
- package/examples/auto-pipeline/tailwind.config.ts +20 -0
- package/examples/auto-pipeline/tsconfig.json +26 -0
- package/examples/aws-cdk-python/README.md +36 -0
- package/examples/aws-cdk-python/cdk.json +72 -0
- package/examples/aws-cdk-python/jest.config.js +8 -0
- package/examples/aws-cdk-python/lib/api/index.py +10 -0
- package/examples/aws-cdk-python/lib/api/requirements.txt +1 -0
- package/examples/aws-cdk-python/package-lock.json +4470 -0
- package/examples/aws-cdk-python/package.json +27 -0
- package/examples/aws-cdk-python/tsconfig.json +31 -0
- package/examples/aws-cdk-typescript/README.md +36 -0
- package/examples/aws-cdk-typescript/cdk.json +72 -0
- package/examples/aws-cdk-typescript/jest.config.js +8 -0
- package/examples/aws-cdk-typescript/package-lock.json +4548 -0
- package/examples/aws-cdk-typescript/package.json +28 -0
- package/examples/aws-cdk-typescript/tsconfig.json +31 -0
- package/examples/aws-lambda/README.md +39 -0
- package/examples/aws-lambda/index.js +11 -0
- package/examples/aws-lambda/package-lock.json +27 -0
- package/examples/aws-lambda/package.json +6 -0
- package/examples/aws-sam/README.md +34 -0
- package/examples/aws-sam/__init__.py +0 -0
- package/examples/aws-sam/events/event.json +62 -0
- package/examples/aws-sam/hello_world/__init__.py +0 -0
- package/examples/aws-sam/hello_world/app.py +10 -0
- package/examples/aws-sam/hello_world/requirements.txt +2 -0
- package/examples/aws-sam/samconfig.toml +34 -0
- package/examples/aws-sam/template.yaml +52 -0
- package/examples/aws-sam/tests/__init__.py +0 -0
- package/examples/aws-sam/tests/integration/__init__.py +0 -0
- package/examples/aws-sam/tests/integration/test_api_gateway.py +45 -0
- package/examples/aws-sam/tests/requirements.txt +3 -0
- package/examples/aws-sam/tests/unit/__init__.py +0 -0
- package/examples/aws-sam/tests/unit/test_handler.py +72 -0
- package/examples/azure-functions/.funcignore +10 -0
- package/examples/azure-functions/.vscode/extensions.json +5 -0
- package/examples/azure-functions/README.md +67 -0
- package/examples/azure-functions/host.json +15 -0
- package/examples/azure-functions/package-lock.json +1019 -0
- package/examples/azure-functions/package.json +24 -0
- package/examples/azure-functions/src/functions/CounterFunction.ts +19 -0
- package/examples/azure-functions/tsconfig.json +10 -0
- package/examples/cloudflare-workers/README.md +26 -0
- package/examples/cloudflare-workers/bun.lockb +0 -0
- package/examples/cloudflare-workers/ci.test.ts +18 -0
- package/examples/cloudflare-workers/index.js +11 -0
- package/examples/cloudflare-workers/package.json +17 -0
- package/examples/cloudflare-workers/wrangler.toml +11 -0
- package/examples/cloudflare-workers-with-typescript/README.md +26 -0
- package/examples/cloudflare-workers-with-typescript/ci.test.ts +17 -0
- package/examples/cloudflare-workers-with-typescript/package.json +17 -0
- package/examples/cloudflare-workers-with-typescript/src/index.ts +16 -0
- package/examples/cloudflare-workers-with-typescript/tsconfig.json +105 -0
- package/examples/cloudflare-workers-with-typescript/wrangler.toml +9 -0
- package/examples/deno/main.test.ts +16 -0
- package/examples/deno/main.ts +9 -0
- package/examples/fastapi/README.md +23 -0
- package/examples/fastapi/main.py +12 -0
- package/examples/fastapi/requirements.txt +2 -0
- package/examples/fastly/README.md +7 -0
- package/examples/fastly/fastly.toml +12 -0
- package/examples/fastly/package.json +23 -0
- package/examples/fastly/src/index.js +19 -0
- package/examples/fastly/webpack.config.js +28 -0
- package/examples/google-cloud-functions/README.md +37 -0
- package/examples/google-cloud-functions/index.js +12 -0
- package/examples/google-cloud-functions/package.json +7 -0
- package/examples/ion/.env.example +2 -0
- package/examples/ion/.eslintrc.json +3 -0
- package/examples/ion/README.md +49 -0
- package/examples/ion/app/favicon.ico +0 -0
- package/examples/ion/app/globals.css +33 -0
- package/examples/ion/app/layout.tsx +22 -0
- package/examples/ion/app/page.tsx +12 -0
- package/examples/ion/next.config.mjs +4 -0
- package/examples/ion/package-lock.json +6709 -0
- package/examples/ion/package.json +28 -0
- package/examples/ion/postcss.config.mjs +8 -0
- package/examples/ion/public/next.svg +1 -0
- package/examples/ion/public/vercel.svg +1 -0
- package/examples/ion/sst-env.d.ts +12 -0
- package/examples/ion/sst.config.ts +19 -0
- package/examples/ion/tailwind.config.ts +20 -0
- package/examples/ion/tsconfig.json +26 -0
- package/examples/nextjs-app-router/.env.example +2 -0
- package/examples/nextjs-app-router/.eslintrc.json +3 -0
- package/examples/nextjs-app-router/README.md +26 -0
- package/examples/nextjs-app-router/app/globals.css +3 -0
- package/examples/nextjs-app-router/app/layout.tsx +22 -0
- package/examples/nextjs-app-router/app/page.tsx +12 -0
- package/examples/nextjs-app-router/next.config.mjs +4 -0
- package/examples/nextjs-app-router/package.json +27 -0
- package/examples/nextjs-app-router/postcss.config.mjs +8 -0
- package/examples/nextjs-app-router/tailwind.config.ts +20 -0
- package/examples/nextjs-app-router/tsconfig.json +26 -0
- package/examples/nextjs-pages-router/.env.example +2 -0
- package/examples/nextjs-pages-router/.eslintrc.json +3 -0
- package/examples/nextjs-pages-router/README.md +26 -0
- package/examples/nextjs-pages-router/next.config.mjs +6 -0
- package/examples/nextjs-pages-router/package.json +27 -0
- package/examples/nextjs-pages-router/pages/_app.tsx +6 -0
- package/examples/nextjs-pages-router/pages/_document.tsx +13 -0
- package/examples/nextjs-pages-router/pages/api/hello.ts +13 -0
- package/examples/nextjs-pages-router/pages/index.tsx +19 -0
- package/examples/nextjs-pages-router/postcss.config.mjs +8 -0
- package/examples/nextjs-pages-router/styles/globals.css +3 -0
- package/examples/nextjs-pages-router/tailwind.config.ts +20 -0
- package/examples/nextjs-pages-router/tsconfig.json +21 -0
- package/examples/nodejs/.env.example +2 -0
- package/examples/nodejs/README.md +24 -0
- package/examples/nodejs/index.js +10 -0
- package/examples/nodejs/package.json +10 -0
- package/examples/serverless-framework/counter/.env.example +2 -0
- package/examples/serverless-framework/counter/README.md +38 -0
- package/examples/serverless-framework/counter/handler.js +12 -0
- package/examples/serverless-framework/counter/package-lock.json +27 -0
- package/examples/serverless-framework/counter/package.json +6 -0
- package/examples/serverless-framework/counter/serverless.yml +16 -0
- package/examples/sst-v2/.vscode/launch.json +15 -0
- package/examples/sst-v2/.vscode/settings.json +5 -0
- package/examples/sst-v2/README.md +62 -0
- package/examples/sst-v2/package.json +27 -0
- package/examples/sst-v2/packages/core/package.json +14 -0
- package/examples/sst-v2/packages/core/sst-env.d.ts +1 -0
- package/examples/sst-v2/packages/core/tsconfig.json +7 -0
- package/examples/sst-v2/packages/functions/package.json +15 -0
- package/examples/sst-v2/packages/functions/sst-env.d.ts +1 -0
- package/examples/sst-v2/packages/functions/tsconfig.json +11 -0
- package/examples/sst-v2/packages/web/README.md +40 -0
- package/examples/sst-v2/packages/web/next.config.mjs +6 -0
- package/examples/sst-v2/packages/web/package.json +23 -0
- package/examples/sst-v2/packages/web/pages/_app.tsx +6 -0
- package/examples/sst-v2/packages/web/pages/_document.tsx +13 -0
- package/examples/sst-v2/packages/web/pages/api/hello.ts +16 -0
- package/examples/sst-v2/packages/web/pages/index.tsx +114 -0
- package/examples/sst-v2/packages/web/public/favicon.ico +0 -0
- package/examples/sst-v2/packages/web/public/next.svg +1 -0
- package/examples/sst-v2/packages/web/public/vercel.svg +1 -0
- package/examples/sst-v2/packages/web/sst-env.d.ts +1 -0
- package/examples/sst-v2/packages/web/styles/Home.module.css +229 -0
- package/examples/sst-v2/packages/web/styles/globals.css +107 -0
- package/examples/sst-v2/packages/web/tsconfig.json +36 -0
- package/examples/sst-v2/pnpm-workspace.yaml +2 -0
- package/examples/sst-v2/sst.config.ts +14 -0
- package/examples/sst-v2/stacks/Default.ts +13 -0
- package/examples/sst-v2/tsconfig.json +8 -0
- package/examples/terraform/README.md +38 -0
- package/examples/terraform/counter/counter.js +11 -0
- package/examples/terraform/counter/package.json +6 -0
- package/examples/terraform/main.tf +166 -0
- package/examples/terraform/outputs.tf +17 -0
- package/examples/terraform/terraform.tf +18 -0
- package/examples/terraform/variables.tf +6 -0
- package/examples/vercel-functions-app-router/.env.example +2 -0
- package/examples/vercel-functions-app-router/.eslintrc.json +3 -0
- package/examples/vercel-functions-app-router/README.md +26 -0
- package/examples/vercel-functions-app-router/app/api/hello/route.ts +11 -0
- package/examples/vercel-functions-app-router/app/globals.css +3 -0
- package/examples/vercel-functions-app-router/app/layout.tsx +22 -0
- package/examples/vercel-functions-app-router/ci.test.ts +14 -0
- package/examples/vercel-functions-app-router/next.config.mjs +4 -0
- package/examples/vercel-functions-app-router/package.json +27 -0
- package/examples/vercel-functions-app-router/postcss.config.mjs +8 -0
- package/examples/vercel-functions-app-router/tailwind.config.ts +20 -0
- package/examples/vercel-functions-app-router/tsconfig.json +26 -0
- package/examples/vercel-functions-pages-router/.env.example +2 -0
- package/examples/vercel-functions-pages-router/.eslintrc.json +3 -0
- package/examples/vercel-functions-pages-router/README.md +26 -0
- package/examples/vercel-functions-pages-router/ci.test.ts +14 -0
- package/examples/vercel-functions-pages-router/next.config.mjs +6 -0
- package/examples/vercel-functions-pages-router/package.json +27 -0
- package/examples/vercel-functions-pages-router/pages/_app.tsx +6 -0
- package/examples/vercel-functions-pages-router/pages/_document.tsx +13 -0
- package/examples/vercel-functions-pages-router/pages/api/hello.ts +12 -0
- package/examples/vercel-functions-pages-router/postcss.config.mjs +8 -0
- package/examples/vercel-functions-pages-router/styles/globals.css +3 -0
- package/examples/vercel-functions-pages-router/tailwind.config.ts +20 -0
- package/examples/vercel-functions-pages-router/tsconfig.json +21 -0
- package/examples/vercel-python-runtime-django/.env.example +2 -0
- package/examples/vercel-python-runtime-django/README.md +34 -0
- package/examples/vercel-python-runtime-django/api/__init__.py +0 -0
- package/examples/vercel-python-runtime-django/api/asgi.py +16 -0
- package/examples/vercel-python-runtime-django/api/settings.py +121 -0
- package/examples/vercel-python-runtime-django/api/urls.py +22 -0
- package/examples/vercel-python-runtime-django/api/wsgi.py +16 -0
- package/examples/vercel-python-runtime-django/example/__init__.py +0 -0
- package/examples/vercel-python-runtime-django/example/admin.py +3 -0
- package/examples/vercel-python-runtime-django/example/apps.py +6 -0
- package/examples/vercel-python-runtime-django/example/urls.py +9 -0
- package/examples/vercel-python-runtime-django/example/views.py +18 -0
- package/examples/vercel-python-runtime-django/manage.py +22 -0
- package/examples/vercel-python-runtime-django/package.json +5 -0
- package/examples/vercel-python-runtime-django/requirements.txt +2 -0
- package/examples/vercel-python-runtime-django/vercel.json +8 -0
- package/examples/with-sentry/index.ts +36 -0
- package/examples/with-sentry/package.json +17 -0
- package/package.json +1 -1
- package/pkg/auto-pipeline.test.ts +321 -0
- package/pkg/auto-pipeline.ts +107 -0
- package/pkg/commands/append.test.ts +28 -0
- package/pkg/commands/append.ts +11 -0
- package/pkg/commands/bitcount.test.ts +37 -0
- package/pkg/commands/bitcount.ts +29 -0
- package/pkg/commands/bitfield.test.ts +51 -0
- package/pkg/commands/bitfield.ts +50 -0
- package/pkg/commands/bitop.test.ts +45 -0
- package/pkg/commands/bitop.ts +22 -0
- package/pkg/commands/bitpos.test.ts +47 -0
- package/pkg/commands/bitpos.ts +14 -0
- package/pkg/commands/command.test.ts +22 -0
- package/pkg/commands/command.ts +98 -0
- package/pkg/commands/copy.test.ts +65 -0
- package/pkg/commands/copy.ts +22 -0
- package/pkg/commands/dbsize.test.ts +18 -0
- package/pkg/commands/dbsize.ts +11 -0
- package/pkg/commands/decr.test.ts +23 -0
- package/pkg/commands/decr.ts +11 -0
- package/pkg/commands/decrby.test.ts +24 -0
- package/pkg/commands/decrby.ts +11 -0
- package/pkg/commands/del.test.ts +38 -0
- package/pkg/commands/del.ts +11 -0
- package/pkg/commands/echo.test.ts +11 -0
- package/pkg/commands/echo.ts +11 -0
- package/pkg/commands/eval.test.ts +30 -0
- package/pkg/commands/eval.ts +14 -0
- package/pkg/commands/evalsha.test.ts +19 -0
- package/pkg/commands/evalsha.ts +14 -0
- package/pkg/commands/exists.test.ts +38 -0
- package/pkg/commands/exists.ts +11 -0
- package/pkg/commands/expire.test.ts +119 -0
- package/pkg/commands/expire.ts +12 -0
- package/pkg/commands/expireat.test.ts +25 -0
- package/pkg/commands/expireat.ts +11 -0
- package/pkg/commands/flushall.test.ts +18 -0
- package/pkg/commands/flushall.ts +14 -0
- package/pkg/commands/flushdb.test.ts +17 -0
- package/pkg/commands/flushdb.ts +14 -0
- package/pkg/commands/geo_add.test.ts +202 -0
- package/pkg/commands/geo_add.ts +54 -0
- package/pkg/commands/geo_dist.test.ts +79 -0
- package/pkg/commands/geo_dist.ts +19 -0
- package/pkg/commands/geo_hash.test.ts +49 -0
- package/pkg/commands/geo_hash.ts +23 -0
- package/pkg/commands/geo_pos.test.ts +60 -0
- package/pkg/commands/geo_pos.ts +39 -0
- package/pkg/commands/geo_search.test.ts +197 -0
- package/pkg/commands/geo_search.ts +139 -0
- package/pkg/commands/geo_search_store.test.ts +153 -0
- package/pkg/commands/geo_search_store.ts +69 -0
- package/pkg/commands/get.test.ts +35 -0
- package/pkg/commands/get.ts +11 -0
- package/pkg/commands/getbit.test.ts +17 -0
- package/pkg/commands/getbit.ts +11 -0
- package/pkg/commands/getdel.test.ts +39 -0
- package/pkg/commands/getdel.ts +11 -0
- package/pkg/commands/getrange.test.ts +25 -0
- package/pkg/commands/getrange.ts +14 -0
- package/pkg/commands/getset.test.ts +33 -0
- package/pkg/commands/getset.ts +14 -0
- package/pkg/commands/hdel.test.ts +45 -0
- package/pkg/commands/hdel.ts +11 -0
- package/pkg/commands/hexists.test.ts +36 -0
- package/pkg/commands/hexists.ts +11 -0
- package/pkg/commands/hget.test.ts +52 -0
- package/pkg/commands/hget.ts +14 -0
- package/pkg/commands/hgetall.test.ts +45 -0
- package/pkg/commands/hgetall.ts +37 -0
- package/pkg/commands/hincrby.test.ts +28 -0
- package/pkg/commands/hincrby.ts +14 -0
- package/pkg/commands/hincrbyfloat.test.ts +28 -0
- package/pkg/commands/hincrbyfloat.ts +14 -0
- package/pkg/commands/hkeys.test.ts +23 -0
- package/pkg/commands/hkeys.ts +11 -0
- package/pkg/commands/hlen.test.ts +25 -0
- package/pkg/commands/hlen.ts +11 -0
- package/pkg/commands/hmget.test.ts +44 -0
- package/pkg/commands/hmget.ts +46 -0
- package/pkg/commands/hmset.test.ts +23 -0
- package/pkg/commands/hmset.ts +14 -0
- package/pkg/commands/hrandfield.test.ts +59 -0
- package/pkg/commands/hrandfield.ts +50 -0
- package/pkg/commands/hscan.test.ts +44 -0
- package/pkg/commands/hscan.ts +30 -0
- package/pkg/commands/hset.test.ts +21 -0
- package/pkg/commands/hset.ts +14 -0
- package/pkg/commands/hsetnx.test.ts +37 -0
- package/pkg/commands/hsetnx.ts +14 -0
- package/pkg/commands/hstrlen.test.ts +24 -0
- package/pkg/commands/hstrlen.ts +11 -0
- package/pkg/commands/hvals.test.ts +24 -0
- package/pkg/commands/hvals.ts +11 -0
- package/pkg/commands/incr.test.ts +24 -0
- package/pkg/commands/incr.ts +11 -0
- package/pkg/commands/incrby.test.ts +24 -0
- package/pkg/commands/incrby.ts +11 -0
- package/pkg/commands/incrbyfloat.test.ts +25 -0
- package/pkg/commands/incrbyfloat.ts +11 -0
- package/pkg/commands/json_arrappend.test.ts +40 -0
- package/pkg/commands/json_arrappend.ts +17 -0
- package/pkg/commands/json_arrindex.test.ts +54 -0
- package/pkg/commands/json_arrindex.ts +14 -0
- package/pkg/commands/json_arrinsert.test.ts +49 -0
- package/pkg/commands/json_arrinsert.ts +17 -0
- package/pkg/commands/json_arrlen.test.ts +31 -0
- package/pkg/commands/json_arrlen.ts +14 -0
- package/pkg/commands/json_arrpop.test.ts +30 -0
- package/pkg/commands/json_arrpop.ts +14 -0
- package/pkg/commands/json_arrtrim.test.ts +31 -0
- package/pkg/commands/json_arrtrim.ts +18 -0
- package/pkg/commands/json_clear.test.ts +35 -0
- package/pkg/commands/json_clear.ts +11 -0
- package/pkg/commands/json_del.test.ts +29 -0
- package/pkg/commands/json_del.ts +11 -0
- package/pkg/commands/json_forget.test.ts +29 -0
- package/pkg/commands/json_forget.ts +11 -0
- package/pkg/commands/json_get.test.ts +28 -0
- package/pkg/commands/json_get.ts +44 -0
- package/pkg/commands/json_mget.test.ts +43 -0
- package/pkg/commands/json_mget.ts +11 -0
- package/pkg/commands/json_mset.test.ts +50 -0
- package/pkg/commands/json_mset.ts +26 -0
- package/pkg/commands/json_numincrby.test.ts +28 -0
- package/pkg/commands/json_numincrby.ts +14 -0
- package/pkg/commands/json_nummultby.test.ts +28 -0
- package/pkg/commands/json_nummultby.ts +14 -0
- package/pkg/commands/json_objkeys.test.ts +32 -0
- package/pkg/commands/json_objkeys.ts +14 -0
- package/pkg/commands/json_objlen.test.ts +26 -0
- package/pkg/commands/json_objlen.ts +14 -0
- package/pkg/commands/json_resp.test.ts +31 -0
- package/pkg/commands/json_resp.ts +11 -0
- package/pkg/commands/json_set.test.ts +48 -0
- package/pkg/commands/json_set.ts +34 -0
- package/pkg/commands/json_strappend.test.ts +34 -0
- package/pkg/commands/json_strappend.ts +14 -0
- package/pkg/commands/json_strlen.test.ts +27 -0
- package/pkg/commands/json_strlen.ts +14 -0
- package/pkg/commands/json_toggle.test.ts +26 -0
- package/pkg/commands/json_toggle.ts +11 -0
- package/pkg/commands/json_type.test.ts +29 -0
- package/pkg/commands/json_type.ts +11 -0
- package/pkg/commands/keys.test.ts +18 -0
- package/pkg/commands/keys.ts +11 -0
- package/pkg/commands/lindex.test.ts +33 -0
- package/pkg/commands/lindex.ts +11 -0
- package/pkg/commands/linsert.test.ts +24 -0
- package/pkg/commands/linsert.ts +10 -0
- package/pkg/commands/llen.test.ts +27 -0
- package/pkg/commands/llen.ts +11 -0
- package/pkg/commands/lmove.test.ts +48 -0
- package/pkg/commands/lmove.ts +19 -0
- package/pkg/commands/lmpop.test.ts +86 -0
- package/pkg/commands/lmpop.ts +19 -0
- package/pkg/commands/lpop.test.ts +40 -0
- package/pkg/commands/lpop.ts +14 -0
- package/pkg/commands/lpos.test.ts +56 -0
- package/pkg/commands/lpos.ts +25 -0
- package/pkg/commands/lpush.test.ts +18 -0
- package/pkg/commands/lpush.ts +11 -0
- package/pkg/commands/lpushx.test.ts +30 -0
- package/pkg/commands/lpushx.ts +11 -0
- package/pkg/commands/lrange.test.ts +21 -0
- package/pkg/commands/lrange.ts +11 -0
- package/pkg/commands/lrem.test.ts +19 -0
- package/pkg/commands/lrem.ts +10 -0
- package/pkg/commands/lset.test.ts +43 -0
- package/pkg/commands/lset.ts +8 -0
- package/pkg/commands/ltrim.test.ts +30 -0
- package/pkg/commands/ltrim.ts +8 -0
- package/pkg/commands/mget.test.ts +44 -0
- package/pkg/commands/mget.ts +11 -0
- package/pkg/commands/mod.ts +168 -0
- package/pkg/commands/mset.test.ts +24 -0
- package/pkg/commands/mset.ts +11 -0
- package/pkg/commands/msetnx.test.ts +46 -0
- package/pkg/commands/msetnx.ts +11 -0
- package/pkg/commands/persist.test.ts +22 -0
- package/pkg/commands/persist.ts +11 -0
- package/pkg/commands/pexpire.test.ts +24 -0
- package/pkg/commands/pexpire.ts +11 -0
- package/pkg/commands/pexpireat.test.ts +31 -0
- package/pkg/commands/pexpireat.ts +11 -0
- package/pkg/commands/pfadd.test.ts +80 -0
- package/pkg/commands/pfadd.ts +11 -0
- package/pkg/commands/pfcount.test.ts +55 -0
- package/pkg/commands/pfcount.ts +11 -0
- package/pkg/commands/pfmerge.test.ts +67 -0
- package/pkg/commands/pfmerge.ts +11 -0
- package/pkg/commands/ping.test.ts +19 -0
- package/pkg/commands/ping.ts +14 -0
- package/pkg/commands/psetex.test.ts +23 -0
- package/pkg/commands/psetex.ts +14 -0
- package/pkg/commands/pttl.test.ts +18 -0
- package/pkg/commands/pttl.ts +11 -0
- package/pkg/commands/publish.test.ts +12 -0
- package/pkg/commands/publish.ts +11 -0
- package/pkg/commands/randomkey.test.ts +16 -0
- package/pkg/commands/randomkey.ts +11 -0
- package/pkg/commands/rename.test.ts +19 -0
- package/pkg/commands/rename.ts +11 -0
- package/pkg/commands/renamenx.test.ts +33 -0
- package/pkg/commands/renamenx.ts +11 -0
- package/pkg/commands/rpop.test.ts +40 -0
- package/pkg/commands/rpop.ts +17 -0
- package/pkg/commands/rpush.test.ts +17 -0
- package/pkg/commands/rpush.ts +11 -0
- package/pkg/commands/rpushx.test.ts +30 -0
- package/pkg/commands/rpushx.ts +11 -0
- package/pkg/commands/sadd.test.ts +22 -0
- package/pkg/commands/sadd.ts +14 -0
- package/pkg/commands/scan.test.ts +91 -0
- package/pkg/commands/scan.ts +33 -0
- package/pkg/commands/scard.test.ts +16 -0
- package/pkg/commands/scard.ts +10 -0
- package/pkg/commands/script_exists.test.ts +34 -0
- package/pkg/commands/script_exists.ts +14 -0
- package/pkg/commands/script_flush.ts +21 -0
- package/pkg/commands/script_load.test.ts +11 -0
- package/pkg/commands/script_load.ts +11 -0
- package/pkg/commands/sdiff.test.ts +20 -0
- package/pkg/commands/sdiff.ts +10 -0
- package/pkg/commands/sdiffstore.test.ts +22 -0
- package/pkg/commands/sdiffstore.ts +13 -0
- package/pkg/commands/set.test.ts +168 -0
- package/pkg/commands/set.ts +51 -0
- package/pkg/commands/setbit.test.ts +17 -0
- package/pkg/commands/setbit.ts +14 -0
- package/pkg/commands/setex.test.ts +22 -0
- package/pkg/commands/setex.ts +11 -0
- package/pkg/commands/setnx.test.ts +27 -0
- package/pkg/commands/setnx.ts +11 -0
- package/pkg/commands/setrange.test.ts +25 -0
- package/pkg/commands/setrange.ts +14 -0
- package/pkg/commands/sinter.test.ts +37 -0
- package/pkg/commands/sinter.ts +10 -0
- package/pkg/commands/sinterstore.test.ts +22 -0
- package/pkg/commands/sinterstore.ts +13 -0
- package/pkg/commands/sismember.test.ts +31 -0
- package/pkg/commands/sismember.ts +10 -0
- package/pkg/commands/smembers.test.ts +22 -0
- package/pkg/commands/smembers.ts +11 -0
- package/pkg/commands/smismember.test.ts +22 -0
- package/pkg/commands/smismember.ts +16 -0
- package/pkg/commands/smove.test.ts +18 -0
- package/pkg/commands/smove.ts +13 -0
- package/pkg/commands/spop.test.ts +36 -0
- package/pkg/commands/spop.ts +17 -0
- package/pkg/commands/srandmember.test.ts +31 -0
- package/pkg/commands/srandmember.ts +17 -0
- package/pkg/commands/srem.test.ts +19 -0
- package/pkg/commands/srem.ts +10 -0
- package/pkg/commands/sscan.test.ts +48 -0
- package/pkg/commands/sscan.ts +30 -0
- package/pkg/commands/strlen.test.ts +17 -0
- package/pkg/commands/strlen.ts +11 -0
- package/pkg/commands/sunion.test.ts +22 -0
- package/pkg/commands/sunion.ts +11 -0
- package/pkg/commands/sunionstore.test.ts +30 -0
- package/pkg/commands/sunionstore.ts +14 -0
- package/pkg/commands/time.test.ts +12 -0
- package/pkg/commands/time.ts +10 -0
- package/pkg/commands/touch.test.ts +21 -0
- package/pkg/commands/touch.ts +11 -0
- package/pkg/commands/ttl.test.ts +17 -0
- package/pkg/commands/ttl.ts +11 -0
- package/pkg/commands/type.test.ts +72 -0
- package/pkg/commands/type.ts +12 -0
- package/pkg/commands/types.ts +150 -0
- package/pkg/commands/unlink.test.ts +22 -0
- package/pkg/commands/unlink.ts +11 -0
- package/pkg/commands/xack.test.ts +53 -0
- package/pkg/commands/xack.ts +15 -0
- package/pkg/commands/xadd.test.ts +128 -0
- package/pkg/commands/xadd.ts +64 -0
- package/pkg/commands/xautoclaim.test.ts +105 -0
- package/pkg/commands/xautoclaim.ts +30 -0
- package/pkg/commands/xclaim.test.ts +70 -0
- package/pkg/commands/xclaim.ts +55 -0
- package/pkg/commands/xdel.test.ts +50 -0
- package/pkg/commands/xdel.ts +15 -0
- package/pkg/commands/xgroup.test.ts +202 -0
- package/pkg/commands/xgroup.ts +100 -0
- package/pkg/commands/xinfo.test.ts +82 -0
- package/pkg/commands/xinfo.ts +27 -0
- package/pkg/commands/xlen.test.ts +29 -0
- package/pkg/commands/xlen.ts +11 -0
- package/pkg/commands/xpending.test.ts +94 -0
- package/pkg/commands/xpending.ts +43 -0
- package/pkg/commands/xrange.test.ts +69 -0
- package/pkg/commands/xrange.ts +48 -0
- package/pkg/commands/xread.test.ts +117 -0
- package/pkg/commands/xread.ts +51 -0
- package/pkg/commands/xreadgroup.test.ts +166 -0
- package/pkg/commands/xreadgroup.ts +66 -0
- package/pkg/commands/xrevrange.test.ts +48 -0
- package/pkg/commands/xrevrange.ts +47 -0
- package/pkg/commands/xtrim.test.ts +65 -0
- package/pkg/commands/xtrim.ts +24 -0
- package/pkg/commands/zadd.test.ts +242 -0
- package/pkg/commands/zadd.ts +53 -0
- package/pkg/commands/zcard.test.ts +16 -0
- package/pkg/commands/zcard.ts +11 -0
- package/pkg/commands/zcount.test.ts +16 -0
- package/pkg/commands/zcount.ts +13 -0
- package/pkg/commands/zdiffstore.test.ts +42 -0
- package/pkg/commands/zdiffstore.ts +14 -0
- package/pkg/commands/zincrby.test.ts +19 -0
- package/pkg/commands/zincrby.ts +13 -0
- package/pkg/commands/zinterstore.test.ts +297 -0
- package/pkg/commands/zinterstore.ts +51 -0
- package/pkg/commands/zlexcount.test.ts +23 -0
- package/pkg/commands/zlexcount.ts +10 -0
- package/pkg/commands/zmscore.test.ts +39 -0
- package/pkg/commands/zmscore.ts +15 -0
- package/pkg/commands/zpopmax.test.ts +46 -0
- package/pkg/commands/zpopmax.ts +17 -0
- package/pkg/commands/zpopmin.test.ts +50 -0
- package/pkg/commands/zpopmin.ts +17 -0
- package/pkg/commands/zrange.test.ts +188 -0
- package/pkg/commands/zrange.ts +68 -0
- package/pkg/commands/zrank.test.ts +23 -0
- package/pkg/commands/zrank.ts +14 -0
- package/pkg/commands/zrem.test.ts +21 -0
- package/pkg/commands/zrem.ts +10 -0
- package/pkg/commands/zremrangebylex.test.ts +24 -0
- package/pkg/commands/zremrangebylex.ts +10 -0
- package/pkg/commands/zremrangebyrank.test.ts +27 -0
- package/pkg/commands/zremrangebyrank.ts +13 -0
- package/pkg/commands/zremrangebyscore.test.ts +24 -0
- package/pkg/commands/zremrangebyscore.ts +10 -0
- package/pkg/commands/zrevrank.test.ts +23 -0
- package/pkg/commands/zrevrank.ts +14 -0
- package/pkg/commands/zscan.test.ts +48 -0
- package/pkg/commands/zscan.ts +30 -0
- package/pkg/commands/zscore.test.ts +18 -0
- package/pkg/commands/zscore.ts +14 -0
- package/pkg/commands/zunion.test.ts +251 -0
- package/pkg/commands/zunion.ts +54 -0
- package/pkg/commands/zunionstore.test.ts +274 -0
- package/pkg/commands/zunionstore.ts +51 -0
- package/pkg/error.ts +18 -0
- package/pkg/http.ts +349 -0
- package/pkg/index.ts +1 -0
- package/pkg/pipeline.test.ts +254 -0
- package/pkg/pipeline.ts +1401 -0
- package/pkg/read-your-writes.test.ts +115 -0
- package/pkg/redis.test.ts +250 -0
- package/pkg/redis.ts +1367 -0
- package/pkg/script.test.ts +58 -0
- package/pkg/script.ts +67 -0
- package/pkg/test-utils.test.ts +17 -0
- package/pkg/test-utils.ts +72 -0
- package/pkg/types.ts +35 -0
- package/pkg/util.ts +42 -0
- package/platforms/cloudflare.ts +144 -0
- package/platforms/fastly.ts +100 -0
- package/platforms/nodejs.ts +196 -0
- package/prettier.config.mjs +13 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +8 -0
- package/version.ts +1 -0
- package/chunk-JD7AT2OK.js +0 -1
- package/chunk-XCPX3L6C.mjs +0 -1
- package/cloudflare.d.mts +0 -50
- package/cloudflare.d.ts +0 -50
- package/cloudflare.js +0 -1
- package/cloudflare.mjs +0 -1
- package/fastly.d.mts +0 -43
- package/fastly.d.ts +0 -43
- package/fastly.js +0 -1
- package/fastly.mjs +0 -1
- package/nodejs.d.mts +0 -85
- package/nodejs.d.ts +0 -85
- package/nodejs.js +0 -1
- package/nodejs.mjs +0 -1
package/pkg/http.ts
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { UpstashError, UrlError } from "./error";
|
|
2
|
+
import type { Telemetry } from "./types";
|
|
3
|
+
|
|
4
|
+
type CacheSetting =
|
|
5
|
+
| "default"
|
|
6
|
+
| "force-cache"
|
|
7
|
+
| "no-cache"
|
|
8
|
+
| "no-store"
|
|
9
|
+
| "only-if-cached"
|
|
10
|
+
| "reload";
|
|
11
|
+
|
|
12
|
+
export type UpstashRequest = {
|
|
13
|
+
path?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Request body will be serialized to json
|
|
16
|
+
*/
|
|
17
|
+
body?: unknown;
|
|
18
|
+
|
|
19
|
+
upstashSyncToken?: string;
|
|
20
|
+
};
|
|
21
|
+
export type UpstashResponse<TResult> = { result?: TResult; error?: string };
|
|
22
|
+
|
|
23
|
+
export interface Requester {
|
|
24
|
+
/**
|
|
25
|
+
* When this flag is enabled, any subsequent commands issued by this client are guaranteed to observe the effects of all earlier writes submitted by the same client.
|
|
26
|
+
*/
|
|
27
|
+
readYourWrites?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This token is used to ensure that the client is in sync with the server. On each request, we send this token in the header, and the server will return a new token.
|
|
31
|
+
*/
|
|
32
|
+
upstashSyncToken?: string;
|
|
33
|
+
request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ResultError = {
|
|
37
|
+
result?: string | number | null | (string | number | null)[];
|
|
38
|
+
error?: string;
|
|
39
|
+
};
|
|
40
|
+
export type RetryConfig =
|
|
41
|
+
| false
|
|
42
|
+
| {
|
|
43
|
+
/**
|
|
44
|
+
* The number of retries to attempt before giving up.
|
|
45
|
+
*
|
|
46
|
+
* @default 5
|
|
47
|
+
*/
|
|
48
|
+
retries?: number;
|
|
49
|
+
/**
|
|
50
|
+
* A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
|
|
51
|
+
*
|
|
52
|
+
* @default
|
|
53
|
+
* ```ts
|
|
54
|
+
* Math.exp(retryCount) * 50
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
backoff?: (retryCount: number) => number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type Options = {
|
|
61
|
+
backend?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type RequesterConfig = {
|
|
65
|
+
/**
|
|
66
|
+
* Configure the retry behaviour in case of network errors
|
|
67
|
+
*/
|
|
68
|
+
retry?: RetryConfig;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
|
|
72
|
+
* valid json and will therefore cause errors when deserializing. This used to happen very
|
|
73
|
+
* frequently with non-utf8 data, such as emojis.
|
|
74
|
+
*
|
|
75
|
+
* By default we will therefore encode the data as base64 on the server, before sending it to the
|
|
76
|
+
* client. The client will then decode the base64 data and parse it as utf8.
|
|
77
|
+
*
|
|
78
|
+
* For very large entries, this can add a few milliseconds, so if you are sure that your data is
|
|
79
|
+
* valid utf8, you can disable this behaviour by setting this option to false.
|
|
80
|
+
*
|
|
81
|
+
* Here's what the response body looks like:
|
|
82
|
+
*
|
|
83
|
+
* ```json
|
|
84
|
+
* {
|
|
85
|
+
* result?: "base64-encoded",
|
|
86
|
+
* error?: string
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @default "base64"
|
|
91
|
+
*/
|
|
92
|
+
responseEncoding?: false | "base64";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Configure the cache behaviour
|
|
96
|
+
* @default "no-store"
|
|
97
|
+
*/
|
|
98
|
+
cache?: CacheSetting;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type HttpClientConfig = {
|
|
102
|
+
headers?: Record<string, string>;
|
|
103
|
+
baseUrl: string;
|
|
104
|
+
options?: Options;
|
|
105
|
+
retry?: RetryConfig;
|
|
106
|
+
agent?: any;
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
keepAlive?: boolean;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* When this flag is enabled, any subsequent commands issued by this client are guaranteed to observe the effects of all earlier writes submitted by the same client.
|
|
112
|
+
*/
|
|
113
|
+
readYourWrites?: boolean;
|
|
114
|
+
} & RequesterConfig;
|
|
115
|
+
|
|
116
|
+
export class HttpClient implements Requester {
|
|
117
|
+
public baseUrl: string;
|
|
118
|
+
public headers: Record<string, string>;
|
|
119
|
+
|
|
120
|
+
public readonly options: {
|
|
121
|
+
backend?: string;
|
|
122
|
+
agent: any;
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
responseEncoding?: false | "base64";
|
|
125
|
+
cache?: CacheSetting;
|
|
126
|
+
keepAlive: boolean;
|
|
127
|
+
};
|
|
128
|
+
public readYourWrites: boolean;
|
|
129
|
+
public upstashSyncToken = "";
|
|
130
|
+
|
|
131
|
+
public readonly retry: {
|
|
132
|
+
attempts: number;
|
|
133
|
+
backoff: (retryCount: number) => number;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
public constructor(config: HttpClientConfig) {
|
|
137
|
+
this.options = {
|
|
138
|
+
backend: config.options?.backend,
|
|
139
|
+
agent: config.agent,
|
|
140
|
+
responseEncoding: config.responseEncoding ?? "base64", // default to base64
|
|
141
|
+
cache: config.cache,
|
|
142
|
+
signal: config.signal,
|
|
143
|
+
keepAlive: config.keepAlive ?? true,
|
|
144
|
+
};
|
|
145
|
+
this.upstashSyncToken = "";
|
|
146
|
+
this.readYourWrites = config.readYourWrites ?? true;
|
|
147
|
+
|
|
148
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* regex to check if the baseUrl starts with http:// or https://
|
|
152
|
+
* - `^` asserts the position at the start of the string.
|
|
153
|
+
* - `[^\s/$.?#]` makes sure that the domain starts correctly;
|
|
154
|
+
* without white space, '/', '$', '.', '?' or '#'
|
|
155
|
+
* - `.` matches any character except new line
|
|
156
|
+
* - `[^\s]*` matches anything except white space
|
|
157
|
+
* - `$` asserts the position at the end of the string.
|
|
158
|
+
*/
|
|
159
|
+
const urlRegex = /^https?:\/\/[^\s#$./?].\S*$/;
|
|
160
|
+
if (!urlRegex.test(this.baseUrl)) {
|
|
161
|
+
throw new UrlError(this.baseUrl);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this.headers = {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
|
|
167
|
+
...config.headers,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (this.options.responseEncoding === "base64") {
|
|
171
|
+
this.headers["Upstash-Encoding"] = "base64";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.retry =
|
|
175
|
+
typeof config.retry === "boolean" && !config.retry
|
|
176
|
+
? {
|
|
177
|
+
attempts: 1,
|
|
178
|
+
backoff: () => 0,
|
|
179
|
+
}
|
|
180
|
+
: {
|
|
181
|
+
attempts: config.retry?.retries ?? 5,
|
|
182
|
+
backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public mergeTelemetry(telemetry: Telemetry): void {
|
|
187
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
|
|
188
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
|
|
189
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public async request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> {
|
|
193
|
+
const requestOptions: RequestInit & { backend?: string; agent?: any } = {
|
|
194
|
+
//@ts-expect-error this should throw due to bun regression
|
|
195
|
+
cache: this.options.cache,
|
|
196
|
+
method: "POST",
|
|
197
|
+
headers: this.headers,
|
|
198
|
+
body: JSON.stringify(req.body),
|
|
199
|
+
keepalive: this.options.keepAlive,
|
|
200
|
+
agent: this.options.agent,
|
|
201
|
+
signal: this.options.signal,
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Fastly specific
|
|
205
|
+
*/
|
|
206
|
+
backend: this.options.backend,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* We've recieved a new `upstash-sync-token` in the previous response. We use it in the next request to observe the effects of previous requests.
|
|
211
|
+
*/
|
|
212
|
+
if (this.readYourWrites) {
|
|
213
|
+
const newHeader = this.upstashSyncToken;
|
|
214
|
+
this.headers["upstash-sync-token"] = newHeader;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let res: Response | null = null;
|
|
218
|
+
let error: Error | null = null;
|
|
219
|
+
for (let i = 0; i <= this.retry.attempts; i++) {
|
|
220
|
+
try {
|
|
221
|
+
res = await fetch([this.baseUrl, ...(req.path ?? [])].join("/"), requestOptions);
|
|
222
|
+
break;
|
|
223
|
+
} catch (error_) {
|
|
224
|
+
if (this.options.signal?.aborted) {
|
|
225
|
+
const myBlob = new Blob([
|
|
226
|
+
JSON.stringify({ result: this.options.signal.reason ?? "Aborted" }),
|
|
227
|
+
]);
|
|
228
|
+
const myOptions = {
|
|
229
|
+
status: 200,
|
|
230
|
+
statusText: this.options.signal.reason ?? "Aborted",
|
|
231
|
+
};
|
|
232
|
+
res = new Response(myBlob, myOptions);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
error = error_ as Error;
|
|
236
|
+
await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!res) {
|
|
240
|
+
throw error ?? new Error("Exhausted all retries");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const body = (await res.json()) as UpstashResponse<string>;
|
|
244
|
+
if (!res.ok) {
|
|
245
|
+
throw new UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (this.readYourWrites) {
|
|
249
|
+
const headers = res.headers;
|
|
250
|
+
this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* We save the new `upstash-sync-token` in the response header to use it in the next request.
|
|
255
|
+
*/
|
|
256
|
+
if (this.readYourWrites) {
|
|
257
|
+
const headers = res.headers;
|
|
258
|
+
this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (this.options.responseEncoding === "base64") {
|
|
262
|
+
if (Array.isArray(body)) {
|
|
263
|
+
return body.map(({ result, error }) => ({
|
|
264
|
+
result: decode(result),
|
|
265
|
+
error,
|
|
266
|
+
})) as UpstashResponse<TResult>;
|
|
267
|
+
}
|
|
268
|
+
const result = decode(body.result) as any;
|
|
269
|
+
return { result, error: body.error };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return body as UpstashResponse<TResult>;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function base64decode(b64: string): string {
|
|
277
|
+
let dec = "";
|
|
278
|
+
try {
|
|
279
|
+
/**
|
|
280
|
+
* Using only atob() is not enough because it doesn't work with unicode characters
|
|
281
|
+
*/
|
|
282
|
+
const binString = atob(b64);
|
|
283
|
+
const size = binString.length;
|
|
284
|
+
const bytes = new Uint8Array(size);
|
|
285
|
+
for (let i = 0; i < size; i++) {
|
|
286
|
+
// eslint-disable-next-line unicorn/prefer-code-point
|
|
287
|
+
bytes[i] = binString.charCodeAt(i);
|
|
288
|
+
}
|
|
289
|
+
dec = new TextDecoder().decode(bytes);
|
|
290
|
+
} catch {
|
|
291
|
+
dec = b64;
|
|
292
|
+
}
|
|
293
|
+
return dec;
|
|
294
|
+
// try {
|
|
295
|
+
// return decodeURIComponent(dec);
|
|
296
|
+
// } catch {
|
|
297
|
+
// return dec;
|
|
298
|
+
// }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function decode(raw: ResultError["result"]): ResultError["result"] {
|
|
302
|
+
let result: any = undefined;
|
|
303
|
+
switch (typeof raw) {
|
|
304
|
+
case "undefined": {
|
|
305
|
+
return raw;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
case "number": {
|
|
309
|
+
result = raw;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "object": {
|
|
313
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
314
|
+
if (Array.isArray(raw)) {
|
|
315
|
+
result = raw.map((v) =>
|
|
316
|
+
typeof v === "string"
|
|
317
|
+
? base64decode(v)
|
|
318
|
+
: Array.isArray(v)
|
|
319
|
+
? v.map((element) => decode(element))
|
|
320
|
+
: v
|
|
321
|
+
);
|
|
322
|
+
} else {
|
|
323
|
+
// If it's not an array it must be null
|
|
324
|
+
// Apparently null is an object in javascript
|
|
325
|
+
result = null;
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
case "string": {
|
|
331
|
+
result = raw === "OK" ? "OK" : base64decode(raw);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
default: {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function merge(obj: Record<string, string>, key: string, value?: string): Record<string, string> {
|
|
344
|
+
if (!value) {
|
|
345
|
+
return obj;
|
|
346
|
+
}
|
|
347
|
+
obj[key] = obj[key] ? [obj[key], value].join(",") : value;
|
|
348
|
+
return obj;
|
|
349
|
+
}
|
package/pkg/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./error";
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Pipeline } from "./pipeline";
|
|
2
|
+
import { Redis } from "./redis";
|
|
3
|
+
import { keygen, newHttpClient, randomID } from "./test-utils";
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
6
|
+
import { ScriptLoadCommand } from "./commands/script_load";
|
|
7
|
+
|
|
8
|
+
const client = newHttpClient();
|
|
9
|
+
|
|
10
|
+
const { newKey, cleanup } = keygen();
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
describe("with destructuring", () => {
|
|
14
|
+
test("correctly binds this", async () => {
|
|
15
|
+
const { pipeline } = new Redis(client);
|
|
16
|
+
const p = pipeline();
|
|
17
|
+
|
|
18
|
+
const { echo, exec } = p;
|
|
19
|
+
echo("Hello");
|
|
20
|
+
|
|
21
|
+
const res = await exec();
|
|
22
|
+
expect(res).toEqual(["Hello"]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("with single command", () => {
|
|
27
|
+
test("works with multiple commands", async () => {
|
|
28
|
+
const p = new Pipeline({ client });
|
|
29
|
+
p.set(newKey(), randomID());
|
|
30
|
+
const res = await p.exec();
|
|
31
|
+
expect(res.length).toEqual(1);
|
|
32
|
+
expect(res[0]).toEqual("OK");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("when chaining in a for loop", () => {
|
|
37
|
+
test("works", async () => {
|
|
38
|
+
const key = newKey();
|
|
39
|
+
const res = await new Pipeline({ client }).set(key, randomID()).get(key).exec();
|
|
40
|
+
|
|
41
|
+
expect(res.length).toEqual(2);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("when chaining inline", () => {
|
|
46
|
+
test("works", async () => {
|
|
47
|
+
const key = newKey();
|
|
48
|
+
const p = new Pipeline({ client });
|
|
49
|
+
for (let i = 0; i < 10; i++) {
|
|
50
|
+
p.set(key, randomID());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const res = await p.exec();
|
|
54
|
+
expect(res.length).toEqual(10);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("when no commands were added", () => {
|
|
59
|
+
test("throws", async () => {
|
|
60
|
+
let hasThrown = false;
|
|
61
|
+
await new Pipeline({ client }).exec().catch(() => {
|
|
62
|
+
hasThrown = true;
|
|
63
|
+
});
|
|
64
|
+
expect(hasThrown).toBeTrue();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("when length called", () => {
|
|
69
|
+
test("before exec()", () => {
|
|
70
|
+
const key = newKey();
|
|
71
|
+
const p = new Pipeline({ client });
|
|
72
|
+
for (let i = 0; i < 10; i++) {
|
|
73
|
+
p.set(key, randomID());
|
|
74
|
+
}
|
|
75
|
+
expect(p.length()).toEqual(10);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("after exec()", async () => {
|
|
79
|
+
const key = newKey();
|
|
80
|
+
const p = new Pipeline({ client });
|
|
81
|
+
for (let i = 0; i < 10; i++) {
|
|
82
|
+
p.set(key, randomID());
|
|
83
|
+
}
|
|
84
|
+
await p.exec();
|
|
85
|
+
expect(p.length()).toEqual(10);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("when one command throws an error", () => {
|
|
90
|
+
test("throws", async () => {
|
|
91
|
+
const p = new Pipeline({ client }).set("key", "value").hget("key", "field");
|
|
92
|
+
let hasThrown = false;
|
|
93
|
+
await p.exec().catch(() => {
|
|
94
|
+
hasThrown = true;
|
|
95
|
+
});
|
|
96
|
+
expect(hasThrown).toBeTrue();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("transaction", () => {
|
|
101
|
+
test("works", async () => {
|
|
102
|
+
const key = newKey();
|
|
103
|
+
const value = randomID();
|
|
104
|
+
const tx = new Pipeline({ client, multiExec: true });
|
|
105
|
+
tx.set(key, value);
|
|
106
|
+
tx.get(key);
|
|
107
|
+
tx.del(key);
|
|
108
|
+
|
|
109
|
+
const [ok, storedvalue, deleted] = await tx.exec<["OK", string, number]>();
|
|
110
|
+
expect(ok).toEqual("OK");
|
|
111
|
+
expect(storedvalue).toEqual(value);
|
|
112
|
+
expect(deleted).toEqual(1);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("use all the things", () => {
|
|
116
|
+
test("works", async () => {
|
|
117
|
+
const p = new Pipeline({ client });
|
|
118
|
+
|
|
119
|
+
const persistentKey = newKey();
|
|
120
|
+
const persistentKey2 = newKey();
|
|
121
|
+
|
|
122
|
+
const scriptHash = await new ScriptLoadCommand(["return 1"]).exec(client);
|
|
123
|
+
|
|
124
|
+
p.append(newKey(), "hello")
|
|
125
|
+
.bitcount(newKey(), 0, 1)
|
|
126
|
+
.bitfield(newKey())
|
|
127
|
+
.set("u4", "#0", 15)
|
|
128
|
+
.get("u4", "#0")
|
|
129
|
+
.overflow("WRAP")
|
|
130
|
+
.incrby("u4", "#0", 10)
|
|
131
|
+
.exec()
|
|
132
|
+
.bitop("and", newKey(), newKey())
|
|
133
|
+
.bitpos(newKey(), 1, 0)
|
|
134
|
+
.dbsize()
|
|
135
|
+
.decr(newKey())
|
|
136
|
+
.decrby(newKey(), 1)
|
|
137
|
+
.del(newKey())
|
|
138
|
+
.echo("hello")
|
|
139
|
+
.eval("return ARGV[1]", [], ["Hello"])
|
|
140
|
+
.evalsha(scriptHash, [], ["Hello"])
|
|
141
|
+
.exists(newKey())
|
|
142
|
+
.expire(newKey(), 5)
|
|
143
|
+
.expireat(newKey(), Math.floor(Date.now() / 1000) + 60)
|
|
144
|
+
.flushall()
|
|
145
|
+
.flushdb()
|
|
146
|
+
.get(newKey())
|
|
147
|
+
.getbit(newKey(), 0)
|
|
148
|
+
.getdel(newKey())
|
|
149
|
+
.getset(newKey(), "hello")
|
|
150
|
+
.hdel(newKey(), "field")
|
|
151
|
+
.hexists(newKey(), "field")
|
|
152
|
+
.hget(newKey(), "field")
|
|
153
|
+
.hgetall(newKey())
|
|
154
|
+
.hincrby(newKey(), "field", 1)
|
|
155
|
+
.hincrbyfloat(newKey(), "field", 1.5)
|
|
156
|
+
.hkeys(newKey())
|
|
157
|
+
.hlen(newKey())
|
|
158
|
+
.hmget(newKey(), newKey())
|
|
159
|
+
.hmset(newKey(), { field: "field", value: "value" })
|
|
160
|
+
.hscan(newKey(), 0)
|
|
161
|
+
.hset(newKey(), { field: "value" })
|
|
162
|
+
.hsetnx(newKey(), "field", "value")
|
|
163
|
+
.hstrlen(newKey(), "field")
|
|
164
|
+
.hvals(newKey())
|
|
165
|
+
.incr(newKey())
|
|
166
|
+
.incrby(newKey(), 1)
|
|
167
|
+
.incrbyfloat(newKey(), 1.5)
|
|
168
|
+
.keys("*")
|
|
169
|
+
.lindex(newKey(), 0)
|
|
170
|
+
.linsert(newKey(), "before", "pivot", "value")
|
|
171
|
+
.llen(newKey())
|
|
172
|
+
.lmove(newKey(), newKey(), "left", "right")
|
|
173
|
+
.lpop(newKey())
|
|
174
|
+
.lpos(newKey(), "value")
|
|
175
|
+
.lpush(persistentKey, "element")
|
|
176
|
+
.lpushx(newKey(), "element1", "element2")
|
|
177
|
+
.lrange(newKey(), 0, 1)
|
|
178
|
+
.lrem(newKey(), 1, "value")
|
|
179
|
+
.lset(persistentKey, 0, "value")
|
|
180
|
+
.ltrim(newKey(), 0, 1)
|
|
181
|
+
.hrandfield(newKey())
|
|
182
|
+
.hrandfield(newKey(), 2)
|
|
183
|
+
.hrandfield(newKey(), 3, true)
|
|
184
|
+
.mget<[string, string]>(newKey(), newKey())
|
|
185
|
+
.mset({ key1: "value", key2: "value" })
|
|
186
|
+
.msetnx({ key3: "value", key4: "value" })
|
|
187
|
+
.persist(newKey())
|
|
188
|
+
.pexpire(newKey(), 1000)
|
|
189
|
+
.pexpireat(newKey(), Date.now() + 1000)
|
|
190
|
+
.ping()
|
|
191
|
+
.psetex(newKey(), 1, "value")
|
|
192
|
+
.pttl(newKey())
|
|
193
|
+
.publish("test", "hello")
|
|
194
|
+
.randomkey()
|
|
195
|
+
.rename(persistentKey, persistentKey2)
|
|
196
|
+
.renamenx(persistentKey2, newKey())
|
|
197
|
+
.rpop(newKey())
|
|
198
|
+
.rpush(newKey(), "element1", "element2")
|
|
199
|
+
.rpushx(newKey(), "element1", "element2")
|
|
200
|
+
.sadd(newKey(), "memeber1", "member2")
|
|
201
|
+
.scan(0)
|
|
202
|
+
.scard(newKey())
|
|
203
|
+
.sdiff(newKey())
|
|
204
|
+
.sdiffstore(newKey(), newKey())
|
|
205
|
+
.set(newKey(), "value")
|
|
206
|
+
.setbit(newKey(), 1, 1)
|
|
207
|
+
.setex(newKey(), 1, "value")
|
|
208
|
+
.setnx(newKey(), "value")
|
|
209
|
+
.setrange(newKey(), 1, "value")
|
|
210
|
+
.sinter(newKey(), newKey())
|
|
211
|
+
.sinterstore(newKey(), newKey())
|
|
212
|
+
.sismember(newKey(), "member")
|
|
213
|
+
.smembers(newKey())
|
|
214
|
+
.smove(newKey(), newKey(), "member")
|
|
215
|
+
.spop(newKey())
|
|
216
|
+
.srandmember(newKey())
|
|
217
|
+
.srem(newKey(), "member")
|
|
218
|
+
.sscan(newKey(), 0)
|
|
219
|
+
.strlen(newKey())
|
|
220
|
+
.sunion(newKey())
|
|
221
|
+
.sunionstore(newKey(), newKey())
|
|
222
|
+
.time()
|
|
223
|
+
.touch(newKey())
|
|
224
|
+
.ttl(newKey())
|
|
225
|
+
.type(newKey())
|
|
226
|
+
.unlink(newKey())
|
|
227
|
+
.zadd(newKey(), { score: 0, member: "member" })
|
|
228
|
+
.zcard(newKey())
|
|
229
|
+
.scriptExists(scriptHash)
|
|
230
|
+
.scriptFlush({ async: true })
|
|
231
|
+
.scriptLoad("return 1")
|
|
232
|
+
.zcount(newKey(), 0, 1)
|
|
233
|
+
.zincrby(newKey(), 1, "member")
|
|
234
|
+
.zinterstore(newKey(), 1, [newKey()])
|
|
235
|
+
.zlexcount(newKey(), "-", "+")
|
|
236
|
+
.zpopmax(newKey())
|
|
237
|
+
.zpopmin(newKey())
|
|
238
|
+
.zrange(newKey(), 0, 1)
|
|
239
|
+
.zrank(newKey(), "member")
|
|
240
|
+
.zrem(newKey(), "member")
|
|
241
|
+
.zremrangebylex(newKey(), "-", "+")
|
|
242
|
+
.zremrangebyrank(newKey(), 0, 1)
|
|
243
|
+
.zremrangebyscore(newKey(), 0, 1)
|
|
244
|
+
.zrevrank(newKey(), "member")
|
|
245
|
+
.zscan(newKey(), 0)
|
|
246
|
+
.zscore(newKey(), "member")
|
|
247
|
+
.zunionstore(newKey(), 1, [newKey()])
|
|
248
|
+
.zunion(1, [newKey()])
|
|
249
|
+
.json.set(newKey(), "$", { hello: "world" });
|
|
250
|
+
|
|
251
|
+
const res = await p.exec();
|
|
252
|
+
expect(res.length).toEqual(121);
|
|
253
|
+
});
|
|
254
|
+
});
|