您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Redis PHP连接操作

2024/3/16 10:25:19发布14次查看
安装要在php程序中使用redis,首先需要确保 redis 的php驱动程序和 php 安装设置在机器上。可以查看 php教程 教你如何在机器上安装php。现在,让我们来看看一下如何设置 redis 的php驱动程序。
需要从 github 上资料库: https://github.com/nicolasff/phpredis 下载 phpredis。下载完成以后,将文件解压缩到 phpredis 目录。在 ubuntu 上安装这个扩展,可使用如下图所示的命令来安装。
cd phpredissudo phpizesudo ./configuresudo makesudo make install
现在,复制和粘贴“modules”文件夹的内容复制到php扩展目录中,并在 php.ini 中添加以下几行。
extension = redis.so
现在 redis 和 php 安装完成。
连接到redis服务器connect('127.0.0.1', 6379); echo connection to server sucessfully; //check whether server is running or not echo server is running: . $redis->ping();?>
当执行程序时,会产生下面的结果:
connection to server sucessfullyserver is running: pong
redis的php字符串实例connect('127.0.0.1', 6379); echo connection to server sucessfully; //set the data in redis string $redis->set(tutorial-name, redis tutorial); // get the stored data and print it echo stored string in redis:: . $redis.get(tutorial-name);?>
当执行程序时,会产生下面的结果:
connection to server sucessfullystored string in redis:: redis tutorial
redis的php列表示例connect('127.0.0.1', 6379); echo connection to server sucessfully; //store data in redis list $redis->lpush(tutorial-list, redis); $redis->lpush(tutorial-list, mongodb); $redis->lpush(tutorial-list, mysql); // get the stored data and print it $arlist = $redis->lrange(tutorial-list, 0 ,5); echo stored string in redis:: print_r($arlist);?>
当执行程序时,会产生下面的结果:
connection to server sucessfullystored string in redis::redismongodbmysql
redis的php键例connect('127.0.0.1', 6379); echo connection to server sucessfully; // get the stored keys and print it $arlist = $redis->keys(*); echo stored keys in redis:: print_r($arlist);?>
当执行程序时,会产生下面的结果:
connection to server sucessfullystored string in redis::tutorial-nametutorial-list
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product