Rectangle 27 0

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"));

php - can predis hmget use array as parameter of multiple fields - Sta...

php redis predis
Rectangle 27 0

foreach ($userIndexArr as $row) {
    $usernames[$row['username']] = 0; 
try {
    $result = $this->cache->zadd('@person', $usernames);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";

Untested, though. But I think it works, as long as you're using v1.0 =)

I tried this but no luck. Still using the zadd in for loop. Is there a way to do this using execute raw?

Check you Predis version, also issue a MONITOR in redis-cli to check what is the current command your code is sending.

So, have you checked monitor command to see what's being output ? Also please tell me your Predis version.

Hi, very sorry for the late reply. Had something a workaround so had to move on. Tried your code as is and it worked like a charm. Many thanks!

php - Predis - how to use array with zadd function? - Stack Overflow

php caching redis predis
Rectangle 27 0

$redis->zincrby('myzset', 2. "one")

I found this later indeed, the docs not being up to date is a major pain. Thanks.

php - How to use ZINCRBY with predis - Stack Overflow

php redis predis
Rectangle 27 0

// Prepare an hash with some fields and their respective values.
$client->hmset('metavars', array('foo' => 'bar', 'hoge' => 'piyo', 'lol' => 'wut'));

Perhaps, make sure you use strings and not integers ...

Error was in connection to redis. Thx for answers :)

php - Problems with using hmset in Predis - Stack Overflow

php redis predis
Rectangle 27 0

To use SCAN to search for matching keys in a database, you simply use the Predis\Collection\Iterator\Keyspace class:

use Predis\Collection\Iterator;

$client = ...;
$pattern = 'foo*';

foreach (new Iterator\Keyspace($client, $pattern) as $key) {

Apparently Predis has an iterator class in Predis\Collection\Iterator for each of the commands that return iterators:


php - How to use SCAN with the MATCH option in Predis - Stack Overflow

php redis predis
Rectangle 27 0

Looks like you just erred in passing parameters in this library. Its looks like it should be

$redis->bitop('OR','ONLINE', $key1, $key2);

While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.

redis - Cannot Use BITOP in Predis PHP - Stack Overflow

php redis predis
Rectangle 27 0

I use below code to connect predis on php page, and it worked fine.. below is code

        require "predis/autoloader.php";
        $redis = new Predis\Client();
        $redis = new Predis\Client(array(
         "scheme" => "tcp",
         "host" => "",
         "port" => 6379));

redis - Trouble loading predis on php website - Stack Overflow

php redis predis
Rectangle 27 0

You got that error when using lpush because the flavors key is already stored with a different Redis data type. So you should delete that key before you try again.

You also used lpush in wrong way. You should try this:

foreach ($array as $value) {
    $redis->lpush($list, $value);
call_user_func_array(array($redis, 'lpush'), array_merge($list, $array));

If you want to store flavors by mainid, you may want to store it with multi keys and use lpush:

$list = "flavor:{$_GET['mainid']}";
$redis->lpush($list, $_GET["flavor1"]);
$redis->lpush($list, $_GET["flavor2"]);
$redis->lpush($list, $_GET["flavor3"]);

Another way is to store in a single hash and using json_encode (don't use implode):

$data = json_encode(array($_GET["flavor1"], $_GET["flavor2"], $_GET["flavor3"]));
$redis->hset('flavors', $_GET["mainid"], $data);

thanks, using json_encode and the hash worked for me.

php - Using Predis to store form data - Stack Overflow

php redis predis