Skip to content

Commit

Permalink
feat: add msetnxBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent 9f75d21 commit 11bbf35
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion compat.md
Expand Up @@ -233,7 +233,6 @@
- [lsetBuffer][1]
- [ltrimBuffer][1]
- [mgetBuffer][1]
- [msetnxBuffer][1]
- [persistBuffer][1]
- [pexpireBuffer][1]
- [pexpireatBuffer][1]
Expand Down
1 change: 0 additions & 1 deletion jest.config.redis.js
Expand Up @@ -43,7 +43,6 @@ module.exports = {
'test/integration/commands/lset.js',
'test/integration/commands/ltrim.js',
'test/integration/commands/mget.js',
'test/integration/commands/msetnx.js',
'test/integration/commands/persist.js',
'test/integration/commands/pexpire.js',
'test/integration/commands/pexpireat.js',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/msetnx.js
Expand Up @@ -13,3 +13,5 @@ export function msetnx(...msetData) {

return 1
}

export const msetnxBuffer = msetnx
52 changes: 25 additions & 27 deletions test/integration/commands/msetnx.js
@@ -1,33 +1,31 @@
import Redis from 'ioredis'

describe('msetnx', () => {
it('should batch set values', () => {
const redis = new Redis()
return redis
.msetnx('key1', 'Hello', 'key2', 'World')
.then(status => {
return expect(status).toBe(1)
})
.then(() => {
expect(redis.data.get('key1')).toBe('Hello')
expect(redis.data.get('key2')).toBe('World')
})
})
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

runTwinSuite('msetnx', command => {
describe(command, () => {
it('should batch set values', async () => {
const redis = new Redis()

expect(await redis[command]('key1', 'Hello', 'key2', 'World')).toBe(1)

expect(await redis.get('key1')).toBe('Hello')
expect(await redis.get('key2')).toBe('World')

redis.disconnect()
})

it('should bail on batch set values if just one key exists', async () => {
const redis = new Redis()
await redis.set('key1', 'Nope')

expect(await redis[command]('key1', 'Hello', 'key2', 'World')).toBe(0)

expect(await redis.get('key1')).toBe('Nope')
expect(await redis.get('key2')).toBe(null)

it('should bail on batch set values if just one key exists', () => {
const redis = new Redis({
data: {
key1: 'Nope',
},
redis.disconnect()
})
return redis
.msetnx('key1', 'Hello', 'key2', 'World')
.then(status => {
return expect(status).toBe(0)
})
.then(() => {
expect(redis.data.get('key1')).toBe('Nope')
expect(redis.data.has('key2')).toBe(false)
})
})
})

0 comments on commit 11bbf35

Please sign in to comment.