主页 > 知识库 > 数据库 > NoSQL >

libredis-Redis PHP扩展

来源: 作者: 发表于:2012-08-20 08:41  点击:
libredis 是一个C语言编写的 Redis 客户端函数库,作者在自己的底层库基础上实现了一个PHP版本的Redis客户端。 项目地址: libredis on github 下面是作者给出的两个简单实例: 实例一: $libredis = Libredis();$connection = $libredis->get_connection("1

libredis是一个C语言编写的Redis客户端函数库,作者在自己的底层库基础上实现了一个PHP版本的Redis客户端。

项目地址:libredis on github

下面是作者给出的两个简单实例:

实例一:

$libredis = Libredis();
$connection = $libredis->get_connection("127.0.0.1");
//set a key
$batch = $libredis->create_batch();
$batch->set('hello', 'world');
$batch->execute($connection);
//now fetch the key
$batch = $libredis->create_batch();
$batch->get('hello');
$batch->execute($connection);
while($batch->next_reply($reply_type, $reply_value, $reply_length)) {
      echo $reply_value, PHP_EOL;
}

实例二:(multiple server模式)

$libredis = Libredis();
$connection1 = $libredis->get_connection("127.0.0.1:6379");
$connection2 = $libredis->get_connection("127.0.0.1:6380");
$batch1 = $libredis->create_batch();
$batch1->set('hello', 'world'); //add a 'set' command to batch1
$batch2 = $libredis->create_batch();
$batch2->set('hello2', 'world2');
$executor = $libredis->create_executor();
$executor->add($connection1, $batch1); //associate connection1 with batch1
$executor->add($connection2, $batch2); //associate connection2 with batch2
//execute all batches against their corresponding connections in parallel, with a
//500 ms timeout on the whole operation.
$executor->execute(500);

    有帮助
    (1)
    100%
    没帮助
    (0)
    0%