PHP 클래스 phpredis, zys

저자: :zqf
파일 보기 프로젝트 열기: qieangel2013/zys 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$_REDIS 实例名

공개 메소드들

메소드 설명
__construct ( $rconfig = '' ) 初始化
dbSize ( ) 获取数据库中key的数目
deinc ( $key, $type = 1, $n = 1 ) key值自增或者自减
delete ( $key = [] ) 删除某个key值
exists ( $key ) 判断某个key是否存在
get ( $key = null, $start = null, $end = null ) 获取某个key值 如果指定了start end 则返回key值的start跟end之间的字符
getKeys ( $key = null ) 获取满足给定pattern的所有key
getOption ( $option = [] ) 获取redis模式参数
hashDel ( $hash, $key ) 删除hash表中的key
hashExists ( $hash, $key ) 查询hash表中某个key是否存在
hashGet ( $hash, $key = [], $type ) 获取hash表的数据
hashInc ( $hash, $key, $inc ) 自增hash表中某个key的值
hashLen ( $hash ) 获取hash表中元素个数
hashSet ( $hash, $data ) 将key->value写入hash表中
hwSave ( $type, $time ) 将数据保存到硬盘 同步/异步
info ( ) 获取redis版本信息等详情
lastSave ( ) 获取上次成功将数据保存到磁盘的Unix时戳
listGet ( $list, $index, $end = null ) 获取list队列的index位置的元素值
listInsert ( $list, $location, $value1, $value2 ) 在list中值为$value1的元素前Redis::BEFORE或者后Redis::AFTER插入值为$value2的元素 如果list不存在,不会插入,如果$value1不存在,return -1
listPop ( $list1, $deriction, $list2 = null, $timeout ) 出队列
listPush ( $list, $value, $direction, $repeat ) 入队列
listRemove ( $list, $value, $count ) 删除list队列中count个值为value的元素
listSet ( $list, $index, $value = null ) 为list队列的index位置的元素赋值
listSize ( $list ) 获取队列中元素数
listTrim ( $list, $start, $end ) 截取list队列,保留start至end之间的元素
mset ( $data ) 同时给多个key赋值
persist ( $key ) 删除到期的key
ping ( ) 查看redis连接是否断开
rpoplpush ( $list1, $list2 ) pop出list1的尾部元素并将该元素push入list2的头部
set ( $key, $value, $type, $repeat, $time, $old ) 写入key-value
setAdd ( $set, $value = null, $stype, $score = null ) 将value写入set集合 如果value存在 不写入 返回false 如果是有序集合则根据score值更新该元素的顺序
setDeleteRange ( $set, $start, $end ) ***只针对有序集合操作 删除set中score从start到end的所有元素
setDiff ( $set, $newset = null ) 求差集 并可选是否将交集保存到新集合
setInter ( $set, $newset = null, $stype, $weight = [1], $function = 'SUM' ) 求交集 并可选是否将交集保存到新集合
setKeyExpire ( $key, $time ) 自增hash表中某个key的值
setMembers ( $set ) 返回set中所有元素
setMove ( $set1, $value = null, $stype, $set2 = null ) 移除set1中的value元素 如果指定了set2 则将该元素写入set2
setOption ( $option = [] ) 设置redis模式参数
setPop ( $set, $isdel ) 随机返回set中一个元素并可选是否删除该元素
setRange ( $set, $start, $end, $order, $score = false ) ***只针对有序集合操作 返回set中index从start到end的所有元素
setScore ( $set, $value, $inc = null ) ***只针对有序集合操作 获取set中某个元素的score 如果指定了inc参数 则给该元素的score增加inc值 如果没有该元素 则将该元素写入集合
setSearch ( $set, $value = null ) 查询set中是否有value元素
setSize ( $set, $stype, $start, $end ) 返回set中所有元素个数 有序集合要指定$stype=1 如果是有序集合并指定了$start和$end 则返回score在start跟end之间的元素个数
setSort ( $set, $option ) 排序 分页等
setUnion ( $set, $newset = null, $stype, $weight = [1], $function = 'SUM' ) 求并集 并可选是否将交集保存到新集合
strlen ( $key ) 获取某一key的value
tranCommit ( ) 提交完成事务
tranRollback ( ) 回滚事务
tranStart ( ) 开始进入事务操作
ttl ( $key ) 查询某个key的生存时间

비공개 메소드들

메소드 설명
connect ( $host, $port, $timeout, $dbname, $type ) 连接redis服务器

메소드 상세

__construct() 공개 메소드

初始化
public __construct ( $rconfig = '' )

dbSize() 공개 메소드

获取数据库中key的数目
public dbSize ( )

deinc() 공개 메소드

key值自增或者自减
public deinc ( $key, $type = 1, $n = 1 )
$key string key名
$type int 0:自减 1:自增 默认为1
$n int 自增步长 默认为1

delete() 공개 메소드

删除某个key值
public delete ( $key = [] )
$key array key数组

exists() 공개 메소드

