You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Support all GEORADIUS Commands (#2017)
* Support all GEORADIUS Commands * move store bool to options * simplify transformReply for store commands * clean code Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
35
packages/client/lib/commands/GEORADIUS.spec.ts
Normal file
35
packages/client/lib/commands/GEORADIUS.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './GEORADIUS';
|
||||
|
||||
describe('GEORADIUS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
['GEORADIUS', 'key', '1', '2', '3', 'm']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadius', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadius('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadius', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadius('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUS.ts
Normal file
25
packages/client/lib/commands/GEORADIUS.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchOptions, GeoCoordinates, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
coordinates: GeoCoordinates,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusArguments(
|
||||
['GEORADIUS'],
|
||||
key,
|
||||
coordinates,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
26
packages/client/lib/commands/GEORADIUSBYMEMBER.spec.ts
Normal file
26
packages/client/lib/commands/GEORADIUSBYMEMBER.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './GEORADIUSBYMEMBER';
|
||||
|
||||
describe('GEORADIUSBYMEMBER', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm'),
|
||||
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusByMember', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusByMember('key', 'member', 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusByMember', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusByMember('key', 'member', 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUSBYMEMBER.ts
Normal file
25
packages/client/lib/commands/GEORADIUSBYMEMBER.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchOptions, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
member: string,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusArguments(
|
||||
['GEORADIUSBYMEMBER'],
|
||||
key,
|
||||
member,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
53
packages/client/lib/commands/GEORADIUSBYMEMBERSTORE.spec.ts
Normal file
53
packages/client/lib/commands/GEORADIUSBYMEMBERSTORE.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments, transformReply } from './GEORADIUSBYMEMBERSTORE';
|
||||
|
||||
describe('GEORADIUSBYMEMBERSTORE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('STORE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm', 'dest', {
|
||||
SORT: 'ASC',
|
||||
COUNT: {
|
||||
value: 1,
|
||||
ANY: true
|
||||
}
|
||||
}),
|
||||
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm', 'ASC', 'COUNT', '1', 'ANY', 'STORE', 'dest']
|
||||
);
|
||||
});
|
||||
|
||||
it('STOREDIST', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm', 'dest', { STOREDIST: true }),
|
||||
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm', 'STOREDIST', 'dest']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusByMemberStore', async client => {
|
||||
await client.geoAdd('source', {
|
||||
longitude: 1,
|
||||
latitude: 1,
|
||||
member: 'member'
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await client.geoRadiusByMemberStore('source', 'member', 3 , 'm', 'dest'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusByMemberStore', async cluster => {
|
||||
await cluster.geoAdd('{tag}source', {
|
||||
longitude: 1,
|
||||
latitude: 1,
|
||||
member: 'member'
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await cluster.geoRadiusByMemberStore('{tag}source', 'member', 3 , 'm','{tag}destination'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUSBYMEMBERSTORE.ts
Normal file
25
packages/client/lib/commands/GEORADIUSBYMEMBERSTORE.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoUnits, GeoRadiusStoreOptions, pushGeoRadiusStoreArguments } from './generic-transformers';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUSBYMEMBER';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
member: string,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
destination: RedisCommandArgument,
|
||||
options?: GeoRadiusStoreOptions,
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusStoreArguments(
|
||||
['GEORADIUSBYMEMBER'],
|
||||
key,
|
||||
member,
|
||||
radius,
|
||||
unit,
|
||||
destination,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number
|
26
packages/client/lib/commands/GEORADIUSBYMEMBER_RO.spec.ts
Normal file
26
packages/client/lib/commands/GEORADIUSBYMEMBER_RO.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './GEORADIUSBYMEMBER_RO';
|
||||
|
||||
describe('GEORADIUSBYMEMBER_RO', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm'),
|
||||
['GEORADIUSBYMEMBER_RO', 'key', 'member', '3', 'm']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusByMemberRo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusByMemberRo('key', 'member', 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusByMemberRo', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusByMemberRo('key', 'member', 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUSBYMEMBER_RO.ts
Normal file
25
packages/client/lib/commands/GEORADIUSBYMEMBER_RO.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchOptions, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
member: string,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusArguments(
|
||||
['GEORADIUSBYMEMBER_RO'],
|
||||
key,
|
||||
member,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
@@ -0,0 +1,31 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith } from './generic-transformers';
|
||||
import { transformArguments } from './GEORADIUSBYMEMBER_RO_WITH';
|
||||
|
||||
describe('GEORADIUSBYMEMBER_RO WITH', () => {
|
||||
it('transformArguments', () => {
|
||||
const expectedReply: RedisCommandArguments = ['GEORADIUSBYMEMBER_RO', 'key', 'member', '3', 'm', 'WITHDIST'];
|
||||
expectedReply.preserve = ['WITHDIST'];
|
||||
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
expectedReply
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusByMemberRoWith', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusByMemberRoWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusByMemberRoWith', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusByMemberRoWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
30
packages/client/lib/commands/GEORADIUSBYMEMBER_RO_WITH.ts
Normal file
30
packages/client/lib/commands/GEORADIUSBYMEMBER_RO_WITH.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith, GeoSearchOptions, GeoUnits } from './generic-transformers';
|
||||
import { transformArguments as geoRadiusTransformArguments } from './GEORADIUSBYMEMBER_RO';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUSBYMEMBER_RO';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
member: string,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
replyWith: Array<GeoReplyWith>,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = geoRadiusTransformArguments(
|
||||
key,
|
||||
member,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
|
||||
args.push(...replyWith);
|
||||
|
||||
args.preserve = replyWith;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
|
31
packages/client/lib/commands/GEORADIUSBYMEMBER_WITH.spec.ts
Normal file
31
packages/client/lib/commands/GEORADIUSBYMEMBER_WITH.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith } from './generic-transformers';
|
||||
import { transformArguments } from './GEORADIUSBYMEMBER_WITH';
|
||||
|
||||
describe('GEORADIUSBYMEMBER WITH', () => {
|
||||
it('transformArguments', () => {
|
||||
const expectedReply: RedisCommandArguments = ['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm', 'WITHDIST'];
|
||||
expectedReply.preserve = ['WITHDIST'];
|
||||
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
expectedReply
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusByMemberWith', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusByMemberWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusByMemberWith', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusByMemberWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
30
packages/client/lib/commands/GEORADIUSBYMEMBER_WITH.ts
Normal file
30
packages/client/lib/commands/GEORADIUSBYMEMBER_WITH.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith, GeoSearchOptions, GeoUnits } from './generic-transformers';
|
||||
import { transformArguments as transformGeoRadiusArguments } from './GEORADIUSBYMEMBER';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUSBYMEMBER';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
member: string,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
replyWith: Array<GeoReplyWith>,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = transformGeoRadiusArguments(
|
||||
key,
|
||||
member,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
|
||||
args.push(...replyWith);
|
||||
|
||||
args.preserve = replyWith;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
|
53
packages/client/lib/commands/GEORADIUSSTORE.spec.ts
Normal file
53
packages/client/lib/commands/GEORADIUSSTORE.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments, transformReply } from './GEORADIUSSTORE';
|
||||
|
||||
describe('GEORADIUSSTORE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('STORE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {longitude: 1, latitude: 2}, 3 , 'm', 'dest', {
|
||||
SORT: 'ASC',
|
||||
COUNT: {
|
||||
value: 1,
|
||||
ANY: true
|
||||
}
|
||||
}),
|
||||
['GEORADIUS', 'key', '1', '2', '3', 'm', 'ASC', 'COUNT', '1', 'ANY', 'STORE', 'dest']
|
||||
);
|
||||
});
|
||||
|
||||
it('STOREDIST', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {longitude: 1, latitude: 2}, 3 , 'm', 'dest', { STOREDIST: true }),
|
||||
['GEORADIUS', 'key', '1', '2', '3', 'm', 'STOREDIST', 'dest']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusStore', async client => {
|
||||
await client.geoAdd('source', {
|
||||
longitude: 1,
|
||||
latitude: 1,
|
||||
member: 'member'
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await client.geoRadiusStore('source', {longitude: 1, latitude: 1}, 3 , 'm', 'dest'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusStore', async cluster => {
|
||||
await cluster.geoAdd('{tag}source', {
|
||||
longitude: 1,
|
||||
latitude: 1,
|
||||
member: 'member'
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await cluster.geoRadiusStore('{tag}source', {longitude: 1, latitude: 1}, 3 , 'm', '{tag}destination'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUSSTORE.ts
Normal file
25
packages/client/lib/commands/GEORADIUSSTORE.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoCoordinates, GeoUnits, GeoRadiusStoreOptions, pushGeoRadiusStoreArguments } from './generic-transformers';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUS';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
coordinates: GeoCoordinates,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
destination: RedisCommandArgument,
|
||||
options?: GeoRadiusStoreOptions,
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusStoreArguments(
|
||||
['GEORADIUS'],
|
||||
key,
|
||||
coordinates,
|
||||
radius,
|
||||
unit,
|
||||
destination,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
35
packages/client/lib/commands/GEORADIUS_RO.spec.ts
Normal file
35
packages/client/lib/commands/GEORADIUS_RO.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './GEORADIUS_RO';
|
||||
|
||||
describe('GEORADIUS_RO', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
['GEORADIUS_RO', 'key', '1', '2', '3', 'm']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusRo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusRo('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusRo', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusRo('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm'),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
25
packages/client/lib/commands/GEORADIUS_RO.ts
Normal file
25
packages/client/lib/commands/GEORADIUS_RO.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchOptions, GeoCoordinates, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
coordinates: GeoCoordinates,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
return pushGeoRadiusArguments(
|
||||
['GEORADIUS_RO'],
|
||||
key,
|
||||
coordinates,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
40
packages/client/lib/commands/GEORADIUS_RO_WITH.spec.ts
Normal file
40
packages/client/lib/commands/GEORADIUS_RO_WITH.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith } from './generic-transformers';
|
||||
import { transformArguments } from './GEORADIUS_RO_WITH';
|
||||
|
||||
describe('GEORADIUS_RO WITH', () => {
|
||||
it('transformArguments', () => {
|
||||
const expectedReply: RedisCommandArguments = ['GEORADIUS_RO', 'key', '1', '2', '3', 'm', 'WITHDIST'];
|
||||
expectedReply.preserve = ['WITHDIST'];
|
||||
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
expectedReply
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusRoWith', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusRoWith('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusReadOnlyWith', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusRoWith('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
30
packages/client/lib/commands/GEORADIUS_RO_WITH.ts
Normal file
30
packages/client/lib/commands/GEORADIUS_RO_WITH.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith, GeoSearchOptions, GeoCoordinates, GeoUnits } from './generic-transformers';
|
||||
import { transformArguments as transformGeoRadiusRoArguments } from './GEORADIUS_RO';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUS_RO';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
coordinates: GeoCoordinates,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
replyWith: Array<GeoReplyWith>,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = transformGeoRadiusRoArguments(
|
||||
key,
|
||||
coordinates,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
|
||||
args.push(...replyWith);
|
||||
|
||||
args.preserve = replyWith;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
|
40
packages/client/lib/commands/GEORADIUS_WITH.spec.ts
Normal file
40
packages/client/lib/commands/GEORADIUS_WITH.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith } from './generic-transformers';
|
||||
import { transformArguments } from './GEORADIUS_WITH';
|
||||
|
||||
describe('GEORADIUS WITH', () => {
|
||||
it('transformArguments', () => {
|
||||
const expectedReply: RedisCommandArguments = ['GEORADIUS', 'key', '1', '2', '3', 'm', 'WITHDIST'];
|
||||
expectedReply.preserve = ['WITHDIST'];
|
||||
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
expectedReply
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.geoRadiusWith', async client => {
|
||||
assert.deepEqual(
|
||||
await client.geoRadiusWith('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.geoRadiusWith', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.geoRadiusWith('key', {
|
||||
longitude: 1,
|
||||
latitude: 2
|
||||
}, 3 , 'm', [GeoReplyWith.DISTANCE]),
|
||||
[]
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
30
packages/client/lib/commands/GEORADIUS_WITH.ts
Normal file
30
packages/client/lib/commands/GEORADIUS_WITH.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoReplyWith, GeoSearchOptions, GeoCoordinates, GeoUnits } from './generic-transformers';
|
||||
import { transformArguments as transformGeoRadiusArguments } from './GEORADIUS';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUS';
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
coordinates: GeoCoordinates,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
replyWith: Array<GeoReplyWith>,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = transformGeoRadiusArguments(
|
||||
key,
|
||||
coordinates,
|
||||
radius,
|
||||
unit,
|
||||
options
|
||||
);
|
||||
|
||||
args.push(...replyWith);
|
||||
|
||||
args.preserve = replyWith;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
|
@@ -1,9 +1,7 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchFrom, GeoSearchBy, GeoSearchOptions, pushGeoSearchArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEOSEARCH';
|
||||
|
||||
interface GeoSearchStoreOptions extends GeoSearchOptions {
|
||||
STOREDIST?: true;
|
||||
|
@@ -286,6 +286,63 @@ export function pushGeoSearchArguments(
|
||||
return args;
|
||||
}
|
||||
|
||||
export function pushGeoRadiusArguments(
|
||||
args: RedisCommandArguments,
|
||||
key: RedisCommandArgument,
|
||||
from: GeoSearchFrom,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
options?: GeoSearchOptions
|
||||
): RedisCommandArguments {
|
||||
args.push(key);
|
||||
|
||||
if (typeof from === 'string') {
|
||||
args.push(from);
|
||||
} else {
|
||||
args.push(
|
||||
from.longitude.toString(),
|
||||
from.latitude.toString()
|
||||
);
|
||||
}
|
||||
|
||||
args.push(
|
||||
radius.toString(),
|
||||
unit
|
||||
);
|
||||
|
||||
if (options?.SORT) {
|
||||
args.push(options.SORT);
|
||||
}
|
||||
|
||||
pushGeoCountArgument(args, options?.COUNT);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export interface GeoRadiusStoreOptions extends GeoSearchOptions {
|
||||
STOREDIST?: boolean;
|
||||
}
|
||||
|
||||
export function pushGeoRadiusStoreArguments(
|
||||
args: RedisCommandArguments,
|
||||
key: RedisCommandArgument,
|
||||
from: GeoSearchFrom,
|
||||
radius: number,
|
||||
unit: GeoUnits,
|
||||
destination: RedisCommandArgument,
|
||||
options?: GeoRadiusStoreOptions
|
||||
): RedisCommandArguments {
|
||||
pushGeoRadiusArguments(args, key, from, radius, unit, options);
|
||||
|
||||
if (options?.STOREDIST) {
|
||||
args.push('STOREDIST', destination);
|
||||
} else {
|
||||
args.push('STORE', destination);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export enum GeoReplyWith {
|
||||
DISTANCE = 'WITHDIST',
|
||||
HASH = 'WITHHASH',
|
||||
|
Reference in New Issue
Block a user