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);
}
Or if your redis api support multi params:
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);