RedisMock icon indicating copy to clipboard operation
RedisMock copied to clipboard

Predis transactions not supported?

Open tarjei opened this issue 6 years ago • 3 comments

Hi, I thought Predis transactions were supported - is that not correct?

Here's the code I was trying to test:

function fetchMessages($redisClient) {
        $messages = $redisClient->zrevrangebyscore('myqueue', time(), 0);
        $queueId = 'myqueue';

        foreach ($messages as $message) {
            $dmes = json_decode($message, true);
            $redisClient->transaction(
                function ($tx) use ($dmes, $queueId, $message) {
                    $tx->zrem($queueId, $message);
                    $tx->rpush($dmes['destination'], json_encode($dmes['message']));
                }
            );
        }

}

And the test:

function testMyRedisQueue() {
$factory = new \M6Web\Component\RedisMock\RedisMockFactory();
        $redis = $factory->getAdapter('Predis\Client', true, false, '', [
           [ 'profile' => '3.0']
        ]);

  $message = json_encode(['destination'=>'tq1', 'message' => ['key' => 'v'], 'timestamp' =>  new \DateTimeImmutable('now - 3 hours')->getTimestamp()]);
        $redis->zadd('myqueue',  \DateTimeImmutable('now - 3 hours')->getTimestamp(), $message);

        $this->assertEquals(0, $redis->llen('tq1'));

       fetchMessages($redis); 
  
       $this->assertEquals(1, $this->redis->llen('tq1'));

}

I have isolated the problem to the code within the transaction call. If I run it outside the transaction then the test works. Any ideas on how to fix this?

tarjei avatar Oct 30 '18 08:10 tarjei

Hey @tarjei , indeed, transaction aren't supported in RedisMock. Feel free to propose something if you want to improve.

omansour avatar Oct 30 '18 14:10 omansour

OK, I thought this sentence in the readme would let me test the transaction code:

'It mocks MULTI, DISCARD and EXEC commands but without any transaction behaviors, they just make the interface fluent and return each command results. PIPELINE and EXECUTE pseudo commands (client pipelining) are also mocked.' T

Den tir. 30. okt. 2018 kl. 15:15 skrev Olivier Mansour < [email protected]>:

Hey @tarjei https://github.com/tarjei , indeed, transaction aren't supported.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/M6Web/RedisMock/issues/74#issuecomment-434317985, or mute the thread https://github.com/notifications/unsubscribe-auth/AAM5P897fn2da7_E_Nn2swc9Yq4KGtd3ks5uqF8TgaJpZM4YBbX6 .

--


Tarjei Huse Mobil: 920 63 413

tarjei avatar Oct 30 '18 14:10 tarjei

I didn't expect a transaction, just that the commands happened.

Den tir. 30. okt. 2018 kl. 15:17 skrev Tarjei Huse [email protected]:

OK, I thought this sentence in the readme would let me test the transaction code:

'It mocks MULTI, DISCARD and EXEC commands but without any transaction behaviors, they just make the interface fluent and return each command results. PIPELINE and EXECUTE pseudo commands (client pipelining) are also mocked.' T

Den tir. 30. okt. 2018 kl. 15:15 skrev Olivier Mansour < [email protected]>:

Hey @tarjei https://github.com/tarjei , indeed, transaction aren't supported.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/M6Web/RedisMock/issues/74#issuecomment-434317985, or mute the thread https://github.com/notifications/unsubscribe-auth/AAM5P897fn2da7_E_Nn2swc9Yq4KGtd3ks5uqF8TgaJpZM4YBbX6 .

--


Tarjei Huse Mobil: 920 63 413

--


Tarjei Huse Mobil: 920 63 413

tarjei avatar Oct 30 '18 14:10 tarjei