Skip to content

Commit

Permalink
feat: implement web streams based Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a committed Oct 24, 2023
1 parent d235d71 commit d8c2934
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Raw,
RedisValue,
SimpleString,
} from "./protocol/mod.ts";
} from "./protocol/shared/types.ts";
import type { RedisPipeline } from "./pipeline.ts";
import type { RedisSubscription } from "./pubsub.ts";
import type {
Expand Down
10 changes: 7 additions & 3 deletions connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { readReply, sendCommand, sendCommands } from "./protocol/mod.ts";
import type { RedisReply, RedisValue } from "./protocol/mod.ts";
import type { Command } from "./protocol/command.ts";
import {
readReply,
sendCommand,
sendCommands,
} from "./protocol/deno_streams/mod.ts";
import type { RedisReply, RedisValue } from "./protocol/shared/types.ts";
import type { Command } from "./protocol/deno_streams/command.ts";
import type { Backoff } from "./backoff.ts";
import { exponentialBackoff } from "./backoff.ts";
import { ErrorReplyError, isRetriableError } from "./errors.ts";
Expand Down
2 changes: 1 addition & 1 deletion executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Connection, SendCommandOptions } from "./connection.ts";
import type { RedisReply, RedisValue } from "./protocol/mod.ts";
import type { RedisReply, RedisValue } from "./protocol/shared/types.ts";

