Redis 常用基本操作

2021-10-14 06:19:55 字數 2646 閱讀 9892

<?php

namespace

;use

;use

;/**

* redis測試介面

*/class

test

extends

apielse}}

/** * 增加瀏覽次數

*/public

function

num(

)/**

* 隊列入列

*/public

functionru(

)$list=$r

->

lrange

('mylist',0

,-1)

;dump

($list);

}/**

* 佇列出列

*/public

function

chu(

)else

}/**

* hash常用操作

*/public

function

set(

)/**

* 有序集合獲取排行榜

* @apiparams (name="type", type="integer", required=true, description="排序:1=正序,2=倒序")

*/public

function

paixu()

/** * 新增資料(沒有新增有則更新分數)

* @apiparams (name="score", type="integer", required=true, description="分數")

* @apiparams (name="username", type="integer", required=true, description="使用者名稱")

*/public

function

add(

)$rank

=new

rank()

;$add

=$rank

->

addlist

($score

,$username);

if($add

)else

}/**

* 刪除指定使用者資料

* @apiparams (name="username", type="integer", required=true, description="使用者索引名")

*/public

function

del(

)$rank

=new

rank()

;$del

=$rank

->

dellist

($username);

if($del

)else

}/**

* 獲取指定使用者排名

* @apiparams (name="username", type="integer", required=true, description="使用者索引名")

*/public

function

node()

$rank

=new

rank()

;$list

=$rank

->

getnoderank

($username);

if($list

)else

}}

/**

* redis 基類

*/

<?php

namespace

;/**

* redis 排序

*/class

rank

else

}/**

* 獲取當前排序的key名

* 1=>正序,2=>倒序

*/public

function

getlist

($type

)else

}/**

* 將對應的值填入到排行榜中

* $score 對應的分數

* $username 對應的值

*/public

function

addlist

($score

,$username

)/**

* 刪除指定使用者

* $username 使用者索引

*/public

function

dellist

($username

)/**

* 獲取給定節點的排名

* @param string $node 對應的節點的key名

* @param string $asc 是否按照分數大小正序排名, true的情況下分數越大,排名越高

* @return 節點排名,根據$asc排序,true的話,第一高分為0,false的話第一低分為0

*/public

function

getnoderank

($node

,$asc

=true

)else

}}

Redis基本操作

set foo bar get foo then return bar set story long long long ago get story also we can get the encoding of the object object encoding foo return embst...

redis基本操作

這個 可以檢視所有的redis的命令 下面是常用的一些命令 1.登入本機 redis 其他電腦,請填寫對應的ip位址 redis cli.exe raw h 192.168.0.204 p 6379 2.新增set集合中的資料 sadd myset hello 3.查詢所有的key keys 模糊查...

Redis基本操作

1.資料庫基本操作 啟動redis redis server etc redis redis.conf 進入reids redis cli p port 退出redis quit 關閉redis redis cli shutdown 選擇資料庫 預設0,共16個 select num 清空資料庫 f...