Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
b5c73a37
Commit
b5c73a37
authored
Nov 25, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow redis connection to be configure directly in cache
fixes #1316
parent
38e5788e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
10 deletions
+49
-10
Cache.php
extensions/redis/Cache.php
+29
-10
README.md
extensions/redis/README.md
+20
-0
No files found.
extensions/redis/Cache.php
View file @
b5c73a37
...
...
@@ -30,13 +30,25 @@ use yii\base\InvalidConfigException;
* 'components' => [
* 'cache' => [
* 'class' => 'yii\redis\Cache',
* 'redis' => [
* 'hostname' => 'localhost',
* 'port' => 6379,
* 'database' => 0,
* ]
* ],
* ],
* ]
* ~~~
*
* Or if you have configured the redis connection as an application component, the following is sufficient:
*
* ~~~
* [
* 'components' => [
* 'cache' => [
* 'class' => 'yii\redis\Cache',
* // 'redis' => 'redis' // id of the connection application component
* ],
* 'redis' => [
* 'class' => 'yii\redis\Connection',
* 'hostname' => 'localhost',
* 'port' => 6379,
* 'database' => 0,
* ]
* ],
* ]
* ~~~
...
...
@@ -49,7 +61,9 @@ use yii\base\InvalidConfigException;
class
Cache
extends
\yii\caching\Cache
{
/**
* @var Connection|string the Redis [[Connection]] object or the application component ID of the Redis [[Connection]].
* @var Connection|string|array the Redis [[Connection]] object or the application component ID of the Redis [[Connection]].
* This can also be an array that is used to create a redis [[Connection]] instance in case you do not want do configure
* redis connection as an application component.
* After the Cache object is created, if you want to change this property, you should only assign it
* with a Redis [[Connection]] object.
*/
...
...
@@ -57,15 +71,20 @@ class Cache extends \yii\caching\Cache
/**
* Initializes the
Db
Cache component.
* This method will initialize the [[
db]] property to make sure it refers to a valid DB
connection.
* @throws InvalidConfigException if [[
db
]] is invalid.
* Initializes the
redis
Cache component.
* This method will initialize the [[
redis]] property to make sure it refers to a valid redis
connection.
* @throws InvalidConfigException if [[
redis
]] is invalid.
*/
public
function
init
()
{
parent
::
init
();
if
(
is_string
(
$this
->
redis
))
{
$this
->
redis
=
Yii
::
$app
->
getComponent
(
$this
->
redis
);
}
else
if
(
is_array
(
$this
->
redis
))
{
if
(
!
isset
(
$this
->
redis
[
'class'
]))
{
$this
->
redis
[
'class'
]
=
Connection
::
className
();
}
$this
->
redis
=
Yii
::
createObject
(
$this
->
redis
);
}
if
(
!
$this
->
redis
instanceof
Connection
)
{
throw
new
InvalidConfigException
(
"Cache::redis must be either a Redis connection instance or the application component ID of a Redis connection."
);
...
...
extensions/redis/README.md
View file @
b5c73a37
...
...
@@ -35,6 +35,26 @@ return [
];
```
If you only use the redis cache, you can also configure the parameters of the connection within the
cache component:
```
php
return
[
//....
'components'
=>
[
// ...
'cache'
=>
[
'class'
=>
'yii\redis\Cache'
,
'redis'
=>
[
'hostname'
=>
'localhost'
,
'port'
=>
6379
,
'database'
=>
0
,
],
],
]
];
```
Installation
------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment