Predis pipelined HGET

548 views
Skip to first unread message

Xiangrong Fang

unread,
May 30, 2011, 5:51:19 AM5/30/11
to redis-db
Hi there,

I try to use the following code to do a pipelined HGET, but the result is complicated Predis Object, not a list of values I need:

<?
//g1~g3 are HASH with a field called tie.
$conn = new Predis\Client();
$pipe = $conn->pipeline();
$pipe->hget('g1', 'tie');
$pipe->hget('g2', 'tie');
$pipe->hget('g3', 'tie');
$res = $pipe->exec();
print_r($res);
?>

How can I do this correctly?

Thanks,
Shannon

Dvir Volk

unread,
May 30, 2011, 5:59:29 AM5/30/11
to redi...@googlegroups.com
another option would be to use the SORT command, not sure about the predis syntax, but suppose you have a list, set or zset containing the hash keys you need (you can always create one if you want), you can do:

(say a key named "lst" contains the values 1,2,3)
do:
> SORT lst BY nosort GET g*->tie

and get a list of the hash values.



--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Daniele Alessandri

unread,
May 30, 2011, 7:02:55 AM5/30/11
to redi...@googlegroups.com
On Mon, May 30, 2011 at 11:51, Xiangrong Fang <xrf...@gmail.com> wrote:

> Hi there,
>
> I try to use the following code to do a pipelined HGET, but the result is
> complicated Predis Object, not a list of values I need:

[...]
> $res = $pipe->exec();

You are calling the wrong method: $pipe->exec() enqueues the Redis
EXEC command into the pipeline (and returns the current pipeline
instance), when you want to send the enqueued commands to the server
and get the result array you must call $pipe->execute().

Cheers,
Daniele

--
Daniele Alessandri
http://clorophilla.net/
http://twitter.com/JoL1hAHN

Xiangrong Fang

unread,
May 30, 2011, 8:47:33 AM5/30/11
to redi...@googlegroups.com
Thanks Daniele,  the exec() is not necessary anyway, I just call execute(), right?

2011/5/30 Daniele Alessandri <suppa...@gmail.com>

Salvatore Sanfilippo

unread,
May 30, 2011, 8:51:22 AM5/30/11
to redi...@googlegroups.com
On Mon, May 30, 2011 at 2:47 PM, Xiangrong Fang <xrf...@gmail.com> wrote:
> Thanks Daniele,  the exec() is not necessary anyway, I just call execute(),
> right?

You did not called multi, so you don't want exec as well.
If I understand correctly you are just interested in the pipelining,
not the atomicity of the multi hget operations.
So no exec() needed :)

Salvatore

--
Salvatore 'antirez' Sanfilippo
open source developer - VMware

http://invece.org
"We are what we repeatedly do. Excellence, therefore, is not an act,
but a habit." -- Aristotele

Daniele Alessandri

unread,
May 30, 2011, 9:53:03 AM5/30/11
to redi...@googlegroups.com
On Mon, May 30, 2011 at 14:47, Xiangrong Fang <xrf...@gmail.com> wrote:

> Thanks Daniele,  the exec() is not necessary anyway, I just call execute(),
> right?

Yes, exec() is only needed if you have previously issued a multi() command.

PS: when using pipelines with anonymous blocks (which is not your case
judging by the example you gave), you don't need to call execute() as
it is called implicitly by Predis.

Reply all
Reply to author
Forward
0 new messages