ASRedis
extends ASObject
in
内存数据库 ASRedis
当前主要解决 数据库缓存 php-redis扩展 -> https://github.com/phpredis/phpredis
- REDIS for 持久化数据支持 可以将大量重复查询 缓存到REDIS服务器 降低数据库压力
- 根据请求的具体参数生成hashid 每个hash有效期 由服务器默认配置 可以针对每一个temp进行expire设置
- Cache是存储到Key String中, 而缓存跟踪是存储到Set中的
Table of Contents
$host | ||
---|---|---|
$port | ||
$password | ||
$connection | ||
$connected | ||
$enabled | ||
$CLASSNAME | 类名 | string |
$CLASSNAME | 类名 | string |
$result | 结果包装器 | ASResult |
shared() | ASRedis | |
__construct() | ASObject constructor. | mixed |
connect() | 连接REDIS数据库 connect to Redis | ASRedis |
isEnabled() | 是否可用 isEnabled | bool |
close() | 关闭连接 close | bool |
cache() | 缓存数据 cache | bool |
has() | 是否存在缓存 Is a cache exist | bool |
read() | 获取缓存 read cache | ASResult |
track() | 缓存追踪 track cache | bool |
update() | mixed | |
clear() | 缓存清理 clear | bool |
get() | 获取Key/String | string|bool |
set() | 存储Key/String set key & value | bool |
increase() | mixed | |
remove() | mixed | |
timeRemain() | mixed | |
isExist() | mixed | |
ping() | mixed | |
analysisKeys() | mixed | |
info() | mixed | |
flush() | mixed | |
__construct() | ASObject constructor. | mixed |
take() | 设置主体别称 Alias of setContent | $this |
setContent() | 设置结果包装中的主数据 set content of result | mixed |
sign() | 设置方法签名 Set method sign | mixed |
feedback() | 返回结果 通用 Returning result to the caller | ASResult |
error() | 返回错误 Returning Error result | ASResult |
success() | 返回成功 Return Success result | ASResult |
Properties
$host
private
mixed
$host
$port
private
mixed
$port
$password
private
mixed
$password
$connection
private
mixed
$connection
$connected
private
mixed
$connected
= false
$enabled
private
mixed
$enabled
= ""
$CLASSNAME
类名
public
string
$CLASSNAME
= "ASRedis"
$CLASSNAME
类名
protected
string
$CLASSNAME
$result
结果包装器
public
ASResult
$result
Methods
shared()
public
static shared(
)
: ASRedis
Return values
ASRedis__construct()
ASObject constructor.
public
__construct(
[ $host :
string|null
= null ]
[, $port :
int|null
= null ]
[, $password :
string|null
= null ]
)
: mixed
Parameters
- $host : string|null = null
- $port : int|null = null
- $password : string|null = null
Return values
mixedconnect()
连接REDIS数据库 connect to Redis
public
connect(
)
: ASRedis
Return values
ASRedis —( 连接尝试后会修改 enabled属性 成功1 失败-1 默认0 )
isEnabled()
是否可用 isEnabled
public
isEnabled(
)
: bool
Return values
boolclose()
关闭连接 close
public
close(
)
: bool
Return values
boolcache()
缓存数据 cache
public
cache(
$params :
mixed
, $value :
mixed
[, $expireDuration :
int
= 3600 ]
)
: bool
Parameters
- $params : mixed
操作参数(将自动转为hash)
- $value : mixed
值
- $expireDuration : int = 3600
有效时间
Return values
boolhas()
是否存在缓存 Is a cache exist
public
has(
$params :
mixed
)
: bool
Parameters
- $params : mixed
查询参数
Tags
Return values
boolread()
获取缓存 read cache
public
read(
$params :
mixed
)
: ASResult
Parameters
- $params : mixed
查询参数
Return values
ASResulttrack()
缓存追踪 track cache
public
track(
$setid :
string
, $uniqid :
string
, $hashID :
mixed
)
: bool
基于Cache只能由cacheId索引、不具备关系数据库的结构,所以一个ID内容可能在多个缓存中被使用,更新内容时我们则应当通知删除或更新缓存 缓存追踪用于追踪一个相关的ID内容是否被缓存,分别在哪些缓存中 setid用于标识uniqid所在的集合(数据表名称或是某个数据用法) 如 user:userid , media:imageid 这里的setid不应该过于细化、应当是多个相关表数据集合后的统称,否则追踪难度较高 容易在通知丢失目标、遗漏通知 基本原则是 相互独立的模块,独立追踪。 如:鉴权不会影响用户资料, 订单不会影响用户资料。 例: ACCESS:userid , USER:userid, ORDER:userid 可以分别用于鉴权模块、用户信息模块、订单模块的跟踪。 无需再进一步细分。
Parameters
- $setid : string
[集合ID]
- $uniqid : string
[表唯一ID]
- $hashID : mixed
[缓存ID]
Tags
Return values
boolupdate()
public
update(
$setid :
string
, $uniqid :
string
)
: mixed
Parameters
- $setid : string
- $uniqid : string
Return values
mixedclear()
缓存清理 clear
public
clear(
$setid :
string
, $uniqid :
string
)
: bool
Parameters
- $setid : string
集合ID
- $uniqid : string
表唯一ID
Return values
boolget()
获取Key/String
public
get(
$key :
string
)
: string|bool
Parameters
- $key : string
查询key
Return values
string|boolset()
存储Key/String set key & value
public
set(
$key :
string
, $value :
string
, $expireDuration :
int
)
: bool
Parameters
- $key : string
- $value : string
- $expireDuration : int
Return values
boolincrease()
public
increase(
$key :
mixed
[, $number :
mixed
= 1 ]
)
: mixed
Parameters
- $key : mixed
- $number : mixed = 1
Return values
mixedremove()
public
remove(
$key :
mixed
)
: mixed
Parameters
- $key : mixed
Return values
mixedtimeRemain()
public
timeRemain(
$key :
mixed
)
: mixed
Parameters
- $key : mixed
Return values
mixedisExist()
public
isExist(
$key :
mixed
)
: mixed
Parameters
- $key : mixed
Return values
mixedping()
public
ping(
)
: mixed
Return values
mixedanalysisKeys()
public
analysisKeys(
)
: mixed
Return values
mixedinfo()
public
info(
[ $listArray :
bool
= false ]
)
: mixed
Parameters
- $listArray : bool = false
Return values
mixedflush()
public
flush(
)
: mixed
Return values
mixed__construct()
ASObject constructor.
public
__construct(
)
: mixed
Return values
mixedtake()
设置主体别称 Alias of setContent
public
take(
$content :
)
: $this
Parameters
Return values
$thissetContent()
设置结果包装中的主数据 set content of result
public
setContent(
$content :
)
: mixed
Parameters
Return values
mixedsign()
设置方法签名 Set method sign
public
sign(
$sign :
)
: mixed
Parameters
Return values
mixedfeedback()
返回结果 通用 Returning result to the caller
public
feedback(
[ $status :
int|null
= null ]
[, $message :
string|null
= null ]
[, $sign :
string|null
= null ]
)
: ASResult
Parameters
- $status : int|null = null
- $message : string|null = null
- $sign : string|null = null
Return values
ASResulterror()
返回错误 Returning Error result
public
error(
$status :
int
, $message :
string
[, $sign :
string|null
= null ]
)
: ASResult
Parameters
- $status : int
- $message : string
- $sign : string|null = null
Return values
ASResultsuccess()
返回成功 Return Success result
public
success(
[ $message :
string|null
= null ]
[, $sign :
string|null
= null ]
)
: ASResult
Parameters
- $message : string|null = null
- $sign : string|null = null