redisun為不同數(shù)據(jù)類型封裝統(tǒng)一的命令
使用redis+lua為不同數(shù)據(jù)類型封裝統(tǒng)一的命令,降低redis操作的復(fù)雜度,提高性能。
例如,創(chuàng)建一個key,常見的5種數(shù)據(jù)類型:string, hash, list, set, zset,均可使用同一個命令來實現(xiàn)
<?php $key = 'hello-redisun'; // string $value = 'hello'; // list $value = [1,2,3]; // set $value = ['hello', 'world', '!']; // zset $value = [ 'apple' => 1, 'banana' => 2, 'grape' => 3, ]; // hash $value = [ 'name' => 'maria', 'age' => 22, ]; $ttl = 100; // 100s后過期 $ttl = null; // 不過期,默認(rèn)值 $model->create($key, $value, $ttl);
已封裝的命令如下。所有的“set”類命令都支持設(shè)置ttl,如果不傳ttl參數(shù)或傳參為null,會保留key的當(dāng)前ttl。
create: 創(chuàng)建key
createNotExists: 當(dāng)key不存在時創(chuàng)建
createExists: 當(dāng)key存在時創(chuàng)建
insert: 創(chuàng)建key,支持批量創(chuàng)建
insertNotExists: key不存在時創(chuàng)建
insertExists: key存在時創(chuàng)建
get: 獲取key,支持批量獲取
getAndSet: 獲取key并設(shè)置新值
find: 獲取單個key
findBatch: 獲取多個key
update: 更新多個key
destroy: 刪除單個key
destroyBatch: 刪除多個key
delete: 刪除多個key
評論
圖片
表情
