04-PHP-redis

來源:互聯網
上載者:User

標籤:str   etc   data   關閉   highlight   daemonize   connect   cpu   ase   

【Redis 先安裝tcl: yum install tcl  [ 下載和安裝]官網http://redis.io/  下載最新的穩定版本,這裡是3.2.0, 然後解壓檔案並進入。
$ sudo tar -zxf redis-3.2.0.tar$ cd redis-3.2.0$ sudo make test  #測試編譯$ sudo make install #安裝
  [ 服務配置](1) 切換到root使用者,並在 /usr/local/redis 下建立3個目錄:bin、etc、db(2) 拷貝 /usr/local 下的 bin 目錄下的redis-* 系列檔案 到 /usr/local/redis/bin
$ cp /usr/local/bin/reids-*  /usr/local/redis/bin
(3) 拷貝redis-3.2.0/src 下的mkreleasehdr.sh 到 /usr/local/redis/bin下
$ cp /usr/local/redis3.2.0/src/mkreleasehdr.sh  /usr/local/redis/bin/
(4) 拷貝redis.conf 到 /usr/local/redis/etc下
$ cp /usr/local/redis-3.2.0/redis.conf  /usr/local/redis/etc
(5) 修改redis.conf: 
#修改為守護模式daemonize yes#設定進程鎖檔案pidfile /usr/local/redis/redis.pid#連接埠port 6379#用戶端逾時時間timeout 300#記錄層級loglevel debug#記錄檔位置logfile /usr/local/redis/log-redis.log#設定資料庫的數量,預設資料庫為0,可以使用SELECT <dbid>命令在串連上指定資料庫iddatabases 8##指定在多長時間內,有多少次更新操作,就將資料同步到資料檔案,可以多個條件配合#save <seconds> <changes>#Redis預設設定檔中提供了三個條件:save 900 1save 300 10save 60 10000#指定儲存至本機資料庫時是否壓縮資料,預設為yes,Redis採用LZF壓縮,如果為了節省CPU時間,#可以關閉該#選項,但會導致資料庫檔案變的巨大rdbcompression yes#指定本機資料庫檔案名稱dbfilename dump.rdb#指定本機資料庫路徑dir /usr/local/redis/db/#指定是否在每次更新操作後進行日誌記錄,Redis在預設情況下是非同步把資料寫入磁碟,如果不開啟,可能#會在斷電時導致一段時間內的資料丟失。因為 redis本身同步資料檔案是按上面save條件來同步的,所以有#的資料會在一段時間內只存在於記憶體中appendonly no#指定更新日誌條件,共有3個可選值:#no:表示等作業系統進行資料緩衝同步到磁碟(快)#always:表示每次更新操作後手動調用fsync()將資料寫到磁碟(慢,安全)#everysec:表示每秒同步一次(折衷,預設值)appendfsync everysec
  (6) 修改許可權為當前使用者 xxx
$ chown -R xxxx /usr/local/redis
(7) 啟動服務
$ cd /usr/local/redis$ ./bin/redis-server  ./etc/redis.conf
(8) 訪問服務
$ cd /usr/local/redis$ ./bin/redis-cli
  [ 基本命令]
set name renxing ex 1000get namekeys *mset a hello b bold c cat d dogmget a b c d...
更多請參考:http://www.cnblogs.com/renxing123/p/6009020.html   【 安裝php-redis擴充】git clone或者下載解壓 [ https://github.com/phpredis/phpredis]
$ cd ./phpredis$ /usr/local/php/bin/phpize$ ./configure --with-php-config=/usr/local/php/bin/php-config$ make && make install

  安裝完成後,在php.ini 後面添加  extension=redis.so  [PHP操作redis]
<?php$redis = new Redis(); //執行個體化Redis對象$redis->open(‘localhost‘,6379) or die ("Could not connect"); //串連到redis伺服器$redis->set(‘user:userid:2:username‘,‘renxing‘); //set方法存入資料$value = $redis->get(‘user:userid:2:username‘); //get方法取出資料print_r($value);  //輸出“renxing”?>

 

 

          

04-PHP-redis

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.