You've already forked node-redis
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:
@@ -184,7 +184,7 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extend
|
|||||||
#initiateQueue(): RedisCommandsQueue {
|
#initiateQueue(): RedisCommandsQueue {
|
||||||
return new RedisCommandsQueue(
|
return new RedisCommandsQueue(
|
||||||
this.#options?.commandsQueueMaxLength,
|
this.#options?.commandsQueueMaxLength,
|
||||||
(encodedCommands: string) => this.#socket.write(encodedCommands)
|
encodedCommands => this.#socket.write(encodedCommands)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,6 +91,10 @@ export default class RedisCluster<M extends RedisModules = RedisModules, S exten
|
|||||||
this.#Multi = RedisMultiCommand.extend(options);
|
this.#Multi = RedisMultiCommand.extend(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duplicate(): RedisClusterOptions<M, S> {
|
||||||
|
return new (Object.getPrototypeOf(this).constructor)(this.#options);
|
||||||
|
}
|
||||||
|
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
return this.#slots.connect();
|
return this.#slots.connect();
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils';
|
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils';
|
||||||
import { transformArguments } from './GEOPOS';
|
import { transformArguments, transformReply } from './GEOPOS';
|
||||||
|
|
||||||
describe('GEOPOS', () => {
|
describe('GEOPOS', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
@@ -19,11 +19,49 @@ describe('GEOPOS', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
itWithClient(TestRedisServers.OPEN, 'client.geoPos', async client => {
|
describe('transformReply', () => {
|
||||||
assert.deepEqual(
|
it('null', () => {
|
||||||
await client.geoPos('key', 'member'),
|
assert.deepEqual(
|
||||||
[null]
|
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 => {
|
itWithCluster(TestRedisClusters.OPEN, 'cluster.geoPos', async cluster => {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster, describeHandleMinimumRedisVersion } from '../test-utils';
|
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster, describeHandleMinimumRedisVersion } from '../test-utils';
|
||||||
import { transformArguments } from './GEOSEARCHSTORE';
|
import { transformArguments, transformReply } from './GEOSEARCHSTORE';
|
||||||
|
|
||||||
describe('GEOSEARCHSTORE', () => {
|
describe('GEOSEARCHSTORE', () => {
|
||||||
describeHandleMinimumRedisVersion([6, 2]);
|
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 => {
|
itWithClient(TestRedisServers.OPEN, 'client.geoSearchStore', async client => {
|
||||||
await client.geoAdd('source', {
|
await client.geoAdd('source', {
|
||||||
longitude: 1,
|
longitude: 1,
|
||||||
|
@@ -33,7 +33,7 @@ describe('PUBSUB NUMSUB', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
itWithCluster(TestRedisClusters.OPEN, 'cluster.pubSubNumPat', async cluster => {
|
itWithCluster(TestRedisClusters.OPEN, 'cluster.pubSubNumSub', async cluster => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await cluster.pubSubNumSub(),
|
await cluster.pubSubNumSub(),
|
||||||
Object.create(null)
|
Object.create(null)
|
||||||
|
Reference in New Issue
Block a user