Redis (DataSource) Plugin for CakePHP
- CakePHP 2.9.0 or greater.
- PHP 7.0.0 or greater.
- PhpRedis.
- Clone/Copy the files in this directory into
app/Plugin/Redis
- Ensure
require
is present incomposer.json
. This will install the plugin intoapp/Plugin/Redis
:
{
"require": {
"oefenweb/cakephp-redis": "dev-master"
}
}
- Ensure the plugin is loaded in
app/Config/bootstrap.php
by calling:
CakePlugin::load('Redis');
- Ensure the plugin is configured in
app/Config/database.php
by specifying:
<?php
class DATABASE_CONFIG {
public $redis = [
'datasource' => 'Redis.RedisSource',
'host' => '127.0.0.1',
'port' => 6379,
'password' => '',
'database' => 0,
'timeout' => 0,
'persistent' => false,
'unix_socket' => '',
'prefix' => '',
];
Get a (connected / configured) Redis
instance:
<?php
App::uses('ConnectionManager', 'Model');
$Redis = ConnectionManager::getDataSource('redis');
Call Redis's ping command:
$Redis->ping();