判断某个key是否存在
public exists ( $key )
$key string 要查询的key名

get() 공개 메소드

获取某个key值 如果指定了start end 则返回key值的start跟end之间的字符
public get ( $key = null, $start = null, $end = null )
$key string/array 要获取的key或者key数组
$start int 字符串开始index
$end int 字符串结束index

getKeys() 공개 메소드

获取满足给定pattern的所有key
public getKeys ( $key = null )
$key regexp key匹配表达式 模式:user* 匹配以user开始的key

getOption() 공개 메소드

获取redis模式参数
public getOption ( $option = [] )
$option array 要获取的参数数组

hashDel() 공개 메소드

删除hash表中的key
public hashDel ( $hash, $key )
$hash string 哈希表名
$key mixed 表中存储的key名

hashExists() 공개 메소드

查询hash表中某个key是否存在
public hashExists ( $hash, $key )
$hash string 哈希表名
$key mixed 表中存储的key名

hashGet() 공개 메소드

获取hash表的数据
public hashGet ( $hash, $key = [], $type )
$hash string 哈希表名
$key mixed 表中要存储的key名 默认为null 返回所有key>value
$type int 要获取的数据类型 0:返回所有key 1:返回所有value 2:返回所有key->value

hashInc() 공개 메소드

自增hash表中某个key的值
public hashInc ( $hash, $key, $inc )
$hash string 哈希表名
$key mixed 表中存储的key名
$inc int 要增加的值

hashLen() 공개 메소드

获取hash表中元素个数
public hashLen ( $hash )
$hash string 哈希表名

hashSet() 공개 메소드

将key->value写入hash表中
public hashSet ( $hash, $data )
$hash string 哈希表名
$data array 要写入的数据 array('key'=>'value')

hwSave() 공개 메소드

将数据保存到硬盘 同步/异步
public hwSave ( $type, $time )
$type int 保存方式 0:同步 1:异步 默认0
$time int 是否要获取上次成功将数据保存到磁盘的Unix时戳 0:不返回时间 1:返回时间

info() 공개 메소드

获取redis版本信息等详情
public info ( )

lastSave() 공개 메소드

获取上次成功将数据保存到磁盘的Unix时戳
public lastSave ( )

listGet() 공개 메소드

获取list队列的index位置的元素值
public listGet ( $list, $index, $end = null )
$list string 队列名
$index int 队列元素开始位置 默认0
$end int 队列元素结束位置 $index=0,$end=-1:返回队列所有元素

listInsert() 공개 메소드

在list中值为$value1的元素前Redis::BEFORE或者后Redis::AFTER插入值为$value2的元素 如果list不存在,不会插入,如果$value1不存在,return -1
public listInsert ( $list, $location, $value1, $value2 )
$list string 队列名
$location int 插入位置 0:之前 1:之后
$value1 mixed 要查找的元素值
$value2 mixed 要插入的元素值

listPop() 공개 메소드

出队列
public listPop ( $list1, $deriction, $list2 = null, $timeout )
$list1 string 队列名
$deriction int 0:数据入队列头(左) 1:数据入队列尾(右) 默认为0
$list2 string 第二个队列名 默认null
$timeout int timeout为0:只获取list1队列的数据 timeout>0:如果队列list1为空 则等待timeout秒 如果还是未获取到数据 则对list2队列执行pop操作

listPush() 공개 메소드

入队列
public listPush ( $list, $value, $direction, $repeat )
$list string 队列名
$value mixed 入队元素值
$repeat int 判断value是否存在 0:不判断存在 1:判断存在 如果value存在则不入队列

listRemove() 공개 메소드

删除list队列中count个值为value的元素
public listRemove ( $list, $value, $count )
$list string 队列名
$value int 元素值
$count int 删除个数 0:删除所有 >0:从头部开始删除 <0:从尾部开始删除 默认为0删除所有

listSet() 공개 메소드

为list队列的index位置的元素赋值
public listSet ( $list, $index, $value = null )
$list string 队列名
$index int 队列元素位置
$value mixed 元素值

listSize() 공개 메소드

获取队列中元素数
public listSize ( $list )
$list string 队列名

listTrim() 공개 메소드

截取list队列,保留start至end之间的元素
public listTrim ( $list, $start, $end )
$list string 队列名
$start int 开始位置
$end int 结束位置

mset() 공개 메소드

同时给多个key赋值
public mset ( $data )
$data array key值数组 array('key0'=>'value0','key1'=>'value1')

persist() 공개 메소드

删除到期的key
public persist ( $key )
$key string key名

ping() 공개 메소드

查看redis连接是否断开
public ping ( )

rpoplpush() 공개 메소드

pop出list1的尾部元素并将该元素push入list2的头部
public rpoplpush ( $list1, $list2 )
$list1 string 队列名
$list2 string 队列名

set() 공개 메소드

