Class RedisEngine
Redis storage engine for cache.
- CacheEngine
- RedisEngine
Properties summary
-
Redis
Redis wrapper. -
array
Settings
Inherited Properties
Method Summary
- Disconnects from the redis server
- Connects to a Redis server
-
Write data for key into cache if it doesn't exist already. If it already exists, it fails and returns false.
- Delete all keys from the cache
-
Increments the group value to simulate deletion of all keys under a group old values will remain in storage until they expire.
- Decrements the value of an integer cached key
- Delete a key from the cache
-
Returns the group value
for each of the configured groups If the group initial value was not found, then it initializes the group accordingly.
- Increments the value of an integer cached key
- Initialize the Cache Engine
- Read a key from the cache
- Write data for key into cache.
Method Detail
__destruct()source public
__destruct( )
Disconnects from the redis server
_connect()source protected
_connect( )
Connects to a Redis server
Returns
boolean
True if Redis server was connected
add( string $key , mixed $value , integer $duration )
Write data for key into cache if it doesn't exist already. If it already exists, it fails and returns false.
Parameters
- string
$key
- Identifier for the data.
- mixed
$value
- Data to be cached.
- integer
$duration
- How long to cache the data, in seconds.
Returns
boolean
True if the data was successfully cached, false on failure.
Link
https://github.com/phpredis/phpredis#setnx Overrides
CacheEngine::add()
clear()source public
clear( boolean $check )
Delete all keys from the cache
Parameters
- boolean
$check
Whether or not expiration keys should be checked. If true, no keys will be removed as cache will rely on redis TTL's.
Returns
boolean
True if the cache was successfully cleared, false otherwise
clearGroup()source public
clearGroup( string $group )
Increments the group value to simulate deletion of all keys under a group old values will remain in storage until they expire.
Parameters
- string
$group
- The group name to clear.
Returns
boolean
success
Overrides
CacheEngine::clearGroup()
decrement()source public
decrement( string $key , integer $offset 1 )
Decrements the value of an integer cached key
Parameters
- string
$key
- Identifier for the data
- integer
$offset
optional 1 - How much to subtract
Returns
New
decremented value, false otherwise
Throws
CacheException
when you try to decrement with compress = true
delete()source public
delete( string $key )
Delete a key from the cache
Parameters
- string
$key
- Identifier for the data
Returns
boolean
True if the value was successfully deleted, false if it didn't exist or couldn't be removed
groups()source public
groups( )
Returns the group value
for each of the configured groups If the group initial value was not found, then it initializes the group accordingly.
Returns
array
Overrides
CacheEngine::groups()
increment()source public
increment( string $key , integer $offset 1 )
Increments the value of an integer cached key
Parameters
- string
$key
- Identifier for the data
- integer
$offset
optional 1 - How much to increment
Returns
New
incremented value, false otherwise
Throws
CacheException
when you try to increment with compress = true
init()source public
init( array $settings array() )
Initialize the Cache Engine
Called automatically by the cache frontend To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
Parameters
- array
$settings
optional array() - array of setting for the engine
Returns
boolean
True if the engine has been successfully initialized, false if not
Overrides
CacheEngine::init()
read()source public
read( string $key )
Read a key from the cache
Parameters
- string
$key
- Identifier for the data
Returns
mixed
The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
write()source public
write( string $key , mixed $value , integer $duration )
Write data for key into cache.
Parameters
- string
$key
- Identifier for the data
- mixed
$value
- Data to be cached
- integer
$duration
- How long to cache the data, in seconds
Returns
boolean
True if the data was successfully cached, false on failure
Methods inherited from CacheEngine
gc( integer $expires null )
Garbage collection
Permanently remove all expired and deleted data
Parameters
- integer
$expires
optional null - [optional] An expires timestamp, invalidating all data before.
key( string $key )
Generates a safe key for use with cache engine storage engines.
Parameters
- string
$key
- the key passed over
Returns
mixed
string $key or false
settings()source public
settings( )
Cache Engine settings
Returns
array
settings
Properties detail
protected Redis
Redis wrapper.
public array
Settings
- server = string URL or ip to the Redis server host
- database = integer database number to use for connection
- port = integer port number to the Redis server (default: 6379)
- timeout = float timeout in seconds (default: 0)
- persistent = boolean Connects to the Redis server with a persistent connection (default: true)
- unix_socket = path to the unix socket file (default: false)