专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

php怎么将数据导入redis_数据库

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/3/5 16:21:50       共计:3577 浏览

php怎么将数据导入redis?

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

PHP安装redis扩展

/usr/local/php/bin/phpize#php安装后的路径

./configure--with-php-config=/usr/local/php/bin/php-config

make&&makeinstall

修改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扩展。

连接到redis服务

<?php

//连接本地的Redis服务

$redis=newRedis();

$redis->connect('127.0.0.1',6379);

echo"Connectiontoserversucessfully";

//查看服务是否运行

echo"Serverisrunning:".$redis->ping();

?>

执行脚本,输出结果为:

Connectiontoserversucessfully

Serverisrunning:PONG

RedisPHPString(字符串)实例

<?php

//连接本地的Redis服务

$redis=newRedis();

$redis->connect('127.0.0.1',6379);

echo"Connectiontoserversucessfully";

//设置redis字符串数据

$redis->set("tutorial-name","Redistutorial");

//获取存储的数据并输出

echo"Storedstringinredis::".jedis.get("tutorial-name");

?>

执行脚本,输出结果为:

Connectiontoserversucessfully

Storedstringinredis::Redistutorial

RedisPHPList(列表)实例

<?php

//连接本地的Redis服务

$redis=newRedis();

$redis->connect('127.0.0.1',6379);

echo"Connectiontoserversucessfully";

//存储数据到列表中

$redis->lpush("tutorial-list","Redis");

$redis->lpush("tutorial-list","Mongodb");

$redis->lpush("tutorial-list","Mysql");

//获取存储的数据并输出

$arList=$redis->lrange("tutorial-list",0,5);

echo"Storedstringinredis::"

print_r($arList);

?>

执行脚本,输出结果为:

Connectiontoserversucessfully

Storedstringinredis::

Redis

Mongodb

Mysql

RedisPHPKeys实例

<?php

//连接本地的Redis服务

$redis=newRedis();

$redis->connect('127.0.0.1',6379);

echo"Connectiontoserversucessfully";

//获取数据并输出

$arList=$redis->keys("*");

echo"Storedkeysinredis::"

print_r($arList);

?>

执行脚本,输出结果为:

Connectiontoserversucessfully

Storedstringinredis::

tutorial-name

tutorial-list

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:mysql查询一列数据,sql中如何将多列用一点合并成一列查询出_数据库 | ·下一条:Windows下如何安装pythonpandas_数据库

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有