Can predis hmget use array as parameter of multiple fields

Can predis use an array as the second parameter to hmget () to retrieve multiple fields at once? e.g. $ client-> hmget ($ key, $ fields); // $ fields - array

Can I also accept many string parameters as fields? e.g.: $ client-> hmget ($ key, $ field1, $ field2, $ field3);

+3
source share
2 answers

Predis supports two methods for passing multiple keys (or keys with values) for Redis command variables. The first one basically matches the same command signature as in the Redis documentation , so using HMSET and HMGET as examples:

$redis->hmset("hash", "field:1", "value:1", "field:2", "value:2");
$values = $redis->hmget("hash", "field:1", "field:2");

but you can also pass a list of keys and / or values ​​as one argument to an array:

$redis->hmset("hash", array("field:1" => "value:1", "field:2" => "value:2"));
$values = $redis->hmget("hash", array("field:1", "field:2"));

Choosing which one to use is actually a matter of preference.

+5
source

From the Predis Repository

$redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut');

$redis->hmget('metavars', 'foo', 'hoge', 'unknown'));
0
source

All Articles