在php程式中使用redis,需要確保我們有redis的php驅動程式和php安裝設定在機器上。可以檢視php教程教你如何在機器上安裝php。現在,讓我們來看看一下如何設定redis的php驅動程式。
cd phpredis現在,複製和貼上「modules」資料夾的內容複製到php擴充套件目錄中,並在php.ini中新增以下幾行。sudo phpize
sudo ./configure
sudo make
sudo make install
extension = redis.so現在redis和php安裝完成。
<?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();
?>
connection to server sucessfullyserver is running: pong
<?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:: " + jedis.get("tutorial-name");
?>
connection to server sucessfullystored string in redis:: redis tutorial
<?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);
?>
connection to server sucessfullystored string in redis::
redis
mongodb
mysql
<?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);
?>
connection to server sucessfullystored string in redis::
tutorial-name
tutorial-list
php操作redis php操作redis
redis類和redi ception類 redis類用於建立redis客戶端 redis new redis 如果無法訪問redis伺服器,會丟擲redi ception異常物件 連線問題,redis服務已關閉,或者redis主機過載等 在任何其他不涉及無法訪問的伺服器 如金鑰不正確,無效命令等 ...
redis PHP 操作筆記
1111111111111111 連線本地的 redis 服務 redis new redis redis connect 127.0.0.1 6379 echo connection to server successfully 檢視服務是否執行 echo server is running re...
php操作redis PHP 使用 Redis
php 使用 redis 安裝開始在 php 中使用 redis 前,我們需要確保已經安裝了 redis 服務及 php redis 驅動,且你的機器上能正常使用 php。php安裝redis擴充套件 wget cd phpredis 3.1.4 進入 phpredis 目錄 usr local p...