Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
LREM 0 must remove all matching list elements. fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
hdachev committed Nov 23, 2013
1 parent 93997a5 commit 1a8e870
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,14 +978,14 @@ exports.Backend.prototype =
{
count *= -1;
for ( i = n - 1; i >= 0; i -- )
if ( K.value [ i ] === value && x < count )
if ( K.value [ i ] === value && (!count || x < count) )
{
K.value.splice ( i, 1 );
x ++;
}
}
else for ( i = 0; i < n; i ++ )
if ( K.value [ i ] === value && x < count )
if ( K.value [ i ] === value && (!count || x < count) )
{
K.value.splice ( i, 1 );
i --; n --; x ++;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "name": "fakeredis",
"version": "0.1.2",
"version": "0.1.3",
"description": "Fake redis for testing, works as a drop-in replacement for node_redis",
"keywords": [ "test", "spec", "fake", "redis", "simulated", "implementation", "client" ],
"author": "Hristo Dachev <tutini@gmail.com>",
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ process.stdout.write ( 'testing fakeredis ...\n\n' );

redis.LREM( "lnonex", 1, "what", test( "LREM nonex", null, 0 ) );

redis.LPUSH("lremlist", "a", "b", "b", "a", "b", "b", test("LPUSH", null, 6));
redis.LREM("lremlist", 0, "a", test("LREM 0", null, 2));
redis.LLEN("lremlist", test("LLEN", null, 4));
redis.LREM("lremlist", 0, "b", test("LREM 0", null, 4));
redis.LLEN("lremlist", test("LLEN empty", null, 0));



//// Blocking list commands !
Expand Down

0 comments on commit 1a8e870

Please sign in to comment.