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

Commit

Permalink
WATCH: increment delrev for keys that exist but expire in the meantime.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdachev committed Nov 21, 2014
1 parent b939c4a commit ce943d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## v0.2.2 - November 21, 2014

* Bugfix: WATCH for keys that do not yet exist.

## v0.2.1 - August 22, 2014

* Added extended SET parameters [EX/PX/NX/XX]

## v0.2.0 - April 25, 2014

* Support for `detect_buffers` and `return_buffers`.
Expand Down
14 changes: 8 additions & 6 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ exports.Backend = function() {
if (key === undefined)
throw new Error("WOOT! key param for getKey is undefined.");

if (!entry || entry.expire < Date.now()) {
delete state[key];
delrev[key] = rev;
entry = null;
if (entry) {
if (entry.expire < Date.now()) {
delete state[key];
delrev[key] = ++rev;
entry = null;
}
else if (!(entry.value instanceof VALID_TYPE))
throw new Error("WOOT! keyspace entry value is not a valid Type.");
}
else if (!(entry.value instanceof VALID_TYPE))
throw new Error("WOOT! keyspace entry value is not a valid Type.");

if (Type) {
if (entry && !(entry.value instanceof Type))
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.2.1",
"version": "0.2.2",
"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
7 changes: 3 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,14 @@ process.stdout.write ( 'testing fakeredis ...\n\n' );
( function ()
{
var multi,
redis = fake.createClient ( "transactions-1" ),
redis2 = fake.createClient ( "transactions-1" );
redis = fake.createClient("transactions-3");

redis.WATCH ( "abc" );
redis.GET( "abc" );
multi = redis.MULTI ();
multi.SET ( "abc", "dfgdfg" );
multi.exec ( test("EXEC succeeds", null, ['OK'] ) );
redis.GET ( "abc", test ( "GET succeeds", null, "dfgdfg" ) );
multi.exec ( test("WATCH NONEX EXEC succeeds", null, ['OK'] ) );
redis.GET ( "abc", test ( "WATCH NONEX GET succeeds", null, "dfgdfg" ) );
}
() );

Expand Down

0 comments on commit ce943d3

Please sign in to comment.