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

fix #1660 - add support for client.HSET('key', 'field', 'value')

This commit is contained in:
leibale
2021-09-20 18:59:42 -04:00
parent 10b9c59e0f
commit 3a169d5e35
2 changed files with 19 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import { TransformArgumentsReply } from '.';
import { transformReplyString } from './generic-transformers';
type HSETObject = Record<string | number, string | number>;
@@ -8,10 +9,18 @@ type HSETTuples = Array<[string, string]> | Array<string>;
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, value: HSETObject | HSETMap | HSETTuples): Array<string> {
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): TransformArgumentsReply {
const args = ['HSET', key];
if (value instanceof Map) {
if (typeof value === 'string') {
args.push(value, fieldValue!);
} else if (value instanceof Map) {
pushMap(args, value);
} else if (Array.isArray(value)) {
pushTuples(args, value);