Redis学习7之Predis连接redis过程和测试
2015-09-16 14:35
691 查看
Predis连接redis过程和测试:
1.下载地址:https://github.com/nrk/predis
可以git clone或者下载压缩包再解压到redis的clients文件夹下;
2.安装apache和php
3.在/var/www/html下新建test1.php,代码内容为:
输出结果为: 查看为127.0.0.1/test1.php
在redis-cli下查看为:
说明predis连接redis且set和get操作成功。
1.下载地址:https://github.com/nrk/predis
可以git clone或者下载压缩包再解压到redis的clients文件夹下;
2.安装apache和php
sudo apt-get install apache2 php5
3.在/var/www/html下新建test1.php,代码内容为:
<?php echo "hello world</br>"; require '/home/xubo/cloud/redis/clients/predis/autoload.php'; //require './predis/autoload.php'; echo "hello xubo1</br>"; /* for ($i = 0; $i < 20; $i++) { echo $i; echo "</br>"; } */ /* $redis = new Predis\Client([ 'scheme'=>'tcp', 'host' => '127.0.0.1', 'port' => 7000, ]);*/ /* $redis = new Predis\Client(); try { echo $redis->get('xubo'); }catch(Exception $e){{ echo "Message:{$e->getMessage()}"; } */ $redis = new Predis\Client(); echo $redis-> get('foo'); echo "</br>hello xubo2</br>"; //echo $redis->get('foo'); //$client = new Predis\Client(); //$client->set('foo', 'bar'); //$value = $client->get('foo'); //echo $redis; for ($i=0;$i<10;$i++){ $client = new Predis\Client(); $client -> set("xubo$i",$i); echo $client->get("xubo$i"); echo '</br>'; } echo "hello xubo end"; ?>
输出结果为: 查看为127.0.0.1/test1.php
hello world hello xubo1 bar hello xubo2 0 1 2 3 4 5 6 7 8 9 hello xubo end
在redis-cli下查看为:
xubo@xubo:~/cloud/redis/clients/predis/tests$ redis-cli 127.0.0.1:6379> keys * 1) "xubo8" 2) "xubo2" 3) "xubo6" 4) "xubo0" 5) "xubo5" 6) "key:__rand_int__" 7) "xubo1" 8) "xubo3" 9) "xubo" 10) "xubo4" 11) "xubo9" 12) "xubo7" 13) "mylist" 14) "foo" 15) "counter:__rand_int__"
说明predis连接redis且set和get操作成功。
相关文章推荐
- 一个关于if else容易迷惑的问题
- Android之使用Http协议实现文件上传功能
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- redis安装问题小结
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- Redis偶发连接失败案例实战记录
- 通晓网络测试常用命令
- Redis中实现查找某个值的范围
- Redis和Memcached的区别详解
- 分割超大Redis数据库例子
- Redis总结笔记(一):安装和常用命令
- Redis sort 排序命令详解
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法