重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

redis连接php-创新互联

安装 在PHP程序中使用Redis,需要确保我们有Redis的PHP驱动程序和PHP安装设置在机器上。可以查看PHP教程教你如何在机器上安装PHP。现在,让我们来看看一下如何设置Redis的PHP驱动程序。 需要从github上资料库https://github.com/nicolasff/phpredis下载phpredis。下载了它以后,将文件解压缩到phpredis目录。在Ubuntu上安装这个扩展,如下图所示。 cd phpredis sudo phpize sudo ./configure sudo make sudo 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 sucessfully Server 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:: " + jedis.get("tutorial-name"); ?> 当执行程序时,会产生下面的结果: Connection to server sucessfully Stored 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 sucessfully Stored string in redis:: Redis Mongodb Mysql 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 sucessfully Stored string in redis:: tutorial-name tutorial-list

创新互联建站坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。十余年网站建设经验创新互联建站是成都老牌网站营销服务商,为您提供成都网站制作、网站设计、网站设计、HTML5、网站制作、品牌网站建设、微信小程序服务,给众多知名企业提供过好品质的建站服务。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:redis连接php-创新互联
分享路径:http://cqcxhl.com/article/djgieg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP