Skip to content

Commit

Permalink
Added possiblity to connect to redis via a unix socket (#1055)
Browse files Browse the repository at this point in the history
* Added possiblity to connect to redis via a unix socket

* Improved redis via socket config usage and added config option to blueprints

* Updated Changelog

* Improved redis via socket by adding a default value and a placeholder in the blueprint
  • Loading branch information
Bernhard Altendorfer authored and rhukster committed Sep 21, 2016
1 parent afc7963 commit 584f4ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#improved)
* Add `batch()` function to Page Collection class
* Added new `cache.redis.socket` setting that allow to pass a UNIX socket as redis server

# v1.1.5
## 09/09/2016
Expand Down
7 changes: 7 additions & 0 deletions system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ form:
help: PLUGIN_ADMIN.MEMCACHED_PORT_HELP
placeholder: "11211"

cache.redis.socket:
type: text
size: medium
label: PLUGIN_ADMIN.REDIS_SOCKET
help: PLUGIN_ADMIN.REDIS_SOCKET_HELP
placeholder: "/var/run/redis/redis.sock"

cache.redis.server:
type: text
size: medium
Expand Down
2 changes: 2 additions & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ cache:
prefix: 'g' # Cache prefix string (prevents cache conflicts)
lifetime: 604800 # Lifetime of cached data in seconds (0 = infinite)
gzip: false # GZip compress the page output
redis:
socket: false # Path to redis unix socket (e.g. /var/run/redis/redis.sock), false = use server and port to connect

twig:
cache: true # Set to true to enable Twig caching
Expand Down
9 changes: 8 additions & 1 deletion system/src/Grav/Common/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,15 @@ public function getCacheDriver()

case 'redis':
$redis = new \Redis();
$redis->connect($this->config->get('system.cache.redis.server', 'localhost'),
$socket = $this->config->get('system.cache.redis.socket', false);

if ($socket) {
$redis->connect($socket);
} else {
$redis->connect($this->config->get('system.cache.redis.server', 'localhost'),
$this->config->get('system.cache.redis.port', 6379));
}

$driver = new DoctrineCache\RedisCache();
$driver->setRedis($redis);
break;
Expand Down

0 comments on commit 584f4ef

Please sign in to comment.