参照runoob:PHP 使用 Redis

Windows:

- 假设redis已经安装好 服务启动

- xampp (php 7.1 x86 windows)

查看phpinfo (php 7.1 x86/x64 ts/uts vc14/vc15)

Zend Extension Build API320160303,TS,VC14
PHP Extension Build API20160303, TS,VC14

https://windows.php.net/downloads/pecl/releases/igbinary/2.0.6rc1/
https://windows.php.net/downloads/pecl/releases/redis/3.1.3/

; php.ini
extension=php_igbinary.dll
extension=php_redis.dll

  

查看phpinfo 有redis扩展

test

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//设置 redis 字符串数据
$redis->set("tutorial-name", "Redis tutorial");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>

Mac:

下载php-redis,地址:https://nodeload.github.com/nicolasff/phpredis/zip/master  

链接: https://pan.baidu.com/s/1-08Wb7TsigVa1fj9k_oByg 密码: ny9g

mv ~/Downloads/phpredis-master.zip .

unzip phpredis-master.zip -d .

cd ./phpredis-master

sudo phpize

若未安装autoconf,则会报错 $ brew install autoconf

./configure --with-php-config=`which php-config`

make

make test

sudo make install

sudo emacs /Applications/XAMPP/etc/php.ini

+++++++++++++++++++++++++++++++++

extension="redis.so"

================================

重启apahce后

php -m|grep redis

查看phpredis扩展是否开启。

test:

<?php
$redis = new Redis(); // connect
$handle = $redis->connect('127.0.0.1', 6379);
if ($handle) {
echo "Connect to server successfull".PHP_EOL;
var_dump($handle);
}
echo "Server is running: ".$redis->ping().PHP_EOL; // string
$redis->set("tutorial-name", "Redis tutorial");
echo "Stored string in redis::" .$redis->get("tutorial-name").PHP_EOL; // list
$redis->del("tutorial-list"); $a = ["Redis", "MongoDB", "MySQL"];
array_walk($a, function($item, $key, $redis) {
$redis->lpush("tutorial-list", $item);
}, $redis); $arList = $redis->lrange("tutorial-list", 0, 5);
print_r($arList);
echo PHP_EOL; // keys
$keys = $redis->keys("*");
print_r($keys);
echo PHP_EOL;

  execute:

$ php connect.php
Connect to server successfull
bool(true)
Server is running: +PONG
Stored string in redis::Redis tutorial
Array
(
[0] => MySQL
[1] => MongoDB
[2] => Redis
)

Array
(
[0] => tutorial-name
[1] => myhash
[2] => foo
[3] => key
[4] => tutorial-list
)

最新文章

  1. Jmeter - 源码开发环境配置
  2. 关于WCF的一些注意事项
  3. 移动web前端之meta标签
  4. node.js cluster多进程、负载均衡和平滑重启
  5. bzoj 4010: [HNOI2015]菜肴制作 拓扑排序
  6. 如何在Linux上安装Storm
  7. bzoj2244[SDOI2011]拦截导弹
  8. 循环语句——for语句
  9. Spring Mvc 用Demo去学习
  10. An internal error occurred during: &quot;Building workspace&quot;. java.lang.StackOverflowError
  11. C#编写一个大字母游戏,详细代码,不懂问博主。。。。
  12. svn 恢复删除文件
  13. 030_CORS深究
  14. 我的大学,我的SPR机器人队
  15. leetcode57:插入区间
  16. python装饰器1
  17. jmeter 在linux服务器的安装和运行;
  18. unittest单元测试框架简单说明
  19. 微信小程序开发 [07] 写在后面的话
  20. linux 使用文件作为交换分区

热门文章

  1. S3C2440—9.复制程序到SDRAM中执行
  2. GIT-版本管理-初阶使用
  3. NOIP 模拟 $25\; \rm queen$
  4. SpringBoot集成Druid
  5. Linux下Qt创建共享库与链接共享库详解
  6. C#多线程详解(一) Thread.Join()的详解
  7. C#综合细说进程、应用程序域与上下文
  8. C 静态存储动态存储
  9. 数据库存储图片相对路径使用问题,配置tomcat的server.xml文件
  10. pyspark启动与简单使用----本地模式(local)----shell