1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

add cluster.duplicate, add some tests

This commit is contained in:
leibale
2021-09-09 16:58:31 -04:00
parent 18ad329ccc
commit 1413a69a6b
5 changed files with 58 additions and 9 deletions

View File

@@ -184,7 +184,7 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
#initiateQueue(): RedisCommandsQueue {
return new RedisCommandsQueue(
this.#options?.commandsQueueMaxLength,
(encodedCommands: string) => this.#socket.write(encodedCommands)
encodedCommands => this.#socket.write(encodedCommands)
);
}

View File

@@ -91,6 +91,10 @@ export default class RedisCluster<M extends RedisModules = RedisModules, S exten
this.#Multi = RedisMultiCommand.extend(options);
}
duplicate(): RedisClusterOptions<M, S> {
return new (Object.getPrototypeOf(this).constructor)(this.#options);
}
async connect(): Promise<void> {
return this.#slots.connect();
}

View File

@@ -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,13 +19,51 @@ describe('GEOPOS', () => {
});
});
itWithClient(TestRedisServers.OPEN, 'client.geoPos', async client => {
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 => {
assert.deepEqual(
await cluster.geoPos('key', 'member'),

View File

@@ -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,

View File

@@ -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)