Question

can predis use array as 2nd parameter of hmget() to retrieve multiple fields on one go? e.g. $client->hmget($key, $fields); //$fields is an array

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

Était-ce utile?

La solution

Predis supports two ways of passing multiple keys (or keys with values) for variadic Redis commands. The first one basically follows the same signature of commands as defined by the Redis documentation, so using HMSET and HMGET as examples you will have:

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

but you can also pass the list of keys and/or values as a single array argument:

$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 really just a matter of preference.

Autres conseils

From Predis repository

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

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

You can try this:

$pd =  $redis->hmget("regconfig" ,array("cont_mgr"));
print_r($pd);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top