Skip to content

Commit 06c1d2c

Browse files
Avital-Fineleibale
andauthored
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 <[email protected]>
1 parent 5c9f31f commit 06c1d2c

23 files changed

+728
-3
lines changed

packages/client/lib/cluster/commands.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ import * as GEOADD from '../commands/GEOADD';
3232
import * as GEODIST from '../commands/GEODIST';
3333
import * as GEOHASH from '../commands/GEOHASH';
3434
import * as GEOPOS from '../commands/GEOPOS';
35+
import * as GEORADIUS_RO_WITH from '../commands/GEORADIUS_RO_WITH';
36+
import * as GEORADIUS_RO from '../commands/GEORADIUS_RO';
37+
import * as GEORADIUS_WITH from '../commands/GEORADIUS_WITH';
38+
import * as GEORADIUS from '../commands/GEORADIUS';
39+
import * as GEORADIUSBYMEMBER_RO_WITH from '../commands/GEORADIUSBYMEMBER_RO_WITH';
40+
import * as GEORADIUSBYMEMBER_RO from '../commands/GEORADIUSBYMEMBER_RO';
41+
import * as GEORADIUSBYMEMBER_WITH from '../commands/GEORADIUSBYMEMBER_WITH';
42+
import * as GEORADIUSBYMEMBER from '../commands/GEORADIUSBYMEMBER';
43+
import * as GEORADIUSBYMEMBERSTORE from '../commands/GEORADIUSBYMEMBERSTORE';
44+
import * as GEORADIUSSTORE from '../commands/GEORADIUSSTORE';
3545
import * as GEOSEARCH_WITH from '../commands/GEOSEARCH_WITH';
3646
import * as GEOSEARCH from '../commands/GEOSEARCH';
3747
import * as GEOSEARCHSTORE from '../commands/GEOSEARCHSTORE';
@@ -263,6 +273,26 @@ export default {
263273
geoHash: GEOHASH,
264274
GEOPOS,
265275
geoPos: GEOPOS,
276+
GEORADIUS_RO_WITH,
277+
geoRadiusRoWith: GEORADIUS_RO_WITH,
278+
GEORADIUS_RO,
279+
geoRadiusRo: GEORADIUS_RO,
280+
GEORADIUS_WITH,
281+
geoRadiusWith: GEORADIUS_WITH,
282+
GEORADIUS,
283+
geoRadius: GEORADIUS,
284+
GEORADIUSBYMEMBER_RO_WITH,
285+
geoRadiusByMemberRoWith: GEORADIUSBYMEMBER_RO_WITH,
286+
GEORADIUSBYMEMBER_RO,
287+
geoRadiusByMemberRo: GEORADIUSBYMEMBER_RO,
288+
GEORADIUSBYMEMBER_WITH,
289+
geoRadiusByMemberWith: GEORADIUSBYMEMBER_WITH,
290+
GEORADIUSBYMEMBER,
291+
geoRadiusByMember: GEORADIUSBYMEMBER,
292+
GEORADIUSBYMEMBERSTORE,
293+
geoRadiusByMemberStore: GEORADIUSBYMEMBERSTORE,
294+
GEORADIUSSTORE,
295+
geoRadiusStore: GEORADIUSSTORE,
266296
GEOSEARCH_WITH,
267297
geoSearchWith: GEOSEARCH_WITH,
268298
GEOSEARCH,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './GEORADIUS';
4+
5+
describe('GEORADIUS', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key', {
9+
longitude: 1,
10+
latitude: 2
11+
}, 3 , 'm'),
12+
['GEORADIUS', 'key', '1', '2', '3', 'm']
13+
);
14+
});
15+
16+
testUtils.testWithClient('client.geoRadius', async client => {
17+
assert.deepEqual(
18+
await client.geoRadius('key', {
19+
longitude: 1,
20+
latitude: 2
21+
}, 3 , 'm'),
22+
[]
23+
);
24+
}, GLOBAL.SERVERS.OPEN);
25+
26+
testUtils.testWithCluster('cluster.geoRadius', async cluster => {
27+
assert.deepEqual(
28+
await cluster.geoRadius('key', {
29+
longitude: 1,
30+
latitude: 2
31+
}, 3 , 'm'),
32+
[]
33+
);
34+
}, GLOBAL.CLUSTERS.OPEN);
35+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { GeoSearchOptions, GeoCoordinates, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 1;
5+
6+
export const IS_READ_ONLY = true;
7+
8+
export function transformArguments(
9+
key: RedisCommandArgument,
10+
coordinates: GeoCoordinates,
11+
radius: number,
12+
unit: GeoUnits,
13+
options?: GeoSearchOptions
14+
): RedisCommandArguments {
15+
return pushGeoRadiusArguments(
16+
['GEORADIUS'],
17+
key,
18+
coordinates,
19+
radius,
20+
unit,
21+
options
22+
);
23+
}
24+
25+
export declare function transformReply(): Array<RedisCommandArgument>;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './GEORADIUSBYMEMBER';
4+
5+
describe('GEORADIUSBYMEMBER', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key', 'member', 3 , 'm'),
9+
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.geoRadiusByMember', async client => {
14+
assert.deepEqual(
15+
await client.geoRadiusByMember('key', 'member', 3 , 'm'),
16+
[]
17+
);
18+
}, GLOBAL.SERVERS.OPEN);
19+
20+
testUtils.testWithCluster('cluster.geoRadiusByMember', async cluster => {
21+
assert.deepEqual(
22+
await cluster.geoRadiusByMember('key', 'member', 3 , 'm'),
23+
[]
24+
);
25+
}, GLOBAL.CLUSTERS.OPEN);
26+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { GeoSearchOptions, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 1;
5+
6+
export const IS_READ_ONLY = true;
7+
8+
export function transformArguments(
9+
key: RedisCommandArgument,
10+
member: string,
11+
radius: number,
12+
unit: GeoUnits,
13+
options?: GeoSearchOptions
14+
): RedisCommandArguments {
15+
return pushGeoRadiusArguments(
16+
['GEORADIUSBYMEMBER'],
17+
key,
18+
member,
19+
radius,
20+
unit,
21+
options
22+
);
23+
}
24+
25+
export declare function transformReply(): Array<RedisCommandArgument>;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments, transformReply } from './GEORADIUSBYMEMBERSTORE';
4+
5+
describe('GEORADIUSBYMEMBERSTORE', () => {
6+
describe('transformArguments', () => {
7+
it('STORE', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 'member', 3 , 'm', 'dest', {
10+
SORT: 'ASC',
11+
COUNT: {
12+
value: 1,
13+
ANY: true
14+
}
15+
}),
16+
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm', 'ASC', 'COUNT', '1', 'ANY', 'STORE', 'dest']
17+
);
18+
});
19+
20+
it('STOREDIST', () => {
21+
assert.deepEqual(
22+
transformArguments('key', 'member', 3 , 'm', 'dest', { STOREDIST: true }),
23+
['GEORADIUSBYMEMBER', 'key', 'member', '3', 'm', 'STOREDIST', 'dest']
24+
);
25+
});
26+
});
27+
28+
testUtils.testWithClient('client.geoRadiusByMemberStore', async client => {
29+
await client.geoAdd('source', {
30+
longitude: 1,
31+
latitude: 1,
32+
member: 'member'
33+
});
34+
35+
assert.equal(
36+
await client.geoRadiusByMemberStore('source', 'member', 3 , 'm', 'dest'),
37+
1
38+
);
39+
}, GLOBAL.SERVERS.OPEN);
40+
41+
testUtils.testWithCluster('cluster.geoRadiusByMemberStore', async cluster => {
42+
await cluster.geoAdd('{tag}source', {
43+
longitude: 1,
44+
latitude: 1,
45+
member: 'member'
46+
});
47+
48+
assert.equal(
49+
await cluster.geoRadiusByMemberStore('{tag}source', 'member', 3 , 'm','{tag}destination'),
50+
1
51+
);
52+
}, GLOBAL.CLUSTERS.OPEN);
53+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { GeoUnits, GeoRadiusStoreOptions, pushGeoRadiusStoreArguments } from './generic-transformers';
3+
4+
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEORADIUSBYMEMBER';
5+
6+
export function transformArguments(
7+
key: RedisCommandArgument,
8+
member: string,
9+
radius: number,
10+
unit: GeoUnits,
11+
destination: RedisCommandArgument,
12+
options?: GeoRadiusStoreOptions,
13+
): RedisCommandArguments {
14+
return pushGeoRadiusStoreArguments(
15+
['GEORADIUSBYMEMBER'],
16+
key,
17+
member,
18+
radius,
19+
unit,
20+
destination,
21+
options
22+
);
23+
}
24+
25+
export declare function transformReply(): number
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './GEORADIUSBYMEMBER_RO';
4+
5+
describe('GEORADIUSBYMEMBER_RO', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key', 'member', 3 , 'm'),
9+
['GEORADIUSBYMEMBER_RO', 'key', 'member', '3', 'm']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.geoRadiusByMemberRo', async client => {
14+
assert.deepEqual(
15+
await client.geoRadiusByMemberRo('key', 'member', 3 , 'm'),
16+
[]
17+
);
18+
}, GLOBAL.SERVERS.OPEN);
19+
20+
testUtils.testWithCluster('cluster.geoRadiusByMemberRo', async cluster => {
21+
assert.deepEqual(
22+
await cluster.geoRadiusByMemberRo('key', 'member', 3 , 'm'),
23+
[]
24+
);
25+
}, GLOBAL.CLUSTERS.OPEN);
26+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { GeoSearchOptions, pushGeoRadiusArguments, GeoUnits } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 1;
5+
6+
export const IS_READ_ONLY = true;
7+
8+
export function transformArguments(
9+
key: RedisCommandArgument,
10+
member: string,
11+
radius: number,
12+
unit: GeoUnits,
13+
options?: GeoSearchOptions
14+
): RedisCommandArguments {
15+
return pushGeoRadiusArguments(
16+
['GEORADIUSBYMEMBER_RO'],
17+
key,
18+
member,
19+
radius,
20+
unit,
21+
options
22+
);
23+
}
24+
25+
export declare function transformReply(): Array<RedisCommandArgument>;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { RedisCommandArguments } from '.';
4+
import { GeoReplyWith } from './generic-transformers';
5+
import { transformArguments } from './GEORADIUSBYMEMBER_RO_WITH';
6+
7+
describe('GEORADIUSBYMEMBER_RO WITH', () => {
8+
it('transformArguments', () => {
9+
const expectedReply: RedisCommandArguments = ['GEORADIUSBYMEMBER_RO', 'key', 'member', '3', 'm', 'WITHDIST'];
10+
expectedReply.preserve = ['WITHDIST'];
11+
12+
assert.deepEqual(
13+
transformArguments('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
14+
expectedReply
15+
);
16+
});
17+
18+
testUtils.testWithClient('client.geoRadiusByMemberRoWith', async client => {
19+
assert.deepEqual(
20+
await client.geoRadiusByMemberRoWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
21+
[]
22+
);
23+
}, GLOBAL.SERVERS.OPEN);
24+
25+
testUtils.testWithCluster('cluster.geoRadiusByMemberRoWith', async cluster => {
26+
assert.deepEqual(
27+
await cluster.geoRadiusByMemberRoWith('key', 'member', 3 , 'm', [GeoReplyWith.DISTANCE]),
28+
[]
29+
);
30+
}, GLOBAL.CLUSTERS.OPEN);
31+
});

0 commit comments

Comments
 (0)