export interface CommandExecutor {
readonly connection: Connection;
Expand Down
2 changes: 1 addition & 1 deletion experimental/cluster/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { RedisConnectOptions } from "../../redis.ts";
import type { CommandExecutor } from "../../executor.ts";
import type { Connection, SendCommandOptions } from "../../connection.ts";
import type { Redis } from "../../redis.ts";
import type { RedisReply, RedisValue } from "../../protocol/mod.ts";
import type { RedisReply, RedisValue } from "../../protocol/shared/types.ts";
import { ErrorReplyError } from "../../errors.ts";
import { delay } from "../../vendor/https/deno.land/std/async/delay.ts";
import calculateSlot from "../../vendor/https/esm.sh/cluster-key-slot/lib/index.js";
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by tools/make_mod.ts. Don't edit.
export { okReply } from "./protocol/mod.ts";
export { okReply } from "./protocol/shared/types.ts";
export { connect, create, createLazyClient, parseURL } from "./redis.ts";
export {
ConnectionClosedError,
Expand Down Expand Up @@ -72,7 +72,7 @@ export type {
RedisReply,
RedisValue,
SimpleString,
} from "./protocol/mod.ts";
} from "./protocol/shared/types.ts";
export type { RedisPubSubMessage, RedisSubscription } from "./pubsub.ts";
export type { Redis, RedisConnectOptions } from "./redis.ts";
export type {
Expand Down
7 changes: 6 additions & 1 deletion pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { Connection, SendCommandOptions } from "./connection.ts";
import { kEmptyRedisArgs } from "./connection.ts";
import { CommandExecutor } from "./executor.ts";
import { okReply, RawOrError, RedisReply, RedisValue } from "./protocol/mod.ts";
import {
okReply,
RawOrError,
RedisReply,
RedisValue,
} from "./protocol/shared/types.ts";
import { create, Redis } from "./redis.ts";
import { kUnstablePipeline } from "./internal/symbols.ts";
import {
Expand Down
10 changes: 5 additions & 5 deletions protocol/command.ts → protocol/deno_streams/command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BufReader } from "../vendor/https/deno.land/std/io/buf_reader.ts";
import { BufWriter } from "../vendor/https/deno.land/std/io/buf_writer.ts";
import { BufReader } from "../../vendor/https/deno.land/std/io/buf_reader.ts";
import { BufWriter } from "../../vendor/https/deno.land/std/io/buf_writer.ts";
import { readReply } from "./reply.ts";
import { ErrorReplyError } from "../errors.ts";
import { encoder } from "./_util.ts";
import type { RedisReply, RedisValue } from "./types.ts";
import { ErrorReplyError } from "../../errors.ts";
import { encoder } from "../../internal/encoding.ts";
import type { RedisReply, RedisValue } from "../shared/types.ts";

const CRLF = encoder.encode("\r\n");
const ArrayCode = encoder.encode("*");
Expand Down
3 changes: 3 additions & 0 deletions protocol/deno_streams/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { readArrayReply, readReply } from "./reply.ts";

export { sendCommand, sendCommands } from "./command.ts";
10 changes: 4 additions & 6 deletions protocol/reply.ts → protocol/deno_streams/reply.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BufReader } from "../vendor/https/deno.land/std/io/buf_reader.ts";
import type * as types from "./types.ts";
import { EOFError, ErrorReplyError, InvalidStateError } from "../errors.ts";
import { decoder } from "./_util.ts";
import { BufReader } from "../../vendor/https/deno.land/std/io/buf_reader.ts";
import type * as types from "../shared/types.ts";
import { EOFError, ErrorReplyError, InvalidStateError } from "../../errors.ts";
import { decoder } from "../../internal/encoding.ts";

const IntegerReplyCode = ":".charCodeAt(0);
const BulkReplyCode = "$".charCodeAt(0);
Expand Down Expand Up @@ -113,8 +113,6 @@ export async function readArrayReply(
return array;
}

export const okReply = "OK";

function tryParseErrorReply(line: Uint8Array): never {
const code = line[0];
if (code === ErrorReplyCode) {
Expand Down
17 changes: 0 additions & 17 deletions protocol/mod.ts

This file was deleted.

4 changes: 3 additions & 1 deletion protocol/types.ts → protocol/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorReplyError } from "../errors.ts";
import { ErrorReplyError } from "../../errors.ts";

/**
* @see https://redis.io/topics/protocol
Expand Down Expand Up @@ -46,3 +46,5 @@ export type ConditionalArray = Raw[];
export type RedisReply = Raw | ConditionalArray;

export type RawOrError = Raw | ErrorReplyError;

export const okReply = "OK";
4 changes: 2 additions & 2 deletions pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CommandExecutor } from "./executor.ts";
import { EOFError, InvalidStateError } from "./errors.ts";
import type { Binary } from "./protocol/mod.ts";
import { decoder } from "./protocol/_util.ts";
import type { Binary } from "./protocol/shared/types.ts";
import { decoder } from "./internal/encoding.ts";
import { kUnstableReadReply } from "./internal/symbols.ts";

type DefaultMessageType = string;
Expand Down
2 changes: 1 addition & 1 deletion redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import type {
RedisReply,
RedisValue,
SimpleString,
} from "./protocol/mod.ts";
} from "./protocol/shared/types.ts";
import { createRedisPipeline } from "./pipeline.ts";
import { psubscribe, subscribe } from "./pubsub.ts";
import {
Expand Down
6 changes: 5 additions & 1 deletion stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ConditionalArray, Raw, RedisValue } from "./protocol/mod.ts";
import type {
ConditionalArray,
Raw,
RedisValue,
} from "./protocol/shared/types.ts";

export interface XId {
unixMs: number;
Expand Down
7 changes: 4 additions & 3 deletions tools/make_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ function collectSourceFilesInRootDir(): Array<string> {
}).map((f) => f.name);
}

const files = [...collectSourceFilesInRootDir(), "protocol/mod.ts"].sort();
const files = [...collectSourceFilesInRootDir(), "protocol/shared/types.ts"]
.sort();
let content = `// Generated by tools/make_mod.ts. Don't edit.\n`;

// Expose public variables from protocol/mod.ts
// Expose public variables from protocol/shared/types.ts
{
const fileName = "protocol/mod.ts";
const fileName = "protocol/shared/types.ts";
const variables = (await doc(fileName)).filter((node) => {
return node.kind === "variable";
}).map((node) => node.name);
Expand Down

0 comments on commit d8c2934

Please sign in to comment.