1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00
Files
node-redis/lib/commands/SET.ts
Leibale Eidelman e592d9403d v4.0.0-rc.2 (#1664)
* 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>
2021-09-23 16:36:40 -04:00

78 lines
1.4 KiB
TypeScript

import { TransformArgumentsReply } from '.';
export const FIRST_KEY_INDEX = 1;
interface EX {
EX: number;
}
interface PX {
PX: number
}
interface EXAT {
EXAT: number;
}
interface PXAT {
PXAT: number;
}
interface KEEPTTL {
KEEPTTL: true;
}
type SetTTL = EX | PX | EXAT | PXAT | KEEPTTL | {};
interface NX {
NX: true;
}
interface XX {
XX: true;
}
type SetGuards = NX | XX | {};
interface SetCommonOptions {
GET: true
}
type SetOptions = SetTTL & SetGuards & (SetCommonOptions | {});
export function transformArguments(key: string | Buffer, value: string | Buffer, options?: SetOptions): TransformArgumentsReply {
const args = ['SET', key, value];
if (!options) {
return args;
}
if ('EX' in options) {
args.push('EX', options.EX.toString());
} else if ('PX' in options) {
args.push('PX', options.PX.toString());
} else if ('EXAT' in options) {
args.push('EXAT', options.EXAT.toString());
} else if ('PXAT' in options) {
args.push('PXAT', options.PXAT.toString());
} else if ((<KEEPTTL>options).KEEPTTL) {
args.push('KEEPTTL');
}
if ((<NX>options).NX) {
args.push('NX');
} else if ((<XX>options).XX) {
args.push('XX');
}
if ((<SetCommonOptions>options).GET) {
args.push('GET');
}
return args;
}
export function transformReply(reply?: string): string | null {
return reply ?? null;
}