This extension provides the [redis](http://redis.io/) key-value store support for the Yii2 framework.
It includes a `Cache` class and implents the `ActiveRecord` pattern that allows you to store active
records in redis.
To use this extension, you have to configure the Connection class in your application configuration:
```php
return[
//....
'components'=>[
'redis'=>[
'class'=>'yii\redis\Connection',
'hostname'=>'localhost',
'port'=>6379,
'database'=>0,
],
]
];
```
To use the `Cache` component, you also have to configure the `cache` component to be `yii\redis\Cache`:
```php
return[
//....
'components'=>[
// ...
'cache'=>[
'class'=>'yii\redis\Cache',
],
]
];
```
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-redis "*"
```
or add
```json
"yiisoft/yii2-redis":"*"
```
to the require section of your composer.json.
Using the redis ActiveRecord
----------------------------
For general information on how to use yii's ActiveRecord please refer to the [guide](https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md).
For defining a redis ActiveRecord class your record class needs to extend from `yii\redis\ActiveRecord` and
implement at least the `attributes()` method to define the attributes of the record.
A primary key can be defined via [[primaryKey()]] which defaults to `id` if not specified.
The primaryKey needs to be part of the attributes so make sure you have an `id` attribute defined if you do
not specify your own primary key.
The following is an example model called `Customer`: