$redis = new Redis();
$redis->connect('127.0.0.1',?6379);
$redis->auth('123456');密碼認證
$redis->set('key',?'val');
echo?$redis->get('key');
http://hi.baidu.com/aqia230/item/a8f07bdfaf028fe2b3f7777c
其他相關操作
$redis->flushDB()?;//清空當前數據庫
$redis->flushAll();????//清空所以數據庫
$redis->dbSize();//查看當前數據庫有多少個鍵值key
randomKey
隨機返回key空間的一個key
$key?=?$redis->randomKey();
select
選擇一個數據庫
move
轉移一個key到另外一個數據庫
$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類似,但是,如果重新命名的名字已經存在,不會替換成功
setTimeout,?expire
設定一個key的活動時間(s)
$redis->setTimeout('x',?3);
expireAt
key存活到一個unix時間戳時間
$redis->expireAt('x',?time()?+?3);
keys,?getKeys
返回滿足給定pattern的所有key
$keyWithUserPrefix?=?$redis->keys('user*');
dbSize
查看現在數據庫有多少key
$count?=?$redis->dbSize();
auth
密碼認證
$redis->auth('foobared');
bgrewriteaof
使用aof來進行數據庫持久化
$redis->bgrewriteaof();
slaveof
選擇從服務器
$redis->slaveof('10.0.1.7',?6379);
save
將數據同步保存到磁盤
bgsave
將數據異步保存到磁盤
lastSave
返回上次成功將數據保存到磁盤的Unix時戳
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