donglu1973 2015-04-14 17:01 采纳率: 100%
浏览 88

使用memcache,redis抛出异常:连接时读取错误

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型