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

fix GEO* commands

This commit is contained in:
Leibale
2023-05-08 11:04:22 +03:00
parent d2e244a77d
commit 6a0b4db4f7
37 changed files with 1115 additions and 990 deletions

View File

@@ -1,23 +1,71 @@
// import { RedisCommandArgument, RedisCommandArguments } from '.';
// import { GeoSearchFrom, GeoSearchBy, GeoReplyWith, GeoSearchOptions } from './generic-transformers';
// import { transformArguments as geoSearchTransformArguments } from './GEOSEARCH';
import { ArrayReply, BlobStringReply, NumberReply, DoubleReply, Command, RedisArgument } from '../RESP/types';
import GEOSEARCH, { GeoSearchBy, GeoSearchFrom, GeoSearchOptions } from './GEOSEARCH';
// export { FIRST_KEY_INDEX, IS_READ_ONLY } from './GEOSEARCH';
export const GEO_REPLY_WITH = {
DISTANCE: 'WITHDIST',
HASH: 'WITHHASH',
COORDINATES: 'WITHCOORD'
} as const;
// export function transformArguments(
// key: RedisCommandArgument,
// from: GeoSearchFrom,
// by: GeoSearchBy,
// replyWith: Array<GeoReplyWith>,
// options?: GeoSearchOptions
// ): RedisCommandArguments {
// const args: RedisCommandArguments = geoSearchTransformArguments(key, from, by, options);
export type GeoReplyWith = typeof GEO_REPLY_WITH[keyof typeof GEO_REPLY_WITH];
// args.push(...replyWith);
export interface GeoReplyWithMember {
member: BlobStringReply;
distance?: BlobStringReply;
hash?: NumberReply;
coordinates?: {
longitude: DoubleReply;
latitude: DoubleReply;
};
}
// args.preserve = replyWith;
export default {
FIRST_KEY_INDEX: GEOSEARCH.FIRST_KEY_INDEX,
IS_READ_ONLY: GEOSEARCH.IS_READ_ONLY,
transformArguments(
key: RedisArgument,
from: GeoSearchFrom,
by: GeoSearchBy,
replyWith: Array<GeoReplyWith>,
options?: GeoSearchOptions
) {
const args = GEOSEARCH.transformArguments(key, from, by, options);
args.push(...replyWith);
args.preserve = replyWith;
return args;
},
transformReply(
reply: ArrayReply<[BlobStringReply, ...Array<any>]>,
replyWith: Array<GeoReplyWith>
) {
const replyWithSet = new Set(replyWith);
let index = 0;
const distanceIndex = replyWithSet.has(GEO_REPLY_WITH.DISTANCE) && ++index,
hashIndex = replyWithSet.has(GEO_REPLY_WITH.HASH) && ++index,
coordinatesIndex = replyWithSet.has(GEO_REPLY_WITH.COORDINATES) && ++index;
return reply.map(raw => {
const item: GeoReplyWithMember = {
member: raw[0]
};
// return args;
// }
if (distanceIndex) {
item.distance = raw[distanceIndex];
}
if (hashIndex) {
item.hash = raw[hashIndex];
}
if (coordinatesIndex) {
const [longitude, latitude] = raw[coordinatesIndex];
item.coordinates = {
longitude,
latitude
};
}
// export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
return item;
});
}
} as const satisfies Command;