<pre name=
"code"
class
=
"php"
><span style=
"font-size:18px;"
>
class
MyRedis {
private
$redis
;
public
function
__construct(
$host
= '10.102.1.8',
$port
= 6379) {
$this
->redis =
new
Redis();
$this
->redis->connect(
$host
,
$port
);
return
$this
->redis;
}
public
function
set(
$key
,
$value
,
$timeOut
=0) {
$retRes
=
$this
->redis->set(
$key
,
$value
);
if
(
$timeOut
> 0)
$redis
->expire('
$key
',
$timeOut
);
return
$retRes
;
}
public
function
sadd(
$key
,
$value
){
return
$this
->redis->sadd(
$key
,
$value
);
}
public
function
zadd(
$key
,
$value
){
return
$this
->redis->zadd(
$key
,
$value
);
}
public
function
smembers(
$setName
){
return
$this
->redis->smembers(
$setName
);
}
public
function
lpush(
$key
,
$value
){
echo
"$key - $value \n"
;
return
$this
->redis->LPUSH(
$key
,
$value
);
}
public
function
rpush(
$key
,
$value
){
echo
"$key - $value \n"
;
return
$this
->redis->rpush(
$key
,
$value
);
}
public
function
lranges(
$key
,
$head
,
$tail
){
return
$this
->redis->lrange(
$key
,
$head
,
$tail
);
}
public
function
hset(
$tableName
,
$field
,
$value
){
return
$this
->redis->hset(
$tableName
,
$field
,
$value
);
}
public
function
hget(
$tableName
,
$field
){
return
$this
->redis->hget(
$tableName
,
$field
);
}
public
function
sets(
$keyArray
,
$timeout
) {
if
(
is_array
(
$keyArray
)) {
$retRes
=
$this
->redis->mset(
$keyArray
);
if
(
$timeout
> 0) {
foreach
(
$keyArray
as
$key
=>
$value
) {
$this
->redis->expire(
$key
,
$timeout
);
}
}
return
$retRes
;
}
else
{
return
"Call "
.
__FUNCTION__
.
" method parameter Error !"
;
}
}
public
function
get(
$key
) {
$result
=
$this
->redis->get(
$key
);
return
$result
;
}
public
function
gets(
$keyArray
) {
if
(
is_array
(
$keyArray
)) {
return
$this
->redis->mget(
$keyArray
);
}
else
{
return
"Call "
.
__FUNCTION__
.
" method parameter Error !"
;
}
}
public
function
keyAll() {
return
$this
->redis->keys('*');
}
public
function
del(
$key
) {
return
$this
->redis->
delete
(
$key
);
}
public
function
dels(
$keyArray
) {
if
(
is_array
(
$keyArray
)) {
return
$this
->redis->del(
$keyArray
);
}
else
{
return
"Call "
.
__FUNCTION__
.
" method parameter Error !"
;
}
}
public
function
increment(
$key
) {
return
$this
->redis->incr(
$key
);
}
public
function
decrement(
$key
) {
return
$this
->redis->decr(
$key
);
}
public
function
isExists(
$key
){
return
$this
->redis->exists(
$key
);
}
public
function
updateName(
$key
,
$newKey
){
return
$this
->redis->RENAMENX(
$key
,
$newKey
);
}
public
function
dataType(
$key
){
return
$this
->redis->type(
$key
);
}
public
function
flushAll() {
return
$this
->redis->flushAll();
}
public
function
redisOtherMethods() {
return
$this
->redis;
}
}</span>