Skip to content

Commit

Permalink
feat: add setnxBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent 81abd47 commit e064075
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
1 change: 0 additions & 1 deletion compat.md
Expand Up @@ -252,7 +252,6 @@
- [sdiffBuffer][1]
- [sdiffstoreBuffer][1]
- [setbitBuffer][1]
- [setnxBuffer][1]
- [sinterBuffer][1]
- [sinterstoreBuffer][1]
- [sismemberBuffer][1]
Expand Down
1 change: 0 additions & 1 deletion jest.config.redis.js
Expand Up @@ -66,7 +66,6 @@ module.exports = {
'test/integration/commands/sdiff.js',
'test/integration/commands/sdiffstore.js',
'test/integration/commands/setbit.js',
'test/integration/commands/setnx.js',
'test/integration/commands/sinter.js',
'test/integration/commands/sinterstore.js',
'test/integration/commands/sismember.js',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/setnx.js
Expand Up @@ -7,3 +7,5 @@ export function setnx(key, val) {

return 0
}

export const setnxBuffer = setnx
34 changes: 16 additions & 18 deletions test/integration/commands/setnx.js
@@ -1,22 +1,20 @@
import Redis from 'ioredis'

describe('setnx', () => {
it('should set a key with value if it does not exist already', () => {
const redis = new Redis()
return redis
.setnx('foo', 'bar')
.then(status => {
return expect(status).toBe(1)
})
.then(() => {
expect(redis.data.get('foo')).toBe('bar')
return redis.setnx('foo', 'baz')
})
.then(status => {
return expect(status).toBe(0)
})
.then(() => {
expect(redis.data.get('foo')).toBe('bar')
})
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

runTwinSuite('setnx', command => {
describe(command, () => {
it('should set a key with value if it does not exist already', async () => {
const redis = new Redis()

expect(await redis[command]('foo', 'bar')).toBe(1)
expect(await redis.get('foo')).toBe('bar')

expect(await redis[command]('foo', 'baz')).toBe(0)
expect(await redis.get('foo')).not.toBe('baz')

redis.disconnect()
})
})
})

0 comments on commit e064075

Please sign in to comment.