[tor-commits] [donate/master] Updated other Redis client to use new host
peterh at torproject.org
peterh at torproject.org
Wed Sep 18 22:24:02 UTC 2019
commit 5a1818383bd139b991eb29f316e0c14023b9b6ac
Author: peterh <peterh at giantrabbit.com>
Date: Mon Jul 29 15:28:25 2019 -0700
Updated other Redis client to use new host
I forgot we were using a different Redis client when not using Redis for
messaging. So we need to have it use the new host now.
---
src/SubscriptionController.php | 13 +++++++++++--
src/dependencies.php | 11 ++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/SubscriptionController.php b/src/SubscriptionController.php
index 7b79d269..d403d77e 100644
--- a/src/SubscriptionController.php
+++ b/src/SubscriptionController.php
@@ -5,12 +5,21 @@ namespace Tor;
class SubscriptionController extends BaseController {
const REDIS_PREFIX = "subscription_request:";
public $vars;
+ public $redisClient = NULL;
public function __construct($container) {
parent::__construct($container);
$this->vars = array();
}
+ public function getRedisClient() {
+ if ($this->redisClient == NULL) {
+ $settings = $this->container->get('settings');
+ $this->redisClient = new \Predis\Client($settings['redis']);
+ }
+ return $this->redisClient;
+ }
+
public function getTokenKey($token) {
return static::REDIS_PREFIX . $token;
}
@@ -29,7 +38,7 @@ class SubscriptionController extends BaseController {
$errors[] = "There should have been a query parameter called token in the URL we sent you, but that seems to be missing. If you cut and pasted the URL, double check that you got the entire streng.";
}
if (empty($errors)) {
- $redis = new \Predis\Client();
+ $redis = $this->getRedisClient();
$key = $this->getTokenKey($token);
$data = $redis->get($key);
if ($data === NULL) {
@@ -90,7 +99,7 @@ class SubscriptionController extends BaseController {
$factory = new \RandomLib\Factory();
$generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::LOW));
$token = $generator->generateString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
- $redis = new \Predis\Client();
+ $redis = $this->getRedisClient();
$data = serialize($subscriptionInfo);
$key = $this->getTokenKey($token);
$redis->set($key, $data);
diff --git a/src/dependencies.php b/src/dependencies.php
index 7d2b423c..68cd24d0 100644
--- a/src/dependencies.php
+++ b/src/dependencies.php
@@ -67,6 +67,15 @@ $container['errorHandler'] = function($container) {
return $error_handler;
};
+$settings = $container->get('settings');
+$settings['redis'] = [
+ 'host' => 'localhost',
+ 'port' => 6379,
+];
if (!$environmentInfo->is_dev()) {
- Resque::setBackend('crm-int-01-priv.torproject.org:6379');
+ $settings['redis'] = [
+ 'host' => 'crm-int-01-priv.torproject.org',
+ 'port' => 6379,
+ ];
+ Resque::setBackend("{$settings['redis']['host']}:{$settings['redis']['port']}");
}
More information about the tor-commits
mailing list