Skip to content

Commit 90c37bd

Browse files
committed
fix #1739 - add support for number as value in HSET
1 parent 2d2d58d commit 90c37bd

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

packages/client/lib/commands/SET.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { transformArguments } from './SET';
44

55
describe('SET', () => {
66
describe('transformArguments', () => {
7-
it('simple', () => {
7+
it('string', () => {
88
assert.deepEqual(
99
transformArguments('key', 'value'),
1010
['SET', 'key', 'value']
1111
);
1212
});
1313

14+
it('number', () => {
15+
assert.deepEqual(
16+
transformArguments('key', 1),
17+
['SET', 'key', '1']
18+
);
19+
});
20+
1421
describe('TTL', () => {
1522
it('with EX', () => {
1623
assert.deepEqual(

packages/client/lib/commands/SET.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ interface SetCommonOptions {
2424

2525
type SetOptions = SetTTL & SetGuards & SetCommonOptions;
2626

27-
export function transformArguments(key: string | Buffer, value: string | Buffer, options?: SetOptions): RedisCommandArguments {
28-
const args = ['SET', key, value];
29-
30-
if (!options) {
31-
return args;
32-
}
33-
34-
if (options.EX) {
27+
export function transformArguments(key: string | Buffer, value: string | number | Buffer, options?: SetOptions): RedisCommandArguments {
28+
const args = [
29+
'SET',
30+
key,
31+
typeof value === 'number' ? value.toString() : value
32+
];
33+
34+
if (options?.EX) {
3535
args.push('EX', options.EX.toString());
36-
} else if (options.PX) {
36+
} else if (options?.PX) {
3737
args.push('PX', options.PX.toString());
38-
} else if (options.EXAT) {
38+
} else if (options?.EXAT) {
3939
args.push('EXAT', options.EXAT.toString());
40-
} else if (options.PXAT) {
40+
} else if (options?.PXAT) {
4141
args.push('PXAT', options.PXAT.toString());
42-
} else if (options.KEEPTTL) {
42+
} else if (options?.KEEPTTL) {
4343
args.push('KEEPTTL');
4444
}
4545

46-
if (options.NX) {
46+
if (options?.NX) {
4747
args.push('NX');
48-
} else if (options.XX) {
48+
} else if (options?.XX) {
4949
args.push('XX');
5050
}
5151

52-
if (options.GET) {
52+
if (options?.GET) {
5353
args.push('GET');
5454
}
5555

0 commit comments

Comments
 (0)