Skip to content

Commit 370e0a0

Browse files
authored
Merge pull request #13 from keroxp/v0.3.0
V0.3.0
2 parents 897ab3b + 7e12bad commit 370e0a0

9 files changed

+42
-32
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
language: python
22

33
install:
4-
- curl -fsSL https://deno.land/x/install/install.sh | sh -s -- v0.3.3
4+
- curl -fsSL https://deno.land/x/install/install.sh | sh -s -- v0.7.0
55
- export PATH="$HOME/.deno/bin:$PATH"
66

77
services:
88
- redis
99

1010
script:
11-
- make test
11+
- deno run --allow-net test.ts

io.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { BufReader, BufWriter } from "https://deno.land/[email protected]/io/bufio.ts";
1+
import {
2+
BufReader,
3+
BufWriter,
4+
EOF
5+
} from "https://deno.land/[email protected]/io/bufio.ts";
26
import Buffer = Deno.Buffer;
37
import { ErrorReplyError } from "./errors.ts";
48

@@ -38,7 +42,7 @@ export function createRequest(
3842
export async function sendCommand(
3943
writer: BufWriter,
4044
reader: BufReader,
41-
command,
45+
command: string,
4246
...args
4347
): Promise<RedisRawReply> {
4448
const msg = createRequest(command, ...args);
@@ -48,8 +52,11 @@ export async function sendCommand(
4852
}
4953

5054
export async function readReply(reader: BufReader): Promise<RedisRawReply> {
51-
const [b] = await reader.peek(1);
52-
switch (b[0]) {
55+
const res = await reader.peek(1);
56+
if (res === EOF) {
57+
throw EOF;
58+
}
59+
switch (res[0]) {
5360
case IntegerReplyCode:
5461
return ["integer", await readIntegerReply(reader)];
5562
case SimpleStringCode:
@@ -118,7 +125,10 @@ export async function readArrayReply(reader: BufReader): Promise<any[]> {
118125
const argCount = parseInt(line.substr(1, line.length - 3));
119126
const result = [];
120127
for (let i = 0; i < argCount; i++) {
121-
const [res] = await reader.peek(1);
128+
const res = await reader.peek(1);
129+
if (res === EOF) {
130+
throw EOF;
131+
}
122132
switch (res[0]) {
123133
case SimpleStringCode:
124134
result.push(await readStatusReply(reader));

pipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BufReader, BufWriter } from "https://deno.land/std@v0.3.2/io/bufio.ts";
1+
import { BufReader, BufWriter } from "https://deno.land/std@v0.7.0/io/bufio.ts";
22
import { createRequest, readReply, RedisRawReply } from "./io.ts";
33
import { ErrorReplyError } from "./errors.ts";
44
import { create, Redis } from "./redis.ts";

pipeline_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { test } from "https://deno.land/std@v0.3.2/testing/mod.ts";
2-
import { assertEquals } from "https://deno.land/std@v0.3.2/testing/asserts.ts";
1+
import { test } from "https://deno.land/std@v0.7.0/testing/mod.ts";
2+
import { assertEquals } from "https://deno.land/std@v0.7.0/testing/asserts.ts";
33
import { connect } from "./redis.ts";
44

55
const addr = "127.0.0.1:6379";

pubsub.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { BufReader, BufWriter } from "https://deno.land/std@v0.3.2/io/bufio.ts";
2-
import { readArrayReply, sendCommand } from "./io.ts";
1+
import { BufReader, BufWriter } from "https://deno.land/std@v0.7.0/io/bufio.ts";
2+
import { createRequest, readArrayReply, sendCommand } from "./io.ts";
33

44
export type RedisSubscription = {
55
readonly isClosed: boolean;
66
receive(): AsyncIterableIterator<RedisPubSubMessage>;
7-
psubscribe(...patterns: string[]);
8-
subscribe(...channels: string[]);
9-
punsubscribe(...patterns: string[]);
10-
unsubscribe(...channels: string[]);
11-
close();
7+
psubscribe(...patterns: string[]): Promise<void>;
8+
subscribe(...channels: string[]): Promise<void>;
9+
punsubscribe(...patterns: string[]): Promise<void>;
10+
unsubscribe(...channels: string[]): Promise<void>;
11+
close(): Promise<void>;
1212
};
1313

1414
export type RedisPubSubMessage = {
@@ -89,7 +89,7 @@ export async function subscribe(
8989
writer: BufWriter,
9090
reader: BufReader,
9191
...channels: string[]
92-
) {
92+
): Promise<RedisSubscription> {
9393
const sub = new RedisSubscriptionImpl(writer, reader);
9494
await sub.subscribe(...channels);
9595
return sub;
@@ -99,7 +99,7 @@ export async function psubscribe(
9999
writer: BufWriter,
100100
reader: BufReader,
101101
...patterns: string[]
102-
) {
102+
): Promise<RedisSubscription> {
103103
const sub = new RedisSubscriptionImpl(writer, reader);
104104
await sub.psubscribe(...patterns);
105105
return sub;

pubsub_test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { test } from "https://deno.land/std@v0.3.2/testing/mod.ts";
2-
import { assertEquals } from "https://deno.land/std@v0.3.2/testing/asserts.ts";
1+
import { test } from "https://deno.land/std@v0.7.0/testing/mod.ts";
2+
import { assertEquals } from "https://deno.land/std@v0.7.0/testing/asserts.ts";
33
import { connect } from "./redis.ts";
44
import { RedisPubSubMessage } from "./pubsub.ts";
55

@@ -26,17 +26,17 @@ test(async function testSubscribe2() {
2626
const pub = await connect(addr);
2727
const sub = await redis.subscribe("subsc2");
2828
let message: RedisPubSubMessage;
29-
(async function() {
29+
const p = (async function() {
3030
const it = sub.receive();
3131
message = (await it.next()).value;
3232
})();
3333
await pub.publish("subsc2", "wayway");
34-
await sub.close();
35-
await wait(100);
34+
await p;
3635
assertEquals(message, {
3736
channel: "subsc2",
3837
message: "wayway"
3938
});
39+
await sub.close();
4040
const a = await redis.get("aaa");
4141
assertEquals(a, void 0);
4242
pub.close();
@@ -49,15 +49,14 @@ test(async function testPsubscribe() {
4949
const sub = await redis.psubscribe("ps*");
5050
let message1;
5151
let message2;
52-
(async function() {
53-
const it = sub.receive();
52+
const it = sub.receive();
53+
const p = (async function() {
5454
message1 = (await it.next()).value;
5555
message2 = (await it.next()).value;
5656
})();
5757
await pub.publish("psub", "wayway");
5858
await pub.publish("psubs", "heyhey");
59-
await sub.close();
60-
await wait(100);
59+
await p;
6160
assertEquals(message1, {
6261
pattern: "ps*",
6362
channel: "psub",
@@ -68,6 +67,7 @@ test(async function testPsubscribe() {
6867
channel: "psubs",
6968
message: "heyhey"
7069
});
70+
await sub.close();
7171
pub.close();
7272
redis.close();
7373
});

redis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type Reader = Deno.Reader;
22
type Writer = Deno.Writer;
33
type Closer = Deno.Closer;
4-
import { BufReader, BufWriter } from "https://deno.land/std@v0.3.2/io/bufio.ts";
4+
import { BufReader, BufWriter } from "https://deno.land/std@v0.7.0/io/bufio.ts";
55
import { ConnectionClosedError } from "./errors.ts";
66
import { psubscribe, RedisSubscription, subscribe } from "./pubsub.ts";
77
import { RedisRawReply, sendCommand } from "./io.ts";

redis_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { connect } from "./redis.ts";
2-
import { test } from "https://deno.land/std@v0.3.2/testing/mod.ts";
3-
import { assertEquals } from "https://deno.land/std@v0.3.2/testing/asserts.ts";
2+
import { test } from "https://deno.land/std@v0.7.0/testing/mod.ts";
3+
import { assertEquals } from "https://deno.land/std@v0.7.0/testing/asserts.ts";
44
// can be substituted with env variable
55
const addr = "127.0.0.1:6379";
66

test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import "./redis_test.ts";
22
import "./pubsub_test.ts";
33
import "./pipeline_test.ts";
4-
import "https://deno.land/std@v0.3.2/testing/main.ts";
4+
import "https://deno.land/std@v0.7.0/testing/main.ts";

0 commit comments

Comments
 (0)