PHP Class Cml\Cache\Redis

Inheritance: extends Base
Show file Open project: linhecheng/cmlphp Class Usage Examples

Public Methods

Method Description
__construct ( $conf = false ) 使用的缓存配置 默认为使用default_cache配置的参数
__construct ( bool|array $conf = false ) 使用的缓存配置 默认为使用default_cache配置的参数
__destruct ( ) 定义析构方法。不用判断长短连接,长链接执行close无效
decrement ( mixed $key, integer $val = 1 ) : boolean 自减
delete ( mixed $key ) : boolean 删除对象
exists ( mixed $key ) : mixed 判断key值是否存在
get ( mixed $key ) : boolean | array 根据key取值
getInstance ( string $key = '' ) : Redis 返回实例便于操作未封装的方法
increment ( mixed $key, integer $val = 1 ) : boolean 自增
set ( mixed $key, mixed $value, integer $expire ) : boolean 存储对象
truncate ( ) 清洗已经存储的所有元素
update ( mixed $key, mixed $value, integer $expire ) : boolean | integer 更新对象

Private Methods

Method Description
hash ( $key ) : Redis 根据key获取redis实例 这边还是用取模的方式,一致性hash用php实现性能开销过大。取模的方式对只有几台机器的情况足够用了 如果有集群需要,直接使用redis3.0+自带的集群功能就好了。不管是可用性还是性能都比用php自己实现好

Method Details

__construct() public method

使用的缓存配置 默认为使用default_cache配置的参数
public __construct ( $conf = false )

__construct() public method

使用的缓存配置 默认为使用default_cache配置的参数
public __construct ( bool|array $conf = false )
$conf bool|array

__destruct() public method

定义析构方法。不用判断长短连接,长链接执行close无效
public __destruct ( )

decrement() public method

自减
public decrement ( mixed $key, integer $val = 1 ) : boolean
$key mixed 要自减的缓存的数据的key
$val integer 自减的进步值,默认为1
return boolean

delete() public method

删除对象
public delete ( mixed $key ) : boolean
$key mixed 要删除的数据的key
return boolean

exists() public method

判断key值是否存在
public exists ( mixed $key ) : mixed
$key mixed 要判断的缓存的数据的key
return mixed

get() public method

根据key取值
public get ( mixed $key ) : boolean | array
$key mixed 要获取的缓存key
return boolean | array | array

getInstance() public method

返回实例便于操作未封装的方法
public getInstance ( string $key = '' ) : Redis
$key string
return Redis

increment() public method

自增
public increment ( mixed $key, integer $val = 1 ) : boolean
$key mixed 要自增的缓存的数据的key
$val integer 自增的进步值,默认为1
return boolean

set() public method

存储对象
public set ( mixed $key, mixed $value, integer $expire ) : boolean
$key mixed 要缓存的数据的key
$value mixed 要缓存的值,除resource类型外的数据类型
$expire integer 缓存的有效时间 0为不过期
return boolean

truncate() public method

清洗已经存储的所有元素
public truncate ( )

update() public method

更新对象
public update ( mixed $key, mixed $value, integer $expire ) : boolean | integer
$key mixed 要更新的数据的key
$value mixed 要更新缓存的值,除resource类型外的数据类型
$expire integer 缓存的有效时间 0为不过期
return boolean | integer