国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 > php教程 > php手冊 > 正文

Redis PHP連接操作,redisphp連接

php中文網(wǎng)
發(fā)布: 2016-07-06 14:25:24
原創(chuàng)
1734人瀏覽過

Redis PHP連接操作,redisphp連接

安裝

要在php程序中使用redis,首先需要確保 redis 的php驅動程序和 php 安裝設置在機器上。可以查看 php教程 教你如何在機器上安裝php?,F(xiàn)在,讓我們來看看一下如何設置 redis 的php驅動程序。

需要從 github 上資料庫: https://github.com/nicolasff/phpredis 下載 phpredis。下載完成以后,將文件解壓縮到 phpredis 目錄。在 Ubuntu 上安裝這個擴展,可使用如下圖所示的命令來安裝。

<span class="pln">
cd phpredis
sudo phpize
sudo ./configure
sudo make
sudo make install

</span>
登錄后復制

現(xiàn)在,復制和粘貼“modules”文件夾的內(nèi)容復制到PHP擴展目錄中,并在 php.ini 中添加以下幾行。

<span class="pln">
extension = redis.so

</span>
登錄后復制

現(xiàn)在 Redis 和 PHP 安裝完成。

連接到Redis服務器

<span class="pln">
<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $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();
?>

</span>
登錄后復制

當執(zhí)行程序時,會產(chǎn)生下面的結果:

立即學習PHP免費學習筆記(深入)”;

<span class="pln">
Connection to server sucessfully
Server is running: PONG

</span>
登錄后復制

Redis的PHP字符串實例

<span class="pln">
<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $redis->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");
?>

</span>
登錄后復制

當執(zhí)行程序時,會產(chǎn)生下面的結果:

立即學習PHP免費學習筆記(深入)”;

<span class="pln">
Connection to server sucessfully
Stored string in redis:: Redis tutorial

</span>
登錄后復制

Redis的PHP列表示例

<span class="pln">
<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $redis->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);
?>

</span>
登錄后復制

當執(zhí)行程序時,會產(chǎn)生下面的結果:

立即學習PHP免費學習筆記(深入)”;

<span class="pln">
Connection to server sucessfully
Stored string in redis::
Redis
Mongodb
Mysql

</span>
登錄后復制

Redis的PHP鍵例

<span class="pln">
<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $redis->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);
?>

</span>
登錄后復制

當執(zhí)行程序時,會產(chǎn)生下面的結果:

立即學習PHP免費學習筆記(深入)”;

<span class="pln">
Connection to server sucessfully
Stored string in redis::
tutorial-name
tutorial-list</span>
登錄后復制
PHP速學教程(入門到精通)
PHP速學教程(入門到精通)

PHP怎么學習?PHP怎么入門?PHP在哪學?PHP怎么學才快?不用擔心,這里為大家提供了PHP速學教程(入門到精通),有需要的小伙伴保存下載就能學習啦!

下載
相關標簽:
來源:php中文網(wǎng)
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內(nèi)容,請聯(lián)系admin@php.cn
最新問題
開源免費商場系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學習
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號