Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predis transactions not supported? #74

Open
tarjei opened this issue Oct 30, 2018 · 3 comments
Open

Predis transactions not supported? #74

tarjei opened this issue Oct 30, 2018 · 3 comments

Comments

@tarjei
Copy link

tarjei commented Oct 30, 2018

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
Copy link
Contributor

omansour commented Oct 30, 2018

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

@tarjei
Copy link
Author

tarjei commented Oct 30, 2018 via email

@tarjei
Copy link
Author

tarjei commented Oct 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants