Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/commands/geo_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,23 @@ describe("GEOSEARCH tests", () => {
},
]);
});

test("should return one member, with count set", async () => {
const key = newKey();
await new GeoAddCommand([
key,
{ longitude: 13.361389, latitude: 38.115556, member: "Palermo" },
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" },
]).exec(client);

const res = await new GeoSearchCommand([
key,
{ type: "FROMLONLAT", coordinate: { lon: 15, lat: 37 } },
{ type: "BYRADIUS", radius: 200, radiusType: "KM" },
"ASC",
{ count: { limit: 1 } },
]).exec(client);

expect(res).toEqual([{ member: "Catania" }]);
});
});
2 changes: 1 addition & 1 deletion pkg/commands/geo_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class GeoSearchCommand<
command.push(order);

if (opts?.count) {
command.push(opts.count.limit, ...(opts.count.any ? ["ANY"] : []));
command.push("COUNT", opts.count.limit, ...(opts.count.any ? ["ANY"] : []));
}

const transform = (result: string[] | string[][]) => {
Expand Down
34 changes: 34 additions & 0 deletions pkg/commands/geo_search_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,38 @@ describe("GEOSSEARCHSTORE tests", () => {
]);
expect(res).toEqual(zrangeRes.length / 2);
});

test("should return limited amount of members and store them in sorted set", async () => {
const key = newKey();
const destination = newKey();

await new GeoAddCommand([
key,
{ longitude: -73.9857, latitude: 40.7488, member: "Empire State Building" },
{ longitude: -74.0445, latitude: 40.6892, member: "Statue of Liberty" },
{ longitude: -73.9632, latitude: 40.7789, member: "Central Park" },
{ longitude: -73.873, latitude: 40.7769, member: "LaGuardia Airport" },
{ longitude: -74.177, latitude: 40.6413, member: "JFK Airport" },
{ longitude: -73.9772, latitude: 40.7527, member: "Grand Central Terminal" },
]).exec(client);

const res = await new GeoSearchStoreCommand([
destination,
key,
{ type: "FROMMEMBER", member: "Empire State Building" },
{ type: "BYRADIUS", radius: 5, radiusType: "KM" },
"ASC",
{ count: { limit: 2 } },
]).exec(client);
const zrangeRes = await new ZRangeCommand([destination, 0, -1, { withScores: true }]).exec(
client,
);
expect(zrangeRes).toEqual([
"Empire State Building",
1791875672666387,
"Grand Central Terminal",
1791875708058440,
]);
expect(res).toEqual(zrangeRes.length / 2);
});
});
2 changes: 1 addition & 1 deletion pkg/commands/geo_search_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class GeoSearchStoreCommand<
command.push(order);

if (opts?.count) {
command.push(opts.count.limit, ...(opts.count.any ? ["ANY"] : []));
command.push("COUNT", opts.count.limit, ...(opts.count.any ? ["ANY"] : []));
}

super([...command, ...(opts?.storeDist ? ["STOREDIST"] : [])], commandOptions);
Expand Down