2014-12-15 12:47:26 -05:00
|
|
|
# Monkey-patch Redis::Store to make 'setex' and 'expire' work with namespacing
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class Redis
|
|
|
|
class Store
|
|
|
|
module Namespace
|
2014-12-16 06:43:38 -05:00
|
|
|
# Redis::Store#setex in redis-store 1.1.4 does not respect namespaces;
|
2014-12-16 06:38:44 -05:00
|
|
|
# this new method does.
|
2014-12-15 12:47:26 -05:00
|
|
|
def setex(key, expires_in, value, options=nil)
|
|
|
|
namespace(key) { |key| super(key, expires_in, value) }
|
|
|
|
end
|
|
|
|
|
2014-12-16 06:38:44 -05:00
|
|
|
# Redis::Store#expire in redis-store 1.1.4 does not respect namespaces;
|
|
|
|
# this new method does.
|
2014-12-15 12:47:26 -05:00
|
|
|
def expire(key, expires_in)
|
|
|
|
namespace(key) { |key| super(key, expires_in) }
|
|
|
|
end
|
2014-12-16 06:38:44 -05:00
|
|
|
|
|
|
|
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
|
2014-12-16 06:46:55 -05:00
|
|
|
# that it is available for all Redis::Store instances, whether they use
|
|
|
|
# namespacing or not.
|
2014-12-16 06:38:44 -05:00
|
|
|
#
|
|
|
|
# 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
|
2014-12-15 12:47:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Redis::Store.class_eval do
|
|
|
|
include Gitlab::Redis::Store::Namespace
|
|
|
|
end
|