You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
* update workflows & README
* add .deepsource.toml
* fix client.quit, add error events on cluster, fix some "deepsource.io" warnings
* Release 4.0.0-rc.1
* add cluster.duplicate, add some tests
* fix #1650 - add support for Buffer in some commands, add GET_BUFFER command
* fix GET and GET_BUFFER return type
* update FAQ
* Update invalid code example in README.md (#1654)
* Update invalid code example in README.md
* Update README.md
Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
* fix #1652
* ref #1653 - better types
* better types
* fix 54124793ad
* Update GEOSEARCHSTORE.spec.ts
* fix #1660 - add support for client.HSET('key', 'field', 'value')
* upgrade dependencies, update README
* fix #1659 - add support for db-number in client options url
* fix README, remove unused import, downgrade typedoc & typedoc-plugin-markdown
* update client-configurations.md
* fix README
* add CLUSTER_SLOTS, add some tests
* fix "createClient with url" test with redis 5
* remove unused imports
* Release 4.0.0-rc.2
Co-authored-by: Richard Samuelsson <noobtoothfairy@gmail.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { TransformArgumentsReply } from '.';
|
|
import { transformReplyString } from './generic-transformers';
|
|
|
|
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): TransformArgumentsReply {
|
|
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 const transformReply = transformReplyString;
|