You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion. Sentinel TypeMapping Correctly types Multi commands Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
@@ -1,23 +1,73 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { GeoSearchFrom, GeoSearchBy, GeoReplyWith, GeoSearchOptions } from './generic-transformers';
|
||||
import { transformArguments as geoSearchTransformArguments } from './GEOSEARCH';
|
||||
import { RedisArgument, ArrayReply, TuplesReply, BlobStringReply, NumberReply, DoubleReply, UnwrapReply, Command } 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,
|
||||
export type GeoReplyWith = typeof GEO_REPLY_WITH[keyof typeof GEO_REPLY_WITH];
|
||||
|
||||
export interface GeoReplyWithMember {
|
||||
member: BlobStringReply;
|
||||
distance?: BlobStringReply;
|
||||
hash?: NumberReply;
|
||||
coordinates?: {
|
||||
longitude: DoubleReply;
|
||||
latitude: DoubleReply;
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = geoSearchTransformArguments(key, from, by, options);
|
||||
|
||||
) {
|
||||
const args = GEOSEARCH.transformArguments(key, from, by, options);
|
||||
args.push(...replyWith);
|
||||
|
||||
args.preserve = replyWith;
|
||||
|
||||
return args;
|
||||
}
|
||||
},
|
||||
transformReply(
|
||||
reply: UnwrapReply<ArrayReply<TuplesReply<[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 unwrapped = raw as unknown as UnwrapReply<typeof raw>;
|
||||
|
||||
export { transformGeoMembersWithReply as transformReply } from './generic-transformers';
|
||||
const item: GeoReplyWithMember = {
|
||||
member: unwrapped[0]
|
||||
};
|
||||
|
||||
if (distanceIndex) {
|
||||
item.distance = unwrapped[distanceIndex];
|
||||
}
|
||||
|
||||
if (hashIndex) {
|
||||
item.hash = unwrapped[hashIndex];
|
||||
}
|
||||
|
||||
if (coordinatesIndex) {
|
||||
const [longitude, latitude] = unwrapped[coordinatesIndex];
|
||||
item.coordinates = {
|
||||
longitude,
|
||||
latitude
|
||||
};
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user