I am using predis and everything was great until I started getting this error:
ERR Protocol error: invalid bulk length
I am not sure why I am getting it. The error is in this file: Predis/Network/StreamConnection.php in this method:
public function writeCommand(ICommand $command) {
$commandId = $command->getId();
$arguments = $command->getArguments();
$cmdlen = strlen($commandId);
$reqlen = count($arguments) + 1;
$buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";
for ($i = 0; $i < $reqlen - 1; $i++) {
$argument = $arguments[$i];
$arglen = strlen($argument);
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}
$this->writeBytes($buffer);
}
It fails when it tries to do an strlen() on an array.
Here is the code that is causing this to fail:
$ids = array(1, 2, 3);
$predis = new Predis\Client();
$predis->set('testerKey', $ids);
Am I not allowed to set an array? Of course I can set an array. The only thing I changed was I make my files UTF-8 so maybe that screwed something up?
Any help would be appreciated.
I found the problem and a solution. Coming from memcached where it will serialize the array automatically this is not the same in PRedis. PRedis will never serialize anything when performing a set or get.