Skip to content

Commit

Permalink
Fix equal items add into set
Browse files Browse the repository at this point in the history
  • Loading branch information
aantonovdevelop committed Sep 19, 2016
1 parent b9b6939 commit 2be7307
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/redis.js
Expand Up @@ -71,7 +71,7 @@ function Redis() {
var self = this;

function save_value(arr, value) {
arr.push(value);
if (arr.indexOf(value) < 0) arr.push(value);
}

if (this.store[key]) {
Expand Down
17 changes: 17 additions & 0 deletions test/redis-mock-test.js
Expand Up @@ -135,6 +135,23 @@ describe('Redis', function () {
done();
});
});

it('Should replace old value if equal value is exist', function (done) {
var test_key = 'test_key';
var test_value = 1;

redis.sadd(test_key, test_value, function (error) {
if (error) return done(error);

redis.sadd(test_key, test_value, function (error) {
if (error) return done(error);

assert.equal(redis.store[test_key].length, 1);

done();
});
});
});
});

describe('#smembers', function () {
Expand Down

0 comments on commit 2be7307

Please sign in to comment.