windows下安裝redis 以及phpredis的擴充 (windows redis php&php7)

來源:互聯網
上載者:User

標籤:title   建議   var   tle   views   center   判斷   遞增   compile   

一、工具準備

1. redis for windows 下載 https://github.com/MSOpenTech/redis

2. PHP擴充下載 http://pecl.php.net/package-stats.php (redis 和 igbinary)

    php 7 擴充下載 http://windows.php.net/downloads/pecl/snaps/redis/20160319/

註: 下載擴充是要注意看自己的php版本及x86orx64 和 compiler  編譯版本

 

 

二、redis安裝

1.redis安裝

將下載後的redis檔案解壓到安裝目錄

2.redis啟動

 

1).windows+R 然後 cmd 進入到D:\program files\redis(根據自己redis路徑自行調整)

2).輸入 redis-server.exe 點擊斷行符號,自己注意看一下redis目錄下檔案情況,不同版本的啟動方式有點小差異。出現標識執行成功。成功後別關閉當前視窗,操作redis期間都要保證此視窗開啟,關閉此視窗表示 關閉reids,重新開啟一個cmd

 

3).cmd 進入到D:\program files\redis(根據自己redis路徑自行調整) 然後輸入 redis-cli.exe 點擊斷行符號。現在我們就可以做一些測試如,標識redis安裝 啟動成功。

註:兩個cmd視窗同時開啟,之前開啟redis的視窗不能關掉

 

三、 php擴充

1.把下載到的php_redis.dll和php_igbinary.dll擴充檔案 拷貝到php\ext中 

2. 開啟php.ini;加入以下代碼

 

[html] view plain copy 
  1. #php for redis  
  2. extension=php_igbinary.dll  
  3. extension=php_redis.dll  

 

3.重啟服務,phpinfo中有redis項表示成功

四.demo

 

[php] view plain copy 
  1. <span style="font-size:18px;">$redis = new redis();    
  2. $redis->connect("127.0.0.1","6379");  //php用戶端設定的ip及連接埠    
  3. //儲存一個 值    
  4. $redis->set("type",12);    
  5. echo $redis->get("type");    
  6.     
  7. //儲存多個值    
  8. $array = array(‘first_key‘=>‘first_val‘,    
  9.     ‘second_key‘=>‘second_val‘,    
  10.     ‘third_key‘=>‘third_val‘);    
  11. $array_get = array(‘first_key‘,‘second_key‘,‘third_key‘);    
  12. $redis->mset($array);    
  13. var_dump($redis->mget($array_get)); </span>  


 

附:Redis類的一些屬性及方法


a)串連redis server

  • connect :串連server
  • pconnect :長串連
  • auth :許可權驗證
  • select :選擇DB
  • close : 關閉串連
  • setOption : 設定 client 選項
  • getOption : 擷取client選項
  • ping : ping redis server
  • echo : 輸出字串

注意,如果頻繁操作redis,不停地connect 和close會很耗效能的,這個時候,建議用pconnect 建立個長串連

b)字串讀寫函數

  • append  :在值的後面追加值
  • decr :遞減一個key的值
  • incr :遞增一個key的值
  • get :擷取一個值
  • set :設定一個值
  • getSet :設定值,並返回老值
  • mGet :批量擷取值
  • mSet :大量設定值
  • strlen :擷取值長度

注意:如果能用大量操作盡量用批量,減少頻繁串連redis資料庫效能

c)hash讀寫函數

  • hDel :刪除一個多個域
  • hExists :判斷一個hash域是否存在
  • hGet :擷取hash域的值
  • hGetAll :擷取所有域值
  • hIncrBy :自增長一個hash int域的值
  • hKeys :擷取hash 所有域
  • hLen :擷取域個數
  • hMGet :批量擷取域的值
  • hMSet :大量設定域的值
  • hSet :設定域的值
  • hVals:得到所有域的值

d)list讀寫函數

  • lInsert:插入元素
  • lLen:list長度
  • lPop:移除並擷取第一個顏色
  • lPush:插入一個元素
  • lRem:移除元素
  • lSet:設定元素值

e)set

    • sAdd:增加一個或多個成員
    • sIsMember:是否包含
    • sMembers:得到成員
    • sMove:移動成員
    • sPop:移除成員
    • sRandMember:得到隨機成

windows下安裝redis 以及phpredis的擴充 (windows redis php&php7)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.