diff --git a/src/commands/set.js b/src/commands/set.js index 78c50824..5cc1ab31 100644 --- a/src/commands/set.js +++ b/src/commands/set.js @@ -10,11 +10,14 @@ function createGroupedArray(arr, groupSize) { } export function set(key, value, ...options) { - const nx = options.indexOf('NX') !== -1 - const xx = options.indexOf('XX') !== -1 - const get = options.indexOf('GET') !== -1 + const normalizedOptions = options.map(option => + typeof option === 'string' ? option.toUpperCase() : option + ) + const nx = normalizedOptions.indexOf('NX') !== -1 + const xx = normalizedOptions.indexOf('XX') !== -1 + const get = normalizedOptions.indexOf('GET') !== -1 - const filteredOptions = options.filter( + const filteredOptions = normalizedOptions.filter( option => option !== 'NX' && option !== 'XX' ) diff --git a/test/integration/commands/set.js b/test/integration/commands/set.js index d21cd397..586ddc3a 100644 --- a/test/integration/commands/set.js +++ b/test/integration/commands/set.js @@ -40,6 +40,17 @@ runTwinSuite('set', (command, equals) => { redis.disconnect() }) + it('should handle expiration options case-insensitively', async () => { + const redis = new Redis() + + expect(equals(await redis[command]('foo', 'bar', 'ex', 10), 'OK')).toBe( + true + ) + expect(await redis.get('foo')).toBe('bar') + expect(await redis.ttl('foo')).toBeGreaterThanOrEqual(1) + redis.disconnect() + }) + it('should set value and expire with PX', async () => { const redis = new Redis()