This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
163 lines (112 loc) · 4.47 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
sfRediskaPlugin
============
sfRediskaPlugin provides Symfony caching with Redis via Rediska (as defined in app.yml and factories.yml), and additionally allows a simple proxy interface to Rediska instances.
Also, a Doctrine Redis driver is provided (also using Rediska) for query/result caching.
Installation
---
There are several ways you can install the plugin:
**Clone from git**
Clone from our plugin github repository to your Symfony project plugins directory:
`git clone http://github.com/mastermix/sfRediskaPlugin.git`
**Add as submodule**
Add plugin github repository to you project repository as git submodule:
`git submodule add http://github.com/mastermix/sfRediskaPlugin.git plugins/sfRediskaPlugin`
**Export from SVN**
Export from plugin SVN repository to your Symfony project plugins directory:
`svn export http://svn.symfony-project.com/plugins/sfRediskaPlugin`
**Add as externals**
Add plugin SVN repository to you project repository as externals:
`svn propset svn:externals "plugins/sfRediskaPlugin http://svn.symfony-project.com/plugins/sfRediskaPlugin" .`
The SVN repository is automatically synchronised whenever a commit is made to the github repository.
Enable sfRediskaPlugin
---
Don't forget to enable the plugin in your ProjectConfiguration.class.php:
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->enablePlugins('sfRediskaPlugin');
}
}
Configuration
---
First of all, lets configure your Rediska instances (eg. app, otherstuff) in app.yml:
all:
rediska:
app:
servers:
server_01:
host: 127.0.0.1
persistent: true
otherstuff:
servers:
server_01:
host: 127.0.0.1
persistent: true
server_02:
host: 127.0.0.1
port: 6380
persistent: true
All configuration parameters that Rediska offers when setting up a Rediska instance are available here.
Now we can use these instances to configure a great number of things!
In the above example, we are going to use the `app` instance as the storage for Symfony internal caching, and `otherstuff` for caching other critical data.
Symfony Caches
---
Symfony provides the ability to cache critical parts of your application - session storage, routing, and the view cache.
To configure sfRediskaPlugin for session storage:
storage:
class: sfCacheSessionStorage
param:
cache:
class: sfRediskaCache
param:
lifetime: 86400
prefix: %SF_APP_DIR%
instance: app
For routing:
routing:
class: sfPatternRouting
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
cache:
class: sfRediskaCache
param:
lifetime: 86400
prefix: routing:%SF_APP%:%SF_ENVIRONMENT%
instance: app
For view cache:
view_cache:
class: sfRediskaCache
param:
instance: app
prefix: view:%SF_APP%:%SF_ENVIRONMENT%
Rediska Usage
---
You may also use sfRediskaPlugin to directly use any Rediska instance.
These are only instantiated once per page load for efficiency.
Heres an example:
$redis = sfRediska::getInstance('otherstuff');
$redis->pipeline()
->addToSortedSet(...)
->deleteFromSortedSet(..)
->delete(..)
->execute();
As you can see all the Rediska commands are fully accessible this way.
Doctrine Driver
---
To setup the Rediska Doctrine driver, first you must edit your application configuration file, eg. frontendConfiguration.class.php
public function configureDoctrine(Doctrine_Manager $manager)
{
$cacheDriver = new Doctrine_Cache_Redis(array('instance' => 'otherstuff', 'prefix' => 'dql:'));
$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
}
**NOTE:** ProjectConfiguration.class.php cannot be used as sfRediskaPlugin depends on configuration variables set at application level.
Links
---
Rediska - [http://rediska.geometria-lab.net/][1]
[1]: http://rediska.geometria-lab.net/
Thanks
---
Credit is due to Thomas Parisot and Benjamin Viellard for their individual plugin contributions.
Some implementation ideas from their plugins have also been considered when developing this plugin.