This extension provides the redis key-value store support for the Yii framework 2.0.
It includes a Cache
and Session
storage handler and implements the ActiveRecord
pattern that allows
you to store active records in redis.
For license information check the LICENSE-file.
Documentation is at https://github.com/yiisoft/yii2-redis/blob/master/docs/guide/README.md.
At least redis version 2.6.12 is required for all components to work properly.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yiisoft/yii2-redis:"~2.0.0"
or add
"yiisoft/yii2-redis": "~2.0.0"
to the require section of your composer.json.
To use this extension, you have to configure the Connection class in your application configuration:
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
]
];
SSL configuration example:
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6380,
'database' => 0,
'useSSL' => true,
// Use contextOptions for more control over the connection (https://www.php.net/manual/en/context.php), not usually needed
'contextOptions' => [
'ssl' => [
'local_cert' => '/path/to/local/certificate',
'local_pk' => '/path/to/local/private_key',
],
],
],
],
];
Configuring The Connection Scheme
By default, Redis will use the tcp scheme when connecting to your Redis server; however, you may use TLS / SSL encryption by specifying a scheme configuration option in your application configuration:
return [
//....
'components' => [
'redis' => [
//....
'scheme' => 'tls'
]
]
];
mget()
for big list of keys (alx-xc, rob006)'scheme' => 'tls'
(tychovbh)Cache::getValue()
now returns false
in case of missing key (rhertogh)protected function sendRawCommand()
(ilyaplot)Connection::$username
for using username for authentication (samdark, rvkulikov)Connection::isActive()
returns false
when the connection is active (cornernote)yii\web\Session
(rhertogh)cache/flush-all
command when cache component is using shared database (rob006)Instance::ensure()
to initialize Session::$redis
(rob006)$timeout
is used in Mutex::acquire()
(rob006)>
, <
, >=
and <=
conditions support in ActiveQuery (nailfor, zacksleo)ActiveRecord::findOne()
and ::findAll()
(cebe)not between
and not
conditions which where not working correctly (cebe, ak1987)yii\redis\SocketException
for these (cebe)yii\redis\ActiveRecord::deleteAll()
with condition (samdark)Mutex
that implements a Redis based mutex (turboezh, sergeymakinen)Connection::$database
to null
to avoid sending a SELECT
command after connection (cebe)\yii\db\QueryInterface::emulateExecution()
(samdark)@method
documentation for redis commands (cebe)Connection::$socketClientFlags
property for connection flags to be passed to stream_socket_client()
(hugh-lee)BLPOP
command to $redisCommands
(samdark)GEO*
commands to $redisCommands
(leadermt)mget()
(pyurin)true
is returned instead, now only OK
will result in a true
while all other values are returned as is (cebe)null
and boolean values (samdark, cebe)unlinkAll()
-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)init
event to ActiveQuery
classes (qiangxue)afterSave()
so information about changed attributes is available in afterSave
-event (cebe)ActiveRecord::create()
to populateRecord()
and changed signature. This method will not call instantiate() anymore (cebe)ActiveRelation
class and moved the functionality to ActiveQuery
.
All relational queries are now directly served by ActiveQuery
allowing to use
custom scopes in relations (cebe)
Comments