国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP鏈接redis的方法代碼

2020-03-24 18:12:08
字體:
供稿:網(wǎng)友
在php程序中使用Redis之前,需要確保在機(jī)器上安裝了Redis的PHP驅(qū)動程序和PHP環(huán)境。可以先在將PHP電腦上并配置好環(huán)境。本文就和大家分享PHP鏈接redis的方法代碼,希望能幫助到大家。

安裝

現(xiàn)在,讓我們看看如何設(shè)置Redis PHP驅(qū)動程序。
從github庫下載phpredis=> http://github.com/nicolasff/phpredis。 當(dāng)下載它之后,提取文件到phpredis目錄。在Ubuntu上,安裝以下擴(kuò)展。

cd phpredis sudo phpize sudo ./configure sudo make sudo make install

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

extension = redis.so

現(xiàn)在,Redis PHP安裝完成!

使用連接到Redis服務(wù)器
<?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(); ?>

PHP

當(dāng)程序執(zhí)行時,將產(chǎn)生以下結(jié)果。

Connection to server sucessfully Server is running: PONG
Redis PHP字符串示例
<?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"); ?>

執(zhí)行上面代碼,將生成以下結(jié)果 -

Connection to server sucessfully Stored string in redis:: Redis tutorial
Redis php列表示例
<?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); ?>

執(zhí)行上面代碼,將生成以下結(jié)果 -

Connection to server sucessfully Stored string in redis:: Redis Mongodb Mysql
Redis php鍵示例
<?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); ?>

執(zhí)行上面代碼,將生成以下結(jié)果 -

Connection to server sucessfully Stored string in redis:: tutorial-name tutorial-list

相關(guān)推薦:

PHP操作Redis實例講解

一個php+redis的簡單實例分享

Redis在PHP的一些使用方法

以上就是PHP鏈接redis的方法代碼的詳細(xì)內(nèi)容,更多請關(guān)注 其它相關(guān)文章!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 通渭县| 会东县| 阜康市| 江津市| 大余县| 华安县| 东兰县| 永丰县| 安阳市| 江达县| 垣曲县| 通化市| 长治市| 蕲春县| 会宁县| 景东| 沅陵县| 内丘县| 陆丰市| 宜兰市| 宜兰市| 阳泉市| 延长县| 垦利县| 巨野县| 柳河县| 汝城县| 扎兰屯市| 同江市| 双城市| 黄龙县| 颍上县| 察雅县| 延川县| 清河县| 萨嘎县| 浦城县| 石楼县| 荣昌县| 兰溪市| 皮山县|