写入key-value
public set ( $key, $value, $type, $repeat, $time, $old )
$key string 要存储的key名
$value mixed 要存储的值
$type int 写入方式 0:不添加到现有值后面 1:添加到现有值的后面 默认0
$repeat int 0:不判断重复 1:判断重复
$time float 过期时间(S)
$old int 1:返回旧的value 默认0

setAdd() 공개 메소드

将value写入set集合 如果value存在 不写入 返回false 如果是有序集合则根据score值更新该元素的顺序
public setAdd ( $set, $value = null, $stype, $score = null )
$set string 集合名
$value mixed 值
$stype int 集合类型 0:无序集合 1:有序集和 默认0
$score int 元素排序值

setDeleteRange() 공개 메소드

***只针对有序集合操作 删除set中score从start到end的所有元素
public setDeleteRange ( $set, $start, $end )
$set string 集合名
$start int 开始score
$end int 结束score

setDiff() 공개 메소드

求差集 并可选是否将交集保存到新集合
public setDiff ( $set, $newset = null )
$set array 集合名数组
$newset string 要保存到的集合名 默认为null 即不保存交集到新集合

setInter() 공개 메소드

求交集 并可选是否将交集保存到新集合
public setInter ( $set, $newset = null, $stype, $weight = [1], $function = 'SUM' )
$set array 集合名数组
$newset string 要保存到的集合名 默认为null 即不保存交集到新集合
$stype int 集合类型 0:无序集合 1:有序集和 默认0
$weight array 权重 执行function操作时要指定的每个集合的相同元素所占的权重 默认1
$function string 不同集合的相同元素的取值规则函数 SUM:取元素值的和 MAX:取最大值元素 MIN:取最小值元素

setKeyExpire() 공개 메소드

自增hash表中某个key的值
public setKeyExpire ( $key, $time )
$key string 哈希表名
$time mixed 表中存储的key名

setMembers() 공개 메소드

返回set中所有元素
public setMembers ( $set )
$set string 集合名

setMove() 공개 메소드

移除set1中的value元素 如果指定了set2 则将该元素写入set2
public setMove ( $set1, $value = null, $stype, $set2 = null )
$set1 string 集合名
$value mixed 值
$stype int 集合类型 0:无序集合 1:有序集和 默认0
$set2 string 集合名

setOption() 공개 메소드

设置redis模式参数
public setOption ( $option = [] )
$option array 参数数组键值对

setPop() 공개 메소드

随机返回set中一个元素并可选是否删除该元素
public setPop ( $set, $isdel )
$set string 集合名
$isdel int 是否删除该元素 0:不删除 1:删除 默认为0

setRange() 공개 메소드

***只针对有序集合操作 返回set中index从start到end的所有元素
public setRange ( $set, $start, $end, $order, $score = false )
$set string 集合名
$start int 开始Index
$end int 结束Index
$order int 排序方式 0:从小到大排序 1:从大到小排序 默认0
$score bool 元素排序值 false:返回数据不带score true:返回数据带score 默认false

setScore() 공개 메소드

***只针对有序集合操作 获取set中某个元素的score 如果指定了inc参数 则给该元素的score增加inc值 如果没有该元素 则将该元素写入集合
public setScore ( $set, $value, $inc = null )
$set string 集合名
$value mixed 元素值
$inc int 要给score增加的数值 默认是null 不执行score增加操作

setSearch() 공개 메소드

查询set中是否有value元素
public setSearch ( $set, $value = null )
$set string 集合名
$value mixed 值

setSize() 공개 메소드

返回set中所有元素个数 有序集合要指定$stype=1 如果是有序集合并指定了$start和$end 则返回score在start跟end之间的元素个数
public setSize ( $set, $stype, $start, $end )
$set string 集合名
$stype int 集合类型 0:无序集合 1:有序集和 默认0
$start int 开始index
$end int 结束index

setSort() 공개 메소드

排序 分页等
public setSort ( $set, $option )
$set string 集合名
$option array 选项

setUnion() 공개 메소드

求并集 并可选是否将交集保存到新集合
public setUnion ( $set, $newset = null, $stype, $weight = [1], $function = 'SUM' )
$set array 集合名数组
$newset string 要保存到的集合名 默认为null 即不保存交集到新集合
$stype int 集合类型 0:无序集合 1:有序集和 默认0
$weight array 权重 执行function操作时要指定的每个集合的相同元素所占的权重 默认1
$function string 不同集合的相同元素的取值规则函数 SUM:取元素值的和 MAX:取最大值元素 MIN:取最小值元素

strlen() 공개 메소드

获取某一key的value
public strlen ( $key )
$key string key名

tranCommit() 공개 메소드

提交完成事务
public tranCommit ( )

tranRollback() 공개 메소드

回滚事务
public tranRollback ( )

tranStart() 공개 메소드

开始进入事务操作
public tranStart ( )

ttl() 공개 메소드

查询某个key的生存时间
public ttl ( $key )
$key string 要查询的key名

프로퍼티 상세

$_REDIS 공개적으로 프로퍼티

实例名
public $_REDIS