You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
fix #1739 - add support for number as value in HSET
This commit is contained in:
@ -4,13 +4,20 @@ import { transformArguments } from './SET';
|
|||||||
|
|
||||||
describe('SET', () => {
|
describe('SET', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('string', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', 'value'),
|
transformArguments('key', 'value'),
|
||||||
['SET', 'key', 'value']
|
['SET', 'key', 'value']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('number', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key', 1),
|
||||||
|
['SET', 'key', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe('TTL', () => {
|
describe('TTL', () => {
|
||||||
it('with EX', () => {
|
it('with EX', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
@ -24,32 +24,32 @@ interface SetCommonOptions {
|
|||||||
|
|
||||||
type SetOptions = SetTTL & SetGuards & SetCommonOptions;
|
type SetOptions = SetTTL & SetGuards & SetCommonOptions;
|
||||||
|
|
||||||
export function transformArguments(key: string | Buffer, value: string | Buffer, options?: SetOptions): RedisCommandArguments {
|
export function transformArguments(key: string | Buffer, value: string | number | Buffer, options?: SetOptions): RedisCommandArguments {
|
||||||
const args = ['SET', key, value];
|
const args = [
|
||||||
|
'SET',
|
||||||
|
key,
|
||||||
|
typeof value === 'number' ? value.toString() : value
|
||||||
|
];
|
||||||
|
|
||||||
if (!options) {
|
if (options?.EX) {
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.EX) {
|
|
||||||
args.push('EX', options.EX.toString());
|
args.push('EX', options.EX.toString());
|
||||||
} else if (options.PX) {
|
} else if (options?.PX) {
|
||||||
args.push('PX', options.PX.toString());
|
args.push('PX', options.PX.toString());
|
||||||
} else if (options.EXAT) {
|
} else if (options?.EXAT) {
|
||||||
args.push('EXAT', options.EXAT.toString());
|
args.push('EXAT', options.EXAT.toString());
|
||||||
} else if (options.PXAT) {
|
} else if (options?.PXAT) {
|
||||||
args.push('PXAT', options.PXAT.toString());
|
args.push('PXAT', options.PXAT.toString());
|
||||||
} else if (options.KEEPTTL) {
|
} else if (options?.KEEPTTL) {
|
||||||
args.push('KEEPTTL');
|
args.push('KEEPTTL');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.NX) {
|
if (options?.NX) {
|
||||||
args.push('NX');
|
args.push('NX');
|
||||||
} else if (options.XX) {
|
} else if (options?.XX) {
|
||||||
args.push('XX');
|
args.push('XX');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.GET) {
|
if (options?.GET) {
|
||||||
args.push('GET');
|
args.push('GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user