From 3a96c94d2794d0008a5f68360ea5f25e88794c24 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 09:38:29 +0200 Subject: [PATCH 1/7] feat: add rev to zrange command --- pkg/commands/zrange.test.ts | 24 ++++++++++++++++++++++++ pkg/commands/zrange.ts | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/commands/zrange.test.ts b/pkg/commands/zrange.test.ts index ca025ca3..7c827032 100644 --- a/pkg/commands/zrange.test.ts +++ b/pkg/commands/zrange.test.ts @@ -132,3 +132,27 @@ Deno.test("bylex", async (t) => { assertEquals(res3![1], "b"); }); }); + +Deno.test("rev", async (t) => { + await t.step("returns the set in reverse order", async () => { + const key = newKey(); + const score1 = 2; + const member1 = randomID(); + + const score2 = 5; + const member2 = randomID(); + + await new ZAddCommand([ + key, + { score: score1, member: member1 }, + { score: score2, member: member2 }, + ]).exec(client); + + const res = await new ZRangeCommand([key, 1, 3, { rev: true }]).exec( + client, + ); + assertEquals(res.length, 2); + assertEquals(res![0], member1); + assertEquals(res![1], score1); + }); +}); \ No newline at end of file diff --git a/pkg/commands/zrange.ts b/pkg/commands/zrange.ts index fe2c0fba..e62655c6 100644 --- a/pkg/commands/zrange.ts +++ b/pkg/commands/zrange.ts @@ -6,7 +6,7 @@ export type ZRangeCommandOptions = | { byScore: true; byLex?: never } | { byScore?: never; byLex: true } | { byScore?: never; byLex?: never } - ); + ) & { rev?: boolean } /** * @see https://redis.io/commands/zrange @@ -55,6 +55,9 @@ export class ZRangeCommand extends Command< if (opts?.byLex) { command.push("bylex"); } + if (opts?.rev) { + command.push("rev") + } if (opts?.withScores) { command.push("withscores"); } From 012ffa3b0f38f87edf85a778e9f6ce89587e543b Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 09:40:59 +0200 Subject: [PATCH 2/7] style: fmt --- pkg/commands/zrange.test.ts | 2 +- pkg/commands/zrange.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/commands/zrange.test.ts b/pkg/commands/zrange.test.ts index 7c827032..16a52cbd 100644 --- a/pkg/commands/zrange.test.ts +++ b/pkg/commands/zrange.test.ts @@ -155,4 +155,4 @@ Deno.test("rev", async (t) => { assertEquals(res![0], member1); assertEquals(res![1], score1); }); -}); \ No newline at end of file +}); diff --git a/pkg/commands/zrange.ts b/pkg/commands/zrange.ts index e62655c6..c6e00b22 100644 --- a/pkg/commands/zrange.ts +++ b/pkg/commands/zrange.ts @@ -6,7 +6,8 @@ export type ZRangeCommandOptions = | { byScore: true; byLex?: never } | { byScore?: never; byLex: true } | { byScore?: never; byLex?: never } - ) & { rev?: boolean } + ) + & { rev?: boolean }; /** * @see https://redis.io/commands/zrange @@ -56,7 +57,7 @@ export class ZRangeCommand extends Command< command.push("bylex"); } if (opts?.rev) { - command.push("rev") + command.push("rev"); } if (opts?.withScores) { command.push("withscores"); From a673a1c5614f005a6f25e50e33966c423da9d3a0 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 09:52:38 +0200 Subject: [PATCH 3/7] test: fix rev --- pkg/commands/zrange.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/commands/zrange.test.ts b/pkg/commands/zrange.test.ts index 16a52cbd..f1748210 100644 --- a/pkg/commands/zrange.test.ts +++ b/pkg/commands/zrange.test.ts @@ -148,11 +148,12 @@ Deno.test("rev", async (t) => { { score: score2, member: member2 }, ]).exec(client); - const res = await new ZRangeCommand([key, 1, 3, { rev: true }]).exec( + const res = await new ZRangeCommand([key, 0, 7, { rev: true }]).exec( client, ); + console.log({ res }); assertEquals(res.length, 2); - assertEquals(res![0], member1); - assertEquals(res![1], score1); + assertEquals(res![0], member2); + assertEquals(res![1], member1); }); }); From 357c6be51dce079d45cd8cb9aca0648f29ea4bbf Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 10:10:01 +0200 Subject: [PATCH 4/7] feat: add limit to zrange --- pkg/commands/zrange.test.ts | 20 +++++++++++++++++++- pkg/commands/zrange.ts | 16 +++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/commands/zrange.test.ts b/pkg/commands/zrange.test.ts index f1748210..d961de6f 100644 --- a/pkg/commands/zrange.test.ts +++ b/pkg/commands/zrange.test.ts @@ -151,9 +151,27 @@ Deno.test("rev", async (t) => { const res = await new ZRangeCommand([key, 0, 7, { rev: true }]).exec( client, ); - console.log({ res }); assertEquals(res.length, 2); assertEquals(res![0], member2); assertEquals(res![1], member1); }); }); + +Deno.test("limit", async (t) => { + await t.step("returns only the first 2", async () => { + const key = newKey(); + for (let i = 0; i < 10; i++) { + await new ZAddCommand([ + key, + { score: i, member: randomID() }, + ]).exec(client); + } + + const res = await new ZRangeCommand([key, 0, 7, { offset: 0, count: 2 }]) + .exec( + client, + ); + console.log({ res }); + assertEquals(res.length, 2); + }); +}); diff --git a/pkg/commands/zrange.ts b/pkg/commands/zrange.ts index c6e00b22..7edfcdb1 100644 --- a/pkg/commands/zrange.ts +++ b/pkg/commands/zrange.ts @@ -1,14 +1,19 @@ import { Command, CommandOptions } from "./command.ts"; export type ZRangeCommandOptions = - & { withScores?: boolean } + & { + withScores?: boolean; + rev?: boolean; + } & ( | { byScore: true; byLex?: never } | { byScore?: never; byLex: true } | { byScore?: never; byLex?: never } ) - & { rev?: boolean }; - + & ( + | { offset: number; count: number } + | { offset?: never; count?: never } + ); /** * @see https://redis.io/commands/zrange */ @@ -59,6 +64,11 @@ export class ZRangeCommand extends Command< if (opts?.rev) { command.push("rev"); } + if ( + typeof opts?.count !== "undefined" && typeof opts?.offset !== "undefined" + ) { + command.push("limit", opts.offset, opts.count); + } if (opts?.withScores) { command.push("withscores"); } From 2abcaf02b36b749dd1c1bdc29b165ad44ab561c8 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 10:28:05 +0200 Subject: [PATCH 5/7] ci: don't add account id on local --- .github/workflows/tests.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2d85a466..fcfb330b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -430,9 +430,9 @@ jobs: pnpm add -g wrangler working-directory: examples/cloudflare-workers - - name: Add account ID - run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml - working-directory: examples/cloudflare-workers + # - name: Add account ID + # run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml + # working-directory: examples/cloudflare-workers - name: Start example run: wrangler dev & sleep 5 @@ -440,8 +440,6 @@ jobs: env: CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} - # - run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8787)" != "200" ]]; do sleep 1; done - # timeout-minutes: 2 - name: Test run: deno test -A ./test.ts From 87b48e8bb87c9daf89a65bf578215a3f5e724a72 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 10:33:46 +0200 Subject: [PATCH 6/7] ci: don't add account id on local --- .github/workflows/tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fcfb330b..0c8f7db8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -782,7 +782,8 @@ jobs: - nextjs-edge-local - cloudflare-workers-with-wrangler-1-local - cloudflare-workers-with-typescript-local - - cloudflare-workers-local + # temporarily skip this, because cloudflare api has issues + # - cloudflare-workers-local name: Release runs-on: ubuntu-latest From 5eeec109c767a30b37e7c101caaccbdb918bd6a0 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 23 Jun 2022 10:36:24 +0200 Subject: [PATCH 7/7] ci: enable cloudflare --- .github/workflows/tests.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0c8f7db8..fcfb330b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -782,8 +782,7 @@ jobs: - nextjs-edge-local - cloudflare-workers-with-wrangler-1-local - cloudflare-workers-with-typescript-local - # temporarily skip this, because cloudflare api has issues - # - cloudflare-workers-local + - cloudflare-workers-local name: Release runs-on: ubuntu-latest