node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Watch with failed transaction causes failure in other calls (code included). if anyone can reproduce and confirm if I'm doing something wrong?

Open SafwanHak opened this issue 13 years ago • 2 comments

Hello,

I have an issue where a watch with failed transaction would cause next callbacks to break. Steps and code included below. Basically, one callback is lost and another callback displays the wrong result. Only fails when transaction fails.


/*
Scenario:
- setting anotherVar to 200
- preparing a watch scenario for 'test' that we expect to fail because it's incremented outside of transaction.
    on failure of transaction, we retrieve the value of 'anotherVar', it should return 200.
- while transaction is running another key is being set test-9999
- the result of test-9999 is that of the get of 'anotherVar', NOT THE SET.

when executed the result :
 reply to set of test-9999 should be 9999 but returns 200 { '0': null, '1': '200' }

 */

var redis = require( "redis" ),
client = redis.createClient(), set_size = 20;

//a variable to test that is unrelated to watch
client.set('anotherVar', 200);

var name = 'test';
client.watch(name);
client.incr(name); //cause transcation to fail on purpose
multi = client.multi();
multi.incr(name);
multi.exec(function(err, replies)
{
    //expected to fail

    //read another var here.
    client.get( 'anotherVar', function()
    {
        //this code never executes
        console.log( 'result for another after failed transaction should be 200', arguments );
    } );
});

//set the value
client.set('test-9999', 9999, function(err, replies)
{
       //this code is execute but with the result of client.get('anotherVar')
    console.log('reply to set of test-9999 should be 9999 but returns 200', arguments);
});

SafwanHak avatar Dec 17 '12 23:12 SafwanHak

@SafwanHak did u try this with hiredis parser instead of the JS one ? seems to be related (or possibly have the same underlying problem) to my issue #364

kessler avatar Jan 12 '13 20:01 kessler

The code works with hiredis as @yanush guessed.

javascript parser

reply to set of test-9999 should be 9999 but returns 200 { '0': null, '1': '200' }

hiredis

reply to set of test-9999 should be 9999 but returns 200 { '0': null, '1': 'OK' }
result for another after failed transaction should be 200 { '0': null, '1': '200' }

(Note: the first line is working, the comment is wrong -- SET returns "OK" not the value set.)

brycebaril avatar Feb 04 '13 07:02 brycebaril