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
8 changes: 5 additions & 3 deletions pkg/commands/geo_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Command, CommandOptions } from "./command.ts";
/**
* @see https://redis.io/commands/geohash
*/
export class GeoHashCommand<TMember = string>
extends Command<(string | null)[], (string | null)[]> {
export class GeoHashCommand<TMember = string> extends Command<
(string | null)[],
(string | null)[]
> {
constructor(
cmd: [string, ...TMember[] | TMember[]],
cmd: [string, ...(TMember[] | TMember[])],
opts?: CommandOptions<(string | null)[], (string | null)[]>,
) {
const [key] = cmd;
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/geo_pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Coordinates = {
export class GeoPosCommand<TMember = string> extends Command<(string | null)[][], Coordinates[]> {
constructor(
cmd: [string, ...(TMember[] | TMember[])],
opts?: CommandOptions<(string | null)[][], Coordinates[]>
opts?: CommandOptions<(string | null)[][], Coordinates[]>,
) {
const [key] = cmd;
// Check if the second argument is an array of strings (members).
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/geo_search.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect, afterAll } from "bun:test";
import { afterAll, describe, expect, test } from "bun:test";
import { keygen, newHttpClient } from "../test-utils.ts";

import { GeoAddCommand } from "./geo_add.ts";
Expand Down
15 changes: 8 additions & 7 deletions pkg/commands/geo_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type OptionMappings = {
};

type GeoSearchOptions<TOptions> = {
[K in keyof TOptions as K extends keyof OptionMappings
? OptionMappings[K]
: never]: K extends "withHash"
[K in
keyof TOptions as K extends keyof OptionMappings
? OptionMappings[K]
: never]: K extends "withHash"
? string
: K extends "withCoord"
? { long: number; lat: number }
Expand All @@ -53,17 +54,17 @@ type GeoSearchResponse<TOptions, TMemberType> = ({
*/
export class GeoSearchCommand<
TMemberType = string,
TOptions extends GeoSearchCommandOptions = GeoSearchCommandOptions
TOptions extends GeoSearchCommandOptions = GeoSearchCommandOptions,
> extends Command<any[] | any[][], GeoSearchResponse<TOptions, TMemberType>> {
constructor(
[key, centerPoint, shape, order, opts]: [
key: string,
centerPoint: CenterPoint<TMemberType>,
shape: Shape,
order: "ASC" | "DESC" | "asc" | "desc",
opts?: TOptions
opts?: TOptions,
],
commandOptions?: CommandOptions<any[] | any[][], GeoSearchResponse<TOptions, TMemberType>>
commandOptions?: CommandOptions<any[] | any[][], GeoSearchResponse<TOptions, TMemberType>>,
) {
const command: unknown[] = ["GEOSEARCH", key];

Expand Down Expand Up @@ -133,7 +134,7 @@ export class GeoSearchCommand<
{
...commandOptions,
deserialize: transform,
}
},
);
}
}
8 changes: 4 additions & 4 deletions pkg/commands/geo_search_store.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, describe, afterAll } from "bun:test";
import { afterAll, describe, expect, test } from "bun:test";
import { keygen, newHttpClient } from "../test-utils.ts";

import { GeoAddCommand } from "./geo_add.ts";
Expand Down Expand Up @@ -32,7 +32,7 @@ describe("GEOSSEARCHSTORE tests", () => {
"ASC",
]).exec(client);
const zrangeRes = await new ZRangeCommand([destination, 0, -1, { withScores: true }]).exec(
client
client,
);
expect(zrangeRes).toEqual([
"Empire State Building",
Expand Down Expand Up @@ -68,7 +68,7 @@ describe("GEOSSEARCHSTORE tests", () => {
{ storeDist: true },
]).exec(client);
const zrangeRes = await new ZRangeCommand([destination, 0, -1, { withScores: true }]).exec(
client
client,
);
expect(zrangeRes).toEqual([
"Empire State Building",
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("GEOSSEARCHSTORE tests", () => {
{ storeDist: true },
]).exec(client);
const zrangeRes = await new ZRangeCommand([destination, 0, -1, { withScores: true }]).exec(
client
client,
);
expect(zrangeRes).toEqual([
{ name: "Empire State Building" },
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/geo_search_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type GeoSearchCommandOptions = {
*/
export class GeoSearchStoreCommand<
TMemberType = string,
TOptions extends GeoSearchCommandOptions = GeoSearchCommandOptions
TOptions extends GeoSearchCommandOptions = GeoSearchCommandOptions,
> extends Command<any[] | any[][], number> {
constructor(
[destination, key, centerPoint, shape, order, opts]: [
Expand All @@ -38,9 +38,9 @@ export class GeoSearchStoreCommand<
centerPoint: CenterPoint<TMemberType>,
shape: Shape,
order: "ASC" | "DESC" | "asc" | "desc",
opts?: TOptions
opts?: TOptions,
],
commandOptions?: CommandOptions<any[] | any[][], number>
commandOptions?: CommandOptions<any[] | any[][], number>,
) {
const command: unknown[] = ["GEOSEARCHSTORE", destination, key];

Expand Down
40 changes: 20 additions & 20 deletions pkg/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
ExpireCommand,
FlushAllCommand,
FlushDBCommand,
GeoHashCommand,
GeoAddCommand,
GeoDistCommand,
GeoSearchStoreCommand,
GeoSearchCommand,
GeoHashCommand,
GeoPosCommand,
GeoSearchCommand,
GeoSearchStoreCommand,
GetBitCommand,
GetCommand,
GetDelCommand,
Expand Down Expand Up @@ -234,7 +234,7 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
exec = async <
TCommandResults extends unknown[] = [] extends TCommands
? unknown[]
: InferResponseData<TCommands>
: InferResponseData<TCommands>,
>(): Promise<TCommandResults> => {
if (this.commands.length === 0) {
throw new Error("Pipeline is empty");
Expand All @@ -248,7 +248,7 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
return res.map(({ error, result }, i) => {
if (error) {
throw new UpstashError(
`Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`
`Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`,
);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
...sourceKeys: string[]
) =>
this.chain(
new BitOpCommand([op as any, destinationKey, sourceKey, ...sourceKeys], this.commandOptions)
new BitOpCommand([op as any, destinationKey, sourceKey, ...sourceKeys], this.commandOptions),
);

/**
Expand Down Expand Up @@ -484,7 +484,7 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
hrandfield = <TData extends string | string[] | Record<string, unknown>>(
key: string,
count?: number,
withValues?: boolean
withValues?: boolean,
) =>
this.chain(new HRandFieldCommand<TData>([key, count, withValues] as any, this.commandOptions));

Expand Down Expand Up @@ -902,23 +902,23 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
| [
key: string,
opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr,
...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]
...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]],
]
) => {
if ("score" in args[1]) {
return this.chain(
new ZAddCommand<TData>(
[args[0], args[1] as ScoreMember<TData>, ...(args.slice(2) as any)],
this.commandOptions
)
this.commandOptions,
),
);
}

return this.chain(
new ZAddCommand<TData>(
[args[0], args[1] as any, ...(args.slice(2) as any)],
this.commandOptions
)
this.commandOptions,
),
);
};

Expand Down Expand Up @@ -980,13 +980,13 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
key: string,
min: `(${string}` | `[${string}` | "-" | "+",
max: `(${string}` | `[${string}` | "-" | "+",
opts: { byLex: true } & ZRangeCommandOptions
opts: { byLex: true } & ZRangeCommandOptions,
]
| [
key: string,
min: number | `(${number}` | "-inf" | "+inf",
max: number | `(${number}` | "-inf" | "+inf",
opts: { byScore: true } & ZRangeCommandOptions
opts: { byScore: true } & ZRangeCommandOptions,
]
) => this.chain(new ZRangeCommand<TData>(args as any, this.commandOptions));

Expand Down Expand Up @@ -1113,37 +1113,37 @@ export class Pipeline<TCommands extends Command<any, any>[] = []> {
* @see https://redis.io/commands/geoadd
*/
geoadd: (...args: CommandArgs<typeof GeoAddCommand>) =>
new GeoAddCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoAddCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/geodist
*/
geodist: (...args: CommandArgs<typeof GeoDistCommand>) =>
new GeoDistCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoDistCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/geopos
*/
geopos: (...args: CommandArgs<typeof GeoPosCommand>) =>
new GeoPosCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoPosCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/geohash
*/
geohash: (...args: CommandArgs<typeof GeoHashCommand>) =>
new GeoHashCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoHashCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/geosearch
*/
geosearch: (...args: CommandArgs<typeof GeoSearchCommand>) =>
new GeoSearchCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoSearchCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/geosearchstore
*/
geosearchstore: (...args: CommandArgs<typeof GeoSearchStoreCommand>) =>
new GeoSearchStoreCommand(args, this.commandOptions).exec(this.client),
this.chain(new GeoSearchStoreCommand(args, this.commandOptions)),

/**
* @see https://redis.io/commands/json.get
Expand Down
24 changes: 12 additions & 12 deletions pkg/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {
FlushDBCommand,
GeoAddCommand,
GeoDistCommand,
GeoSearchStoreCommand,
GeoSearchCommand,
GeoHashCommand,
GeoPosCommand,
GeoSearchCommand,
GeoSearchStoreCommand,
GetBitCommand,
GetCommand,
GetDelCommand,
Expand Down Expand Up @@ -362,8 +362,8 @@ export class Redis {
use = <TResult = unknown>(
middleware: (
r: UpstashRequest,
next: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>
) => Promise<UpstashResponse<TResult>>
next: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>,
) => Promise<UpstashResponse<TResult>>,
) => {
const makeRequest = this.client.request.bind(this.client);
this.client.request = (req: UpstashRequest) => middleware(req, makeRequest) as any;
Expand Down Expand Up @@ -446,7 +446,7 @@ export class Redis {
...sourceKeys: string[]
) =>
new BitOpCommand([op as any, destinationKey, sourceKey, ...sourceKeys], this.opts).exec(
this.client
this.client,
);

/**
Expand Down Expand Up @@ -626,12 +626,12 @@ export class Redis {
<TData extends Record<string, unknown>>(
key: string,
count: number,
withValues: boolean
withValues: boolean,
): Promise<Partial<TData>>;
} = <TData extends string | string[] | Record<string, unknown>>(
key: string,
count?: number,
withValues?: boolean
withValues?: boolean,
) => new HRandFieldCommand<TData>([key, count, withValues] as any, this.opts).exec(this.client);

/**
Expand Down Expand Up @@ -1060,19 +1060,19 @@ export class Redis {
| [
key: string,
opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr,
...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]
...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]],
]
) => {
if ("score" in args[1]) {
return new ZAddCommand<TData>(
[args[0], args[1] as ScoreMember<TData>, ...(args.slice(2) as any)],
this.opts
this.opts,
).exec(this.client);
}

return new ZAddCommand<TData>(
[args[0], args[1] as any, ...(args.slice(2) as any)],
this.opts
this.opts,
).exec(this.client);
};
/**
Expand Down Expand Up @@ -1139,13 +1139,13 @@ export class Redis {
key: string,
min: `(${string}` | `[${string}` | "-" | "+",
max: `(${string}` | `[${string}` | "-" | "+",
opts: { byLex: true } & ZRangeCommandOptions
opts: { byLex: true } & ZRangeCommandOptions,
]
| [
key: string,
min: number | `(${number}` | "-inf" | "+inf",
max: number | `(${number}` | "-inf" | "+inf",
opts: { byScore: true } & ZRangeCommandOptions
opts: { byScore: true } & ZRangeCommandOptions,
]
) => new ZRangeCommand<TData>(args as any, this.opts).exec(this.client);

Expand Down