php foreach用法 (phpredis使用技巧大全)

安装

开始在 PHP 中使用 Redis 前, 我们需要确保已经安装了 redis 服务及 PHP redis 驱动,且你的机器上能正常使用 PHP。

PHP安装redis扩展

以下操作需要在*载下**的 phpredis 目录中完成:

phplaravel框架开发实例,phpredis使用技巧大全

修改php.ini文件

vi /usr/local/php/lib/php.ini

增加如下内容:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626"
extension=redis.so

安装完成后重启php-fpm 或 apache。查看phpinfo信息,就能看到redis扩展。

phplaravel框架开发实例,phpredis使用技巧大全

phplaravel框架开发实例,phpredis使用技巧大全

连接到 redis 服务

phplaravel框架开发实例,phpredis使用技巧大全

执行脚本,输出结果为:

Connection to server sucessfully
Server is running: PONG

Redis PHP String(字符串) 实例

phplaravel框架开发实例,phpredis使用技巧大全

执行脚本,输出结果为:

Connection to server sucessfully
Stored string in redis:: Redis tutorial

Redis PHP List(列表) 实例

phplaravel框架开发实例,phpredis使用技巧大全

执行脚本,输出结果为:

phplaravel框架开发实例,phpredis使用技巧大全

Redis PHP Keys 实例

phplaravel框架开发实例,phpredis使用技巧大全

执行脚本,输出结果为:

phplaravel框架开发实例,phpredis使用技巧大全

小编每天都会分享这方面的干货,感兴趣的朋友走一波关注哩~

phplaravel框架开发实例,phpredis使用技巧大全