Skip to content

Commit

Permalink
refactor: minor cleanups and maintenance (#198)
Browse files Browse the repository at this point in the history
* refactor: minor cleanups and maintenance

* version
  • Loading branch information
iuioiua authored Feb 3, 2025
1 parent 9cff12a commit 0997910
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 41 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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/).
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 1 addition & 11 deletions bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
16 changes: 8 additions & 8 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 3 additions & 10 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ function createRequest(command: Command): Uint8Array {
return concat(lines);
}

async function writeCommand(
writer: Writer,
command: Command,
): Promise<void> {
await writeAll(writer, createRequest(command));
}

async function* readLines(reader: Reader): AsyncIterableIterator<Uint8Array> {
const buffer = new Uint8Array(1024);
let chunks = new Uint8Array();
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -411,7 +404,7 @@ export class RedisClient {
*/
sendCommand(command: Command, raw = false): Promise<Reply> {
return this.#enqueue(async () => {
await writeCommand(this.#conn, command);
await writeAll(this.#conn, createRequest(command));
return readReply(this.#lines, raw);
});
}
Expand All @@ -436,7 +429,7 @@ export class RedisClient {
* ```
*/
writeCommand(command: Command): Promise<void> {
return this.#enqueue(() => writeCommand(this.#conn, command));
return this.#enqueue(() => writeAll(this.#conn, createRequest(command)));
}

/**
Expand Down
2 changes: 0 additions & 2 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,3 @@ Deno.test("RedisClient.sendCommand() - no reply", async () => {
"No reply received",
);
});

addEventListener("unload", () => redisConn.close());

0 comments on commit 0997910

Please sign in to comment.