Skip to content

Commit

Permalink
add renamenx (stipsan#152)
Browse files Browse the repository at this point in the history
* add renamenx

* update preversion script to auto commit compat table updates

* chore(compat): update feature table

* 1.9.1

* fix quotes

* update script

* chore(compat): update feature table

* 1.10.0
  • Loading branch information
stipsan authored Oct 1, 2016
1 parent 73dab3e commit 7137cba
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
|[readonly](http://redis.io/commands/READONLY)|:white_check_mark:|:x:|
|[readwrite](http://redis.io/commands/READWRITE)|:white_check_mark:|:x:|
|[rename](http://redis.io/commands/RENAME)|:white_check_mark:|:white_check_mark:|
|[renamenx](http://redis.io/commands/RENAMENX)|:white_check_mark:|:x:|
|[renamenx](http://redis.io/commands/RENAMENX)|:white_check_mark:|:white_check_mark:|
|[replconf](http://redis.io/commands/REPLCONF)|:white_check_mark:|:x:|
|[restore](http://redis.io/commands/RESTORE)|:white_check_mark:|:x:|
|[restore-asking](http://redis.io/commands/RESTORE-ASKING)|:white_check_mark:|:x:|
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "ioredis-mock",
"version": "1.9.0",
"version": "1.10.0",
"description": "This library emulates ioredis by performing all operations in-memory.",
"main": "./lib",
"scripts": {
"clean": "rimraf lib",
"prepublish": "npm run clean && npm run build",
"preversion": "node scripts/update-compat",
"preversion": "node scripts/update-compat && git add . && git commit --allow-empty -m \"chore(compat): update feature table\"",
"build": "mkdirp lib && babel src --out-dir lib",
"build:watch": "npm run build -- --watch",
"test": "mocha --compilers js:babel-register --recursive",
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './lrem';
export * from './mget';
export * from './publish';
export * from './rename';
export * from './renamenx';
export * from './rpoplpush';
export * from './rpush';
export * from './sadd';
Expand Down
11 changes: 11 additions & 0 deletions src/commands/renamenx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { rename } from './rename';

export function renamenx(key, newKey) {
if ({}.hasOwnProperty.call(this.data, newKey)) {
return '0';
}

rename.call(this, key, newKey);

return '1';
}
26 changes: 26 additions & 0 deletions test/commands/renamenx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import expect from 'expect';

import MockRedis from '../../src';

describe('renamenx', () => {
it('should return integer 1 on key rename', () => {
const redis = new MockRedis({
data: {
foo: 'baz',
},
});
return redis.renamenx('foo', 'bar').then(status => expect(status).toBe('1'))
.then(() => expect(redis.data).toEqual({ bar: 'baz' }));
});

it('should return integer 0 if new key already exist', () => {
const redis = new MockRedis({
data: {
foo: 'baz',
bar: 'foobar',
},
});
return redis.renamenx('foo', 'bar').then(status => expect(status).toBe('0'))
.then(() => expect(redis.data).toEqual({ foo: 'baz', bar: 'foobar' }));
});
});

0 comments on commit 7137cba

Please sign in to comment.