Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/commands/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)

Expand Down
11 changes: 11 additions & 0 deletions test/integration/commands/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down