$redis = new Redis();
$redis->connect('127.0.0.1',?6379);
$redis->auth('123456');密碼認(rèn)證
$redis->set('key',?'val');
echo?$redis->get('key');
http://hi.baidu.com/aqia230/item/a8f07bdfaf028fe2b3f7777c
其他相關(guān)操作
$redis->flushDB()?;//清空當(dāng)前數(shù)據(jù)庫
$redis->flushAll();????//清空所以數(shù)據(jù)庫
$redis->dbSize();//查看當(dāng)前數(shù)據(jù)庫有多少個(gè)鍵值key
randomKey
隨機(jī)返回key空間的一個(gè)key
$key?=?$redis->randomKey();
select
選擇一個(gè)數(shù)據(jù)庫
move
轉(zhuǎn)移一個(gè)key到另外一個(gè)數(shù)據(jù)庫
$redis->select(0);?//?switch?to?DB?0
$redis->set('x',?'42');?//?write?42?to?x
$redis->move('x',?1);?//?move?to?DB?1
$redis->select(1);?//?switch?to?DB?1
$redis->get('x');?//?will?return?42
rename,?renameKey
給key重命名
$redis->set('x',?'42');
$redis->rename('x',?'y');
$redis->get('y');?//?→?42
$redis->get('x');?//?→?`FALSE`
renameNx
與remane類似硫兰,但是诅愚,如果重新命名的名字已經(jīng)存在劫映,不會替換成功
setTimeout,?expire
設(shè)定一個(gè)key的活動時(shí)間(s)
$redis->setTimeout('x',?3);
expireAt
key存活到一個(gè)unix時(shí)間戳?xí)r間
$redis->expireAt('x',?time()?+?3);
keys,?getKeys
返回滿足給定pattern的所有key
$keyWithUserPrefix?=?$redis->keys('user*');
dbSize
查看現(xiàn)在數(shù)據(jù)庫有多少key
$count?=?$redis->dbSize();
auth
密碼認(rèn)證
$redis->auth('foobared');
bgrewriteaof
使用aof來進(jìn)行數(shù)據(jù)庫持久化
$redis->bgrewriteaof();
slaveof
選擇從服務(wù)器
$redis->slaveof('10.0.1.7',?6379);
save
將數(shù)據(jù)同步保存到磁盤
bgsave
將數(shù)據(jù)異步保存到磁盤
lastSave
返回上次成功將數(shù)據(jù)保存到磁盤的Unix時(shí)戳
info
返回redis的版本信息等詳情
type
返回key的類型值
string:?Redis::REDIS_STRING
set:?Redis::REDIS_SET
list:?Redis::REDIS_LIST
zset:?Redis::REDIS_ZSET
hash:?Redis::REDIS_HASH
other:?Redis::REDIS_NOT_FOUND