summaryrefslogtreecommitdiff
path: root/config/initializers
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2014-12-16 12:38:44 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2014-12-16 12:38:44 +0100
commit764eaedf810af307d68d5e6b552988db1cb15f54 (patch)
tree242e44b03c36ce7194e2e4d366fc3228921d65ed /config/initializers
parent62ea02740d2fff83d636eb659eb5f80dbf1bd888 (diff)
downloadgitlab-ce-764eaedf810af307d68d5e6b552988db1cb15f54.tar.gz
Improve Redis::Store monkey-patch robustness
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/redis-store-fix-expiry.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/config/initializers/redis-store-fix-expiry.rb b/config/initializers/redis-store-fix-expiry.rb
index dd27596cd0b..813d4c76c81 100644
--- a/config/initializers/redis-store-fix-expiry.rb
+++ b/config/initializers/redis-store-fix-expiry.rb
@@ -4,13 +4,36 @@ module Gitlab
class Redis
class Store
module Namespace
+ # Redis::Store#expire in redis-store 1.1.4 does not respect namespaces;
+ # this new method does.
def setex(key, expires_in, value, options=nil)
namespace(key) { |key| super(key, expires_in, value) }
end
+ # Redis::Store#expire in redis-store 1.1.4 does not respect namespaces;
+ # this new method does.
def expire(key, expires_in)
namespace(key) { |key| super(key, expires_in) }
end
+
+ private
+
+ # Our new definitions of #setex and #expire above assume that the
+ # #namespace method exists. Because we cannot be sure of that, we
+ # re-implement the #namespace method from Redis::Store::Namespace so
+ # that it all Redis::Store instances, whether they use namespacing or
+ # not.
+ #
+ # Based on lib/redis/store/namespace.rb L49-51 (redis-store 1.1.4)
+ def namespace(key)
+ if @namespace
+ yield interpolate(key)
+ else
+ # This Redis::Store instance does not use a namespace so we should
+ # just pass through the key.
+ yield key
+ end
+ end
end
end
end