Skip to content

Predis transactions not supported? #74

@tarjei

Description

@tarjei

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions