subscribe callback function can't reuse the redis connection #322

Closed
gaecom opened this Issue Mar 28, 2013 · 2 comments

Projects

None yet

3 participants

@gaecom
gaecom commented Mar 28, 2013

$r->subscribe(array("comment'), function($r, $chan, $msg) {
global $user;

if($chan=='comment')
{
    $k="abc";
    $res=$r->get($key);

    //$res always return false,but the key did exist

}

@nicolasff
Contributor

Hello,

This is a limitation of Redis, not phpredis: http://redis.io/commands/subscribe :

Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE and PUNSUBSCRIBE commands.

@michael-grunder
Member

You could use the new introspection methods to attain a new connection to redis, based on the passed in Redis object though.

e.g.

sub_func($r,$chan,$msg) {
    $r2 = new Redis();
    $r2->connect($r->GetHost(),$r->GetPort());
    if($chan=='comment') {
        $r2->rpush('something',$msg); 
    }
}
@nicolasff nicolasff closed this Apr 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment