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
38e5788e
Commit
38e5788e
authored
Nov 25, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
* 'master' of github.com:yiisoft/yii2: removed unneeded setting. refactored redis cache.
parents
e837e44a
c6318050
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
43 deletions
+37
-43
main.php
apps/advanced/backend/config/main.php
+0
-3
main.php
apps/advanced/frontend/config/main.php
+0
-3
web.php
apps/basic/config/web.php
+0
-3
Cache.php
extensions/redis/Cache.php
+37
-34
No files found.
apps/advanced/backend/config/main.php
View file @
38e5788e
...
...
@@ -17,9 +17,6 @@ return [
'modules'
=>
[],
'extensions'
=>
require
(
$rootDir
.
'/vendor/yiisoft/extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
],
'db'
=>
$params
[
'components.db'
],
'cache'
=>
$params
[
'components.cache'
],
'mail'
=>
$params
[
'components.mail'
],
...
...
apps/advanced/frontend/config/main.php
View file @
38e5788e
...
...
@@ -18,9 +18,6 @@ return [
],
'extensions'
=>
require
(
$rootDir
.
'/vendor/yiisoft/extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
],
'db'
=>
$params
[
'components.db'
],
'cache'
=>
$params
[
'components.cache'
],
'mail'
=>
$params
[
'components.mail'
],
...
...
apps/basic/config/web.php
View file @
38e5788e
...
...
@@ -5,9 +5,6 @@ $config = [
'basePath'
=>
dirname
(
__DIR__
),
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
],
'cache'
=>
[
'class'
=>
'yii\caching\FileCache'
,
],
...
...
extensions/redis/Cache.php
View file @
38e5788e
...
...
@@ -7,6 +7,9 @@
namespace
yii\redis
;
use
Yii
;
use
yii\base\InvalidConfigException
;
/**
* Redis Cache implements a cache application component based on [redis](http://redis.io/) key-value store.
*
...
...
@@ -46,13 +49,30 @@ namespace yii\redis;
class
Cache
extends
\yii\caching\Cache
{
/**
* @var string the id of the application component to use as the redis connection.
* It should be configured as a [[yii\redis\Connection]]. Defaults to `redis`.
* @var Connection|string the Redis [[Connection]] object or the application component ID of the Redis [[Connection]].
* After the Cache object is created, if you want to change this property, you should only assign it
* with a Redis [[Connection]] object.
*/
public
$
connectionId
=
'redis'
;
public
$
redis
=
'redis'
;
/**
* Initializes the DbCache component.
* This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
* @throws InvalidConfigException if [[db]] is invalid.
*/
public
function
init
()
{
parent
::
init
();
if
(
is_string
(
$this
->
redis
))
{
$this
->
redis
=
Yii
::
$app
->
getComponent
(
$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."
);
}
}
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
...
...
@@ -64,9 +84,7 @@ class Cache extends \yii\caching\Cache
*/
public
function
exists
(
$key
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
return
(
bool
)
$connection
->
executeCommand
(
'EXISTS'
,
[
$this
->
buildKey
(
$key
)]);
return
(
bool
)
$this
->
redis
->
executeCommand
(
'EXISTS'
,
[
$this
->
buildKey
(
$key
)]);
}
/**
...
...
@@ -74,9 +92,7 @@ class Cache extends \yii\caching\Cache
*/
protected
function
getValue
(
$key
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
return
$connection
->
executeCommand
(
'GET'
,
[
$key
]);
return
$this
->
redis
->
executeCommand
(
'GET'
,
[
$key
]);
}
/**
...
...
@@ -84,9 +100,7 @@ class Cache extends \yii\caching\Cache
*/
protected
function
getValues
(
$keys
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
$response
=
$connection
->
executeCommand
(
'MGET'
,
$keys
);
$response
=
$this
->
redis
->
executeCommand
(
'MGET'
,
$keys
);
$result
=
[];
$i
=
0
;
foreach
(
$keys
as
$key
)
{
...
...
@@ -100,13 +114,11 @@ class Cache extends \yii\caching\Cache
*/
protected
function
setValue
(
$key
,
$value
,
$expire
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
if
(
$expire
==
0
)
{
return
(
bool
)
$
connection
->
executeCommand
(
'SET'
,
[
$key
,
$value
]);
return
(
bool
)
$
this
->
redis
->
executeCommand
(
'SET'
,
[
$key
,
$value
]);
}
else
{
$expire
=
(
int
)
(
$expire
*
1000
);
return
(
bool
)
$
connection
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'PX'
,
$expire
]);
return
(
bool
)
$
this
->
redis
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'PX'
,
$expire
]);
}
}
...
...
@@ -115,9 +127,6 @@ class Cache extends \yii\caching\Cache
*/
protected
function
setValues
(
$data
,
$expire
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
$args
=
[];
foreach
(
$data
as
$key
=>
$value
)
{
$args
[]
=
$key
;
...
...
@@ -126,17 +135,17 @@ class Cache extends \yii\caching\Cache
$failedKeys
=
[];
if
(
$expire
==
0
)
{
$
connection
->
executeCommand
(
'MSET'
,
$args
);
$
this
->
redis
->
executeCommand
(
'MSET'
,
$args
);
}
else
{
$expire
=
(
int
)
(
$expire
*
1000
);
$
connection
->
executeCommand
(
'MULTI'
);
$
connection
->
executeCommand
(
'MSET'
,
$args
);
$
this
->
redis
->
executeCommand
(
'MULTI'
);
$
this
->
redis
->
executeCommand
(
'MSET'
,
$args
);
$index
=
[];
foreach
(
$data
as
$key
=>
$value
)
{
$
connection
->
executeCommand
(
'PEXPIRE'
,
[
$key
,
$expire
]);
$
this
->
redis
->
executeCommand
(
'PEXPIRE'
,
[
$key
,
$expire
]);
$index
[]
=
$key
;
}
$result
=
$
connection
->
executeCommand
(
'EXEC'
);
$result
=
$
this
->
redis
->
executeCommand
(
'EXEC'
);
array_shift
(
$result
);
foreach
(
$result
as
$i
=>
$r
)
{
if
(
$r
!=
1
)
{
...
...
@@ -152,13 +161,11 @@ class Cache extends \yii\caching\Cache
*/
protected
function
addValue
(
$key
,
$value
,
$expire
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
if
(
$expire
==
0
)
{
return
(
bool
)
$
connection
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'NX'
]);
return
(
bool
)
$
this
->
redis
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'NX'
]);
}
else
{
$expire
=
(
int
)
(
$expire
*
1000
);
return
(
bool
)
$
connection
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'PX'
,
$expire
,
'NX'
]);
return
(
bool
)
$
this
->
redis
->
executeCommand
(
'SET'
,
[
$key
,
$value
,
'PX'
,
$expire
,
'NX'
]);
}
}
...
...
@@ -167,9 +174,7 @@ class Cache extends \yii\caching\Cache
*/
protected
function
deleteValue
(
$key
)
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
return
(
bool
)
$connection
->
executeCommand
(
'DEL'
,
[
$key
]);
return
(
bool
)
$this
->
redis
->
executeCommand
(
'DEL'
,
[
$key
]);
}
/**
...
...
@@ -177,8 +182,6 @@ class Cache extends \yii\caching\Cache
*/
protected
function
flushValues
()
{
/** @var Connection $connection */
$connection
=
\Yii
::
$app
->
getComponent
(
$this
->
connectionId
);
return
$connection
->
executeCommand
(
'FLUSHDB'
);
return
$this
->
redis
->
executeCommand
(
'FLUSHDB'
);
}
}
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