From 1413a69a6b75253b606ffd211f7f119ec5337894 Mon Sep 17 00:00:00 2001 From: leibale Date: Thu, 9 Sep 2021 16:58:31 -0400 Subject: [PATCH] add cluster.duplicate, add some tests --- lib/client.ts | 2 +- lib/cluster.ts | 4 +++ lib/commands/GEOPOS.spec.ts | 50 +++++++++++++++++++++++++---- lib/commands/GEOSEARCHSTORE.spec.ts | 9 +++++- lib/commands/PUBSUB_NUMSUB.spec.ts | 2 +- 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/lib/client.ts b/lib/client.ts index ed06317c14..139ec647fc 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -184,7 +184,7 @@ export default class RedisClient this.#socket.write(encodedCommands) + encodedCommands => this.#socket.write(encodedCommands) ); } diff --git a/lib/cluster.ts b/lib/cluster.ts index 2c1b23465e..3eeaed5009 100644 --- a/lib/cluster.ts +++ b/lib/cluster.ts @@ -91,6 +91,10 @@ export default class RedisCluster { + return new (Object.getPrototypeOf(this).constructor)(this.#options); + } + async connect(): Promise { return this.#slots.connect(); } diff --git a/lib/commands/GEOPOS.spec.ts b/lib/commands/GEOPOS.spec.ts index 98cfa6aa2d..e15abeff51 100644 --- a/lib/commands/GEOPOS.spec.ts +++ b/lib/commands/GEOPOS.spec.ts @@ -1,6 +1,6 @@ import { strict as assert } from 'assert'; import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; -import { transformArguments } from './GEOPOS'; +import { transformArguments, transformReply } from './GEOPOS'; describe('GEOPOS', () => { describe('transformArguments', () => { @@ -19,11 +19,49 @@ describe('GEOPOS', () => { }); }); - itWithClient(TestRedisServers.OPEN, 'client.geoPos', async client => { - assert.deepEqual( - await client.geoPos('key', 'member'), - [null] - ); + describe('transformReply', () => { + it('null', () => { + assert.deepEqual( + transformReply([null]), + [null] + ); + }); + + it('with member', () => { + assert.deepEqual( + transformReply([['1', '2']]), + [{ + longitude: '1', + latitude: '2' + }] + ); + }); + }); + + describe('client.geoPos', () => { + itWithClient(TestRedisServers.OPEN, 'null', async client => { + assert.deepEqual( + await client.geoPos('key', 'member'), + [null] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'with member', async client => { + const coordinates = { + longitude: '-122.06429868936538696', + latitude: '37.37749628831998194' + }; + + await client.geoAdd('key', { + member: 'member', + ...coordinates + }); + + assert.deepEqual( + await client.geoPos('key', 'member'), + [coordinates] + ); + }); }); itWithCluster(TestRedisClusters.OPEN, 'cluster.geoPos', async cluster => { diff --git a/lib/commands/GEOSEARCHSTORE.spec.ts b/lib/commands/GEOSEARCHSTORE.spec.ts index 1983537077..ad33c62b78 100644 --- a/lib/commands/GEOSEARCHSTORE.spec.ts +++ b/lib/commands/GEOSEARCHSTORE.spec.ts @@ -1,6 +1,6 @@ import { strict as assert } from 'assert'; import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster, describeHandleMinimumRedisVersion } from '../test-utils'; -import { transformArguments } from './GEOSEARCHSTORE'; +import { transformArguments, transformReply } from './GEOSEARCHSTORE'; describe('GEOSEARCHSTORE', () => { describeHandleMinimumRedisVersion([6, 2]); @@ -40,6 +40,13 @@ describe('GEOSEARCHSTORE', () => { }); }); + it('transformReply with empty array (https://github.com/redis/redis/issues/9261)', () => { + assert.throws( + () => (transformReply as any)([]), + TypeError + ); + }); + itWithClient(TestRedisServers.OPEN, 'client.geoSearchStore', async client => { await client.geoAdd('source', { longitude: 1, diff --git a/lib/commands/PUBSUB_NUMSUB.spec.ts b/lib/commands/PUBSUB_NUMSUB.spec.ts index 74065dbb48..403732f8f9 100644 --- a/lib/commands/PUBSUB_NUMSUB.spec.ts +++ b/lib/commands/PUBSUB_NUMSUB.spec.ts @@ -33,7 +33,7 @@ describe('PUBSUB NUMSUB', () => { ); }); - itWithCluster(TestRedisClusters.OPEN, 'cluster.pubSubNumPat', async cluster => { + itWithCluster(TestRedisClusters.OPEN, 'cluster.pubSubNumSub', async cluster => { assert.deepEqual( await cluster.pubSubNumSub(), Object.create(null)