Permalink
Browse files

Setup REDIS to store the sessions.

  • Loading branch information...
1 parent e2450db commit 58bc2e149f84d6e9f1083a01fbfee0d2084d9180 @damienalexandre damienalexandre committed Nov 12, 2015
Showing with 81 additions and 10 deletions.
  1. +9 −5 README.md
  2. +2 −1 composer.json
  3. +53 −3 composer.lock
  4. +17 −1 src/SantaKernel.php
View
@@ -12,17 +12,19 @@ srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platfor
- If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.
- Give your heroku details to Damien to be able to deploy
+
$ heroku login
$ heroku git:remote -a slack-secret-santa
-
-Deploy your application : Commit your code to the repository and deploy it to Heroku using Git.
-
- $ git add .
- $ git commit -am "make it better"
+ $ heroku plugins:install heroku-redis
$ git push heroku master
## Run the project
+The app require:
+
+- a Redis server
+- PHP 5.6+
+
As we rely on env variables, we cannot use `server:run`. From `web/`:
SLACK_CLIENT_SECRET=TOTO SLACK_CLIENT_ID=TOTO php -d variables_order=EGPCS -S 127.0.0.1:8000 ../etc/router.php
@@ -31,3 +33,5 @@ Variables are:
- SLACK_CLIENT_SECRET: Application secret from Slack;
- SLACK_CLIENT_ID: Application id from Slack;
+- REDIS_URL: The full redis connexion url (default `redis://localhost:6379`)
+
View
@@ -20,7 +20,8 @@
"require": {
"bramdevries/oauth2-slack": "^0.1.0",
"cleentfaar/slack": "^0.17.1",
- "symfony/symfony": "2.8.x@dev"
+ "symfony/symfony": "2.8.x@dev",
+ "predis/predis": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
View
@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "d5ba6a59f9fc7ed44940ce880640954b",
- "content-hash": "3b88dc8dfe74b83d2fb656f92874fb20",
+ "hash": "87f426aee8b6eaaaa44903dc97dfa9be",
+ "content-hash": "2a679bfd5ba10a97db84f8ed20ac2996",
"packages": [
{
"name": "bramdevries/oauth2-slack",
@@ -1189,6 +1189,56 @@
"time": "2015-07-25 16:39:46"
},
{
+ "name": "predis/predis",
+ "version": "v1.0.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/nrk/predis.git",
+ "reference": "84060b9034d756b4d79641667d7f9efe1aeb8e04"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/nrk/predis/zipball/84060b9034d756b4d79641667d7f9efe1aeb8e04",
+ "reference": "84060b9034d756b4d79641667d7f9efe1aeb8e04",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "suggest": {
+ "ext-curl": "Allows access to Webdis when paired with phpiredis",
+ "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Predis\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Daniele Alessandri",
+ "email": "suppakilla@gmail.com",
+ "homepage": "http://clorophilla.net"
+ }
+ ],
+ "description": "Flexible and feature-complete PHP client library for Redis",
+ "homepage": "http://github.com/nrk/predis",
+ "keywords": [
+ "nosql",
+ "predis",
+ "redis"
+ ],
+ "time": "2015-07-30 18:34:15"
+ },
+ {
"name": "psr/http-message",
"version": "1.0",
"source": {
@@ -1734,7 +1784,7 @@
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/symfony/zipball/cbaa9c4eac6bb0cac60d0cba06a93ff69e269f4c",
+ "url": "https://api.github.com/repos/symfony/symfony/zipball/fef28b2fa143119161e421a5c8ecd558189d2938",
"reference": "cbaa9c4eac6bb0cac60d0cba06a93ff69e269f4c",
"shasum": ""
},
View
@@ -2,6 +2,8 @@
namespace Joli\SlackSecretSanta;
+use Predis\Client;
+use Predis\Session\Handler;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
@@ -79,7 +81,10 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
{
$c->loadFromExtension('framework', [
'secret' => 'NotSoRandom...:)',
- 'session' => true,
+ 'session' => [
+ 'handler_id' => 'session.handler.predis',
+ 'name' => 'santaSession',
+ ],
]);
$c->loadFromExtension('twig', [
'paths' => [
@@ -92,6 +97,10 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
$_ENV['SLACK_CLIENT_ID'] = 'dummy';
}
+ if (empty($_ENV['REDIS_URL'])) {
+ $_ENV['REDIS_URL'] = 'redis://localhost:6379';
+ }
+
// Slack application credentials
$c->setParameter('slack.client_secret', $_ENV['SLACK_CLIENT_SECRET']);
$c->setParameter('slack.client_id', $_ENV['SLACK_CLIENT_ID']);
@@ -102,6 +111,13 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
$controller->addArgument(new Reference('twig'));
$controller->addArgument(new Parameter('slack.client_id'));
$controller->addArgument(new Parameter('slack.client_secret'));
+
+ $sessionHandler = $c->register('session.handler.predis', Handler::class);
+ $sessionHandler->setPublic(false);
+ $sessionHandler->addArgument(new Reference('predis'));
+
+ $predis = $c->register('predis', Client::class);
+ $predis->addArgument($_ENV['REDIS_URL']);
}
/**

0 comments on commit 58bc2e1

Please sign in to comment.