From 09979101e470f94804ed1063db4d7573ee0783ac Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 3 Feb 2025 18:44:23 +1100 Subject: [PATCH] refactor: minor cleanups and maintenance (#198) * refactor: minor cleanups and maintenance * version --- CONTRIBUTING.md | 7 +++++++ README.md | 13 +++---------- bench.ts | 12 +----------- deno.json | 16 ++++++++-------- mod.ts | 13 +++---------- test.ts | 2 -- 6 files changed, 22 insertions(+), 41 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0f52941 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +## Contributing Guidelines + +Before submitting a pull request, please run `deno task ok:dev`. This task +checks formatting, runs the linter and runs tests. + +> Note: Redis must be installed on your local machine. For installation +> instructions, see [here](https://redis.io/docs/getting-started/installation/). diff --git a/README.md b/README.md index 1d67244..f81c37c 100644 --- a/README.md +++ b/README.md @@ -29,17 +29,10 @@ assertEquals(reply2, "world"); - Written to be easily understood and debugged. - Encourages the use of actual Redis commands without intermediate abstractions. -## Usage +## Resources -See [documentation](https://jsr.io/@iuioiua/r2d2/doc) for usage instructions. - -## Contributing - -Before submitting a pull request, please run `deno task ok:dev`. This task -checks formatting, runs the linter and runs tests. - -> Note: Redis must be installed on your local machine. For installation -> instructions, see [here](https://redis.io/docs/getting-started/installation/). +- [Documentation](https://jsr.io/@iuioiua/r2d2/doc) +- [Contributing guidelines](./CONTRIBUTING.md) ## Size comparison diff --git a/bench.ts b/bench.ts index 163367e..be57350 100644 --- a/bench.ts +++ b/bench.ts @@ -86,20 +86,10 @@ Deno.bench({ await nodeRedisClient.hSet("hash", { a: "foo", b: "bar" }); await nodeRedisClient.hGetAll("hash"); - /** Auto-pipelining */ + // Auto-pipelining await nodeRedisClient.incr("X"); await nodeRedisClient.incr("X"); await nodeRedisClient.incr("X"); await nodeRedisClient.incr("X"); }, }); - -addEventListener("beforeunload", async () => { - ioRedis.disconnect(); - await nodeRedisClient.disconnect(); -}); - -addEventListener("unload", () => { - denoRedisConn.close(); - redisConn.close(); -}); diff --git a/deno.json b/deno.json index 443953f..7e250dc 100644 --- a/deno.json +++ b/deno.json @@ -1,15 +1,15 @@ { "name": "@iuioiua/r2d2", - "version": "2.1.2", + "version": "2.1.3", "exports": "./mod.ts", "imports": { - "@db/redis": "jsr:@db/redis@^0.37.0", - "@std/assert": "jsr:@std/assert@^1.0.9", - "@std/async": "jsr:@std/async@^1.0.9", - "@std/bytes": "jsr:@std/bytes@^1.0.4", - "@std/collections": "jsr:@std/collections@^1.0.9", - "@std/io": "jsr:@std/io@^0.225.0", - "ioredis": "npm:ioredis@^5.4.1", + "@db/redis": "jsr:@db/redis@^0.37.1", + "@std/assert": "jsr:@std/assert@^1.0.11", + "@std/async": "jsr:@std/async@^1.0.10", + "@std/bytes": "jsr:@std/bytes@^1.0.5", + "@std/collections": "jsr:@std/collections@^1.0.10", + "@std/io": "jsr:@std/io@^0.225.2", + "ioredis": "npm:ioredis@^5.4.2", "redis": "npm:redis@^4.7.0" }, "tasks": { diff --git a/mod.ts b/mod.ts index 4875c22..ddb2074 100644 --- a/mod.ts +++ b/mod.ts @@ -84,13 +84,6 @@ function createRequest(command: Command): Uint8Array { return concat(lines); } -async function writeCommand( - writer: Writer, - command: Command, -): Promise { - await writeAll(writer, createRequest(command)); -} - async function* readLines(reader: Reader): AsyncIterableIterator { const buffer = new Uint8Array(1024); let chunks = new Uint8Array(); @@ -142,7 +135,7 @@ async function readReply( case BIG_NUMBER_PREFIX: return BigInt(line); case BLOB_ERROR_PREFIX: { - /** Skip to reading the next line, which is a string */ + // Skip to reading the next line, which is a string const { value } = await iterator.next(); return Promise.reject(decoder.decode(value)); } @@ -411,7 +404,7 @@ export class RedisClient { */ sendCommand(command: Command, raw = false): Promise { return this.#enqueue(async () => { - await writeCommand(this.#conn, command); + await writeAll(this.#conn, createRequest(command)); return readReply(this.#lines, raw); }); } @@ -436,7 +429,7 @@ export class RedisClient { * ``` */ writeCommand(command: Command): Promise { - return this.#enqueue(() => writeCommand(this.#conn, command)); + return this.#enqueue(() => writeAll(this.#conn, createRequest(command))); } /** diff --git a/test.ts b/test.ts index eaf8014..275837f 100644 --- a/test.ts +++ b/test.ts @@ -216,5 +216,3 @@ Deno.test("RedisClient.sendCommand() - no reply", async () => { "No reply received", ); }); - -addEventListener("unload", () => redisConn.close());