You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
use dockers for tests, use npm workspaces, add rejson & redisearch modules, fix some bugs
This commit is contained in:
49
packages/client/lib/commands/HSET.ts
Normal file
49
packages/client/lib/commands/HSET.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
|
||||
type HSETObject = Record<string | number, string | number>;
|
||||
|
||||
type HSETMap = Map<string | number, string | number>;
|
||||
|
||||
type HSETTuples = Array<[string, string]> | Array<string>;
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
type GenericArguments = [key: string];
|
||||
|
||||
type SingleFieldArguments = [...generic: GenericArguments, field: string, value: string];
|
||||
|
||||
type MultipleFieldsArguments = [...generic: GenericArguments, value: HSETObject | HSETMap | HSETTuples];
|
||||
|
||||
export function transformArguments(...[ key, value, fieldValue ]: SingleFieldArguments | MultipleFieldsArguments): RedisCommandArguments {
|
||||
const args = ['HSET', key];
|
||||
|
||||
if (typeof value === 'string') {
|
||||
args.push(value, fieldValue!);
|
||||
} else if (value instanceof Map) {
|
||||
pushMap(args, value);
|
||||
} else if (Array.isArray(value)) {
|
||||
pushTuples(args, value);
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
pushObject(args, value);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
function pushMap(args: Array<string>, map: HSETMap): void {
|
||||
for (const [key, value] of map.entries()) {
|
||||
args.push(key.toString(), value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
function pushTuples(args: Array<string>, tuples: HSETTuples): void {
|
||||
args.push(...tuples.flat());
|
||||
}
|
||||
|
||||
function pushObject(args: Array<string>, object: HSETObject): void {
|
||||
for (const key of Object.keys(object)) {
|
||||
args.push(key.toString(), object[key].toString());
|
||||
}
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
Reference in New Issue
Block a user