Search code examples
phpsymfonyredisphpredis

PHPRedis and SMEMBERS


I'm trying some stuff with Redis and PHP, and I've encountered a problem when it came to work with SETS and SMEMBERS.

I'm using Symfony2 and SncRedisBundle.

$redis->multi();
// Some stuff
$result = $redis->smembers("myset");
var_dump($result);
die();
$redis->exec();

Here's the dump

object(Redis)[990]
  public 'socket' => resource(841, Redis Socket Buffer)

I'm a bit stuck now, I don't know how I can work with the result since there's nothing really visible or explained on php-redis documentation.

Can someone help me?


Solution

  • You should check the result of $redis->exec() instead of the result of smembers. The principle of MULTI/EXEC blocks is that command executions are delayed until the EXEC command. At this point, all commands are executed atomically and their results are sent back to the client.

    See this example: https://github.com/nicolasff/phpredis#transactions

    Note that using a MULTI/EXEC block with just one command inside is pointless and does not bring any benefits.