Skip to content

Commit

Permalink
BREAKING: improve commands API correctness (#132)
Browse files Browse the repository at this point in the history
## Adjustment
* migrate: add auth option
* object_idletime: renamed from object_ideltime
* object_freq: add BulkNil to return type
* restore: add absttl, idletime, and freq options
* scan: add type options
* sort: make limit option an object and make order optional
* incrbyfloat: return type BulkString
* mset: add support for Record and improve type safety
* msetnx, geoadd, hmset, and hset: ditto
* set: add keepttl option
* geopos: return type BulkString
* geo* : adjust options names
* bzop*: make timeout first argument to use rest with keys
* z*store: add support for Record to add multiple arguments
* eval: remove numkeys argument, get this value from keys.length
* acl* and memory*: adjust some commands to return BulkString instead of Status

## Addition
* zadd_incr: zadd with incr option that only accepts a single member score pair and returns Bulk
* replicaof_no_one: REPLICAOF NO ONE
* slaveof_no_one: SLAVEOF NO ONE
  • Loading branch information
tumile authored Aug 13, 2020
1 parent 551ffc2 commit a194441
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 885 deletions.
458 changes: 228 additions & 230 deletions command.ts

Large diffs are not rendered by default.

1,003 changes: 482 additions & 521 deletions redis.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/general_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ suite.test("execRawReply", async () => {
suite.test("eval", async () => {
const raw = await client.eval(
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
2,
["1", "2"],
["3", "4"],
);
Expand Down
34 changes: 19 additions & 15 deletions tests/geo_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ suite.test("geoadd", async () => {
await client.geoadd("Sicily", 15.087269, 37.502669, "Catania"),
1,
);
assertEquals(
await client.geoadd("Sicily", {
Palermo: [13.361389, 38.115556],
Catania: [15.087269, 37.502669],
}),
0,
);
assertEquals(
await client.geoadd(
"Sicily",
Expand All @@ -30,21 +37,19 @@ suite.test("geoadd", async () => {
});

suite.test("geohash", async () => {
await client.geoadd(
"Sicily",
[13.361389, 38.115556, "Palermo"],
[15.087269, 37.502669, "Catania"],
);
await client.geoadd("Sicily", {
Palermo: [13.361389, 38.115556],
Catania: [15.087269, 37.502669],
});
const resp = await client.geohash("Sicily", "Palermo", "Catania", "Enna");
assertEquals(resp, ["sqc8b49rny0", "sqdtr74hyu0", undefined]);
});

suite.test("geopos", async () => {
await client.geoadd(
"Sicily",
[13.361389, 38.115556, "Palermo"],
[15.087269, 37.502669, "Catania"],
);
await client.geoadd("Sicily", {
Palermo: [13.361389, 38.115556],
Catania: [15.087269, 37.502669],
});
const resp = await client.geopos("Sicily", "Palermo", "Catania", "Enna");
assertEquals(resp, [
["13.36138933897018433", "38.11555639549629859"],
Expand All @@ -54,11 +59,10 @@ suite.test("geopos", async () => {
});

suite.test("geodist", async () => {
await client.geoadd(
"Sicily",
[13.361389, 38.115556, "Palermo"],
[15.087269, 37.502669, "Catania"],
);
await client.geoadd("Sicily", {
Palermo: [13.361389, 38.115556],
Catania: [15.087269, 37.502669],
});
let resp = await client.geodist("Sicily", "Palermo", "Catania");
assertEquals(resp, "166274.1516");
resp = await client.geodist("Sicily", "Palermo", "Enna");
Expand Down
6 changes: 4 additions & 2 deletions tests/hash_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ suite.test("hmget", async () => {

suite.test("hmset", async () => {
assertEquals(await client.hmset("key", "f1", "1"), "OK");
assertEquals(await client.hmset("key", "f1", "1", "f2", "2"), "OK");
assertEquals(await client.hmset("key", { f1: "1", f2: "2" }), "OK");
assertEquals(await client.hmset("key", ["f4", "4"], ["f5", "5"]), "OK");
});

suite.test("hset", async () => {
assertEquals(await client.hset("key", "f1", "1"), 1);
assertEquals(await client.hset("key", "f2", "2", "f3", "3"), 2);
assertEquals(await client.hset("key", { f2: "2", f3: "3" }), 2);
assertEquals(await client.hset("key", ["f4", "4"], ["f5", "5"]), 2);
});

suite.test("hsetnx", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/key_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ suite.test("object encoding", async () => {

suite.test("object idletime", async () => {
await client.set("key", "baz");
const v = await client.object_ideltime("key");
const v = await client.object_idletime("key");
assertEquals(v, 0);
});

Expand Down
8 changes: 4 additions & 4 deletions tests/list_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ suite.afterAll(() => {

suite.test("blpoop", async () => {
await client.rpush("list", "1", "2");
assertEquals(await client.blpop("list", 2), ["list", "1"]);
assertEquals(await client.blpop(2, "list"), ["list", "1"]);
});

suite.test("blpoop timeout", async () => {
assertEquals(await client.blpop("list", 1), []);
assertEquals(await client.blpop(1, "list"), []);
});

suite.test("brpoop", async () => {
await client.rpush("list", "1", "2");
assertEquals(await client.brpop("list", 2), ["list", "2"]);
assertEquals(await client.brpop(2, "list"), ["list", "2"]);
});

suite.test("brpoop timeout", async () => {
assertEquals(await client.brpop("list", 1), []);
assertEquals(await client.brpop(1, "list"), []);
});

suite.test("brpoplpush", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ suite.test("error while pipeline", async () => {
const client = await newClient(opts);
const tx = client.pipeline();
tx.set("a", "a");
tx.eval("var", 1, "k", "v");
tx.eval("var", ["k"], ["v"]);
tx.get("a");
const resp = await tx.flush();
assertEquals(resp.length, 3);
Expand Down
Loading

0 comments on commit a194441

Please sign in to comment.