BedrockStreaming / RedisMock

A simple PHP Redis mock
http://tech.m6web.fr/redismock-qui-a-bouchonne-mon-redis.html
MIT License
80 stars 60 forks source link

Predis transactions not supported? #74

Open tarjei opened 5 years ago

tarjei commented 5 years ago

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?

omansour commented 5 years ago

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

tarjei commented 5 years ago

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 < notifications@github.com>:

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 commented 5 years ago

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

Den tir. 30. okt. 2018 kl. 15:17 skrev Tarjei Huse tarjei.huse@gmail.com:

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 < notifications@github.com>:

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