~~~
$redis->muti($mode)
->get($key)
->set($key)
->exec();
~~~
既然是这样的, 当我要使用管道执行一万次操作的时候,需要写一万次操作在muti()的后面,有没有更好的写法?
设计者没有想到这个问题么?
~~~
<?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::MULTI or Redis::PIPELINE. Defaults toRedis::MULTI.
A Redis::MULTI block of commands runs as a single transaction; aRedis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity.discard cancels 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 untilexec() 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 contain FALSE at 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
~~~
<?php
$redis->set('key1', 'value1');
$redis->set('key2', 'value2');
$redis->set('key3', 'value3');
# $redis->mSet(array('key1' => 'value1', 'key2 => 'value2', 'key3 => 'value3'));
$redis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3');
$redis->mGet(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
~~~
- 目录
- 安装扩展
- 在 Windows 上安装 PHP 扩展
- 测试Redis扩展函数
- 教程
- 简介
- Redis 安装
- Redis 配置
- 运行
- 测试
- 书籍
- 《Redis开发与运维》
- 《Redis入门指南》
- 《Redis实战》
- 《当 Redis 遇上 ThinkPHP5》
- 参考站点
- 下载
- 命令参考
- 管理工具
- 视频
- 云数据库 Redis 版使用教程
- Redis 深入之道
- Redis高可用教程
- Redis入门
- NoSQL概述
- Redis概述
- Redis安装
- Jedis入门
- PHP命令
- PHP中利用Redis管道加快执行
- Hash操作
- Set操作
- Gearman
- MySQL - Redis配合使用方案
- 应用场景
- 缓存应用
- Redis实现简单的条件查询功能
- 获取网站中点击量最高的前n篇文章
- 显示最新的项目列表
- 排行榜相关
- 设计技巧
- SortedSets
- List列表
- 消息队列
- 最新文章
- Set集合
- 共同好友
- 独立 IP
- Linux教程
- 常用命令
- 哈希命令
- 字符串
- 集合
- 有序集合
- Redis 有序集合命令
- 有序集合命令(中)
- 发布订阅
- 用例
- 列表
- Lindex
- Ltrim
- Rpush
- Lset
- Llen
- Lpush
- 信息
- info memory
- 安装
- 数据类型
- Redis管道(pipeline)
- Memory Command
- 阿里云Redis
- 架构
- 4.0版本
- Redis 4.0 新功能介绍
- Redis Desktop Manager
- 创建hash列表数据
- Lua: 给 Redis 用户的入门指导
- Lua入门
- 乐观锁介绍
- 悲观锁介绍
- 脏数据
- Redis核心概念
- Redis事务
- Lua
- 在Redis中使用lua脚本
- php-redis
- mysql缓存服务器
- redis setnx 实现分布式锁和单机锁
- 为什么分布式一定要有Redis?