-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from iuioiua/jsr
feat: JSR support
- Loading branch information
Showing
4 changed files
with
74 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
import { chunk } from "https://deno.land/[email protected]/collections/chunk.ts"; | ||
import { concat } from "https://deno.land/[email protected]/bytes/concat.ts"; | ||
import { writeAll } from "https://deno.land/[email protected]/io/write_all.ts"; | ||
import { readDelim } from "https://deno.land/[email protected]/io/read_delim.ts"; | ||
import { chunk } from "@std/collections/chunk"; | ||
import { concat } from "@std/bytes/concat"; | ||
import { readDelim } from "@std/io/read_delim"; | ||
import { writeAll } from "@std/io/write_all"; | ||
|
||
/** | ||
* A Redis client that can be used to send commands to a Redis server. | ||
* | ||
* ```ts | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
* | ||
* // Returns "OK" | ||
* await redisClient.sendCommand(["SET", "hello", "world"]); | ||
* | ||
* // Returns "world" | ||
* await redisClient.sendCommand(["GET", "hello"]); | ||
* ``` | ||
* | ||
* @module | ||
*/ | ||
|
||
/** Command sent to a Redis server. */ | ||
export type Command = (string | number | Uint8Array)[]; | ||
/** Reply received from a Redis server and triggered by a command. */ | ||
export type Reply = | ||
| string | ||
| number | ||
|
@@ -320,10 +341,28 @@ class AsyncQueue { | |
} | ||
} | ||
|
||
/** | ||
* A Redis client that can be used to send commands to a Redis server. | ||
* | ||
* @example | ||
* ```ts | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
* | ||
* // Returns "OK" | ||
* await redisClient.sendCommand(["SET", "hello", "world"]); | ||
* | ||
* // Returns "world" | ||
* await redisClient.sendCommand(["GET", "hello"]); | ||
* ``` | ||
*/ | ||
export class RedisClient { | ||
#conn: Deno.TcpConn | Deno.TlsConn; | ||
#queue: AsyncQueue; | ||
|
||
/** Constructs a new instance. */ | ||
constructor(conn: Deno.TcpConn | Deno.TlsConn) { | ||
this.#conn = conn; | ||
this.#queue = new AsyncQueue(); | ||
|
@@ -334,7 +373,7 @@ export class RedisClient { | |
* | ||
* @example | ||
* ```ts | ||
* import { RedisClient } from "https://deno.land/x/r2d2/mod.ts"; | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
|
@@ -357,7 +396,7 @@ export class RedisClient { | |
* | ||
* @example | ||
* ```ts | ||
* import { RedisClient } from "https://deno.land/x/r2d2/mod.ts"; | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
|
@@ -376,7 +415,7 @@ export class RedisClient { | |
* | ||
* @example | ||
* ```ts | ||
* import { RedisClient } from "https://deno.land/x/r2d2/mod.ts"; | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
|
@@ -398,7 +437,7 @@ export class RedisClient { | |
* | ||
* @example | ||
* ```ts | ||
* import { RedisClient } from "https://deno.land/x/r2d2/mod.ts"; | ||
* import { RedisClient } from "jsr:@iuioiua/r2d2"; | ||
* | ||
* const redisConn = await Deno.connect({ port: 6379 }); | ||
* const redisClient = new RedisClient(redisConn); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { | ||
assertEquals, | ||
assertRejects, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import { StringReader } from "https://deno.land/[email protected]/io/string_reader.ts"; | ||
import { readDelim } from "https://deno.land/[email protected]/io/read_delim.ts"; | ||
import { assertEquals, assertRejects } from "@std/assert"; | ||
import { StringReader } from "@std/io/string_reader"; | ||
import { readDelim } from "@std/io/read_delim"; | ||
import { type Command, readReply, RedisClient, type Reply } from "./mod.ts"; | ||
|
||
const encoder = new TextEncoder(); | ||
|