PHP中利用Redis管道加快执行
2015-01-31 12:56
176 查看
$redis->muti($mode)->get($key)->set($key)->exec();
既然是这样的, 也就是说当我要使用管道执行一万次操作的时候需要写一万次操作在muti()的后面,,,还是我找到更好的写法?
设计者没有想到这个问题么?今天测试成功了
[php] view plaincopy
<?
php $redis = new Redis();
$redis->connect('10.1.132.86', 6379);
$pipe = $redis->multi(Redis::PIPELINE);
for ($i = 0; $i < 10000; $i++) {
$pipe->set("key::$i", str_pad($i, 4, '0', 0));
$pipe->get("key::$i");
}
$replies = $pipe->exec(); echo " "; print_r($replies);
Description: Enter and exit transactional mode.
Parameters
(optional)
Return value
Example
##############
简单数据mget也可以实现
Parameters
Array: Array containing the list of the keys
Return value
Array: Array containing the values related to keys in argument
Examples
既然是这样的, 也就是说当我要使用管道执行一万次操作的时候需要写一万次操作在muti()的后面,,,还是我找到更好的写法?
设计者没有想到这个问题么?今天测试成功了
[php] view plaincopy
<?
php $redis = new Redis();
$redis->connect('10.1.132.86', 6379);
$pipe = $redis->multi(Redis::PIPELINE);
for ($i = 0; $i < 10000; $i++) {
$pipe->set("key::$i", str_pad($i, 4, '0', 0));
$pipe->get("key::$i");
}
$replies = $pipe->exec(); echo " "; print_r($replies);
Description: Enter and exit transactional mode.
Parameters
(optional)
Redis::MULTIor
Redis::PIPELINE. Defaults to
Redis::MULTI. A
Redis::MULTIblock of commands runs as a single transaction; a
Redis::PIPELINEblock is simply transmitted faster to the server, but without any guarantee of atomicity.
discardcancels a transaction.
Return value
multi()returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until
exec()is called.
Example
$ret = $redis->multi() ->set('key1', 'val1') ->get('key1') ->set('key2', 'val2') ->get('key2') ->exec(); /* $ret == array( 0 => TRUE, 1 => 'val1', 2 => TRUE, 3 => 'val2'); */
##############
简单数据mget也可以实现
mGet, getMultiple
Description: Get the values of all the specified keys. If one or more keys dont exist, the array will containFALSEat the position of the key.
Parameters
Array: Array containing the list of the keys
Return value
Array: Array containing the values related to keys in argument
Examples
$redis->set('key1', 'value1'); $redis->set('key2', 'value2'); $redis->set('key3', 'value3'); $redis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3'); $redis->mGet(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
相关文章推荐
- PHP中利用Redis管道加快执行
- PHP中利用Redis管道加快执行
- Redis 管道加快Redis 执行速度说明
- 向PHP要效率——加快你的代码执行速度(strpos 快于 preg_match 快于 strstr 快于 ereg)
- 利用PHP和crontab命令作Linux自动执行脚本
- 在linux下利用crontab定时执行PHP脚本
- win7下利用计划任务定期执行php文件
- 利用PHP执行.SQL文件
- PHP 利用redis 做统计缓存mysql的压力
- 利用php利用root权限执行shell脚本必须进行以下几个步骤
- php消息队列处理实践 ,利用AMQP和redis两种方法
- 利用管道完成数据从MySQL到Redis的高效迁移
- 如何利用内置PHP灵活性执行外部程序
- 如何利用PHP执行.SQL文件
- VC中利用管道技术取得DOS或者命令行以及外部程序的执行结果
- php利用root权限执行shell脚本(二)
- 利用 PHP 扩展模块突破 Disable_functions 执行命令
- VC中利用管道技术取得DOS或者命令行以及外部程序的执行结果
- VC中利用管道技术取得DOS或者命令行以及外部程序的执行结果
- 利用 Linux crontab 定时执行 PHP