In my project, I want to use redis while using memcached(It's an old system and I donnot want to outright replace memcached).But when I try to push element into a list in redis, I meet exception "read error on connection". I find if connecting memcached before connecting redis, it always throw this exception, but connecting redis firstly can avoid this problem.
ENVIRONMENT: Nginx + php-fpm + PHP 5.3.3 + Redis 2.8.19
Use connect instead of pconnect can fix this exception. But I perfer to use pconnect. Here is my code:
$memCache = new Memcached ('client');
$memCache->addServer('127.0.0.1', '8022');
$memCache->set ('mcKey', 1);
echo $memCache->get('mcKey');
$redis = new Redis();
$redis->pconnect('127.0.0.1', '6379', 1000);
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
try {
$redis->lPush('mykey', 1, 2);
echo 'OK';
} catch (Exception $e) {
echo $e->getMessage();
}
Any problem of the code here?