Properties

$keyPrefix

$keyPrefix : string

Type

string — Redis key前缀

$hashKey

$hashKey : boolean

Type

boolean — 是否需要hash key

$phpSerialize

$phpSerialize : boolean

Type

boolean — 是否启用PHP序列化

$redisSerialize

$redisSerialize : boolean

Type

boolean — 是否启用Redis序列化

Methods

__construct()

__construct(\PG\MSF\Pools\RedisAsynPool  $redisAsynPool) 

CoroutineRedisProxy constructor.

Parameters

\PG\MSF\Pools\RedisAsynPool $redisAsynPool

Redis连接池对象

cache()

cache(\PG\MSF\Helpers\Context  $context, string  $key, string  $value = '', integer  $expire) : mixed|\PG\MSF\Coroutine\Redis

redis cache 操作封装

Parameters

\PG\MSF\Helpers\Context $context

请求上下文对象

string $key

Redis Key

string $value

Redis Value

integer $expire

过期时间,单位秒

Returns

mixed|\PG\MSF\Coroutine\Redis

evalMock()

evalMock(\PG\MSF\Helpers\Context  $context, string  $script, array  $args = array(), integer  $numKeys) : array

在redis执行lua脚本,因为redis原生方法eval是php的保留关键字,所以用该方法名代替 会根据$args参数中的缓存key进行redis实例选择

Parameters

\PG\MSF\Helpers\Context $context

上下文

string $script

Lua脚本代码

array $args

参数

integer $numKeys

脚本用到的redis的key的数量

Throws

Returns

array —

redis中执行的Lua脚本,不支持直接返回多维数组,需要将多维数组转成json返回 本方法的返回值会对Lua脚本的返回值进行封装:

  1. 如果脚本中需要返回多个key的操作结果,Lua脚本的返回值格式请如下,需要是json:

Examples

key1 : '' or array(), key2 : '' or array(), ... } 本方法会将各个实例的返回值按照缓存key进行合并,然后返作为数组返回
** File not found : { **
key1 => '' or array(), key2 => '' or array(), ... ] 2. 如果只有一个key的操作结果,Lua脚本的返回值就无需按照key封装成数组,比如:
** File not found : [ **
或者 array(value1, value2, ...) 本方法会将这些值直接返回 3. 如果redis中本身存的就是未做序列化的json,该方法会自己将json解析成数组返回:
** File not found : true **
value2, ...)
** File not found : array(value1, **

__call()

__call(string  $name, array  $arguments) : array|boolean|mixed

__call魔术方法

Parameters

string $name

Redis指令

array $arguments

Redis指令参数

Returns

array|boolean|mixed

generateUniqueKey()

generateUniqueKey(string  $key) : string

生成唯一Redis Key

Parameters

string $key

a key identifying a value to be cached

Returns

string —

a key generated from the provided key which ensures the uniqueness across applications

serializeHandler()

serializeHandler(mixed  $data, boolean  $phpSerialize = false) : string

序列化

Parameters

mixed $data

待序列化数据

boolean $phpSerialize

是否启动PHP序列化

Returns

string

unSerializeHandler()

unSerializeHandler(mixed  $data, array  $keys = array(), integer  $len) : array|boolean|mixed

反序列化

Parameters

mixed $data

响应数据

array $keys

操作的多个Key列表

integer $len

操作的数量

Returns

array|boolean|mixed

canUnserialize()

canUnserialize(string  $string) : boolean

是否可以反序列化

Parameters

string $string

待反序列化数据

Returns

boolean

realUnserialize()

realUnserialize(string  $data) : mixed|string

真正反序列化

Parameters

string $data

待反序列化数据

Returns

mixed|string