参照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
)

配置php redis 扩展的更多相关文章

  1. Apache配置php redis扩展

    1.根据phpinfo,下载redis 下载地址:注意php版本号 http://windows.php.net/downloads/pecl/snaps/redis/2.2.5/ http://wi ...

  2. Ubutun 配置php redis 扩展

    1.安装redis 下载:wget --no-check-certificate https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz ...

  3. MAC 下 安装redis 并配置 php redis 扩展

    下载 redis redis-3.1.2.tgz sudo tar -xzf redis-3.1.2.tgz cd redis-3.1.2 sudo phpize grep: /usr/include ...

  4. 腾讯云环境配置之PHP5.6.3 + redis扩展 稳定版

    腾讯云环境配置之PHP5.6.3 + redis扩展 稳定版 时间:2015-01-18 01:41来源:linux.it.net.cn 作者:IT   #由于上文装过yum groupinstall ...

  5. redis安装和配置教程phpredis扩展安装测试

    作者:zhanhailiang 日期:2014-10-16 推荐阅读: Redis持久化策略 关于Redis很多其它资料阅读 1. 下载redis-2.8.17.tar.gz:http://downl ...

  6. nginx + php + mysql安装、配置、自启动+redis扩展

    用过了apache就想着用用nginx,网上教程其实很多,但是受服务器版本等限制,每个人遇到的问题也不一样,先记录下我的 一.安装依赖 yum -y install gcc zlib zlib-dev ...

  7. Linux上给php配置redis扩展

    说明,在项目开发中难免会遇到redis中,那我应该如何配置redis这样的一个扩展呢,看下面流程: 一.安装Redis PHP在安装redis扩展时,难免要看一下官网下载安装流程,链接如下: http ...

  8. 【Redis】windows环境下安装redis服务器,并配置php的redis扩展

    win7示例: 1.下载Redis服务器 : https://github.com/dmajkic/redis/downloads:(随便下,建议不要太老的) 2.在D:\phpStudy\ 新建Re ...

  9. mac机上搭建php56/nginx 1.8.x/thinkphp 3.2.x/gearman扩展/seaslog扩展/redis扩展环境

    php的各种扩展配置起来实在不容易,记录一下备忘: 一.php56 安装 虽然php7出来了,但是没用过,不知道有没有坑,这里仍然使用php5.6版本 1.1 安装php/php-pfm brew u ...

随机推荐

  1. MySQL自动填充

    一.数据库级别 1.1 表设计 create_time默认值添加CURRENT_TIMESTAMP. update_time默认值添加CURRENT_TIMESTAMP,更新打勾. 1.2 验证是否成 ...

  2. RHEL 7 “There are no enabled repos” 的解决方法

    RHEL 7 "There are no enabled repos"  的解决方法 [root@system1 Desktop]# yum install squidLoaded ...

  3. nodejs 更改项目端口号的 方法

    我这里是 koa2 项目 1.项目目录 serverConf.js 这里面配置端口 代码如下: const ServerConf= { ServicePort: 3036 }; module.expo ...

  4. C#中Finalize方法的问题

    ninputer在关于"值类型的Finalize不会被调用"中(http://blog.joycode.com/lijianzhong/archive/2005/01/13/429 ...

  5. C# 中的异步问题 Task

    public class SharedData { public int Value { get; set; } } public class Test { async Task ModifyValu ...

  6. WPF---数据绑定之Xml数据源(四)

    一.场景 现在外部有一xml文件,我们想将该xml文件中的内容绑定到ListView中,该如何实现? 二.实现 xml文件的内容如下: <?xml version="1.0" ...

  7. ubuntu编译安装python3.6.5

    去官网下载安装包放到~/software/   下 1更新软件库 sudo apt-get update 2安装相应的开发库 sudo apt-get install zlib1g-dev libbz ...

  8. Python代码阅读(第1篇):列表映射后的平均值

    本篇阅读的代码实现了将列表进行映射,并求取映射后的平均值. 本篇阅读的代码片段来自于30-seconds-of-python. average_by def average_by(lst, fn=la ...

  9. redis BLPOP命令阻塞,非阻塞(读了好久才懂)

    来源于:http://redisdoc.com/list/blpop.html#id1BLPOP key [key -] timeout 可用版本: >= 2.0.0 时间复杂度: O(1) B ...

  10. Spring Boot +Vue 项目实战笔记(一):使用 CLI 搭建 Vue.js 项目

    前言 从这篇文章开始,就进入真正的实践了. 在前端项目开发中,我们可以根据实际情况不同程度地使用 Vue.利用 Vue CLI(或写成 vue-cli,即 Vue 脚手架)搭建出来的项目,是最能体现 ...