mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: s/\$redis/Discourse\.redis (#8431)
This commit also adds a rubocop rule to prevent global variables.
This commit is contained in:
@@ -19,13 +19,13 @@ module CachedCounting
|
||||
|
||||
class_methods do
|
||||
def perform_increment!(key, opts = nil)
|
||||
val = $redis.incr(key).to_i
|
||||
val = Discourse.redis.incr(key).to_i
|
||||
|
||||
# readonly mode it is going to be 0, skip
|
||||
return if val == 0
|
||||
|
||||
# 3.days, see: https://github.com/rails/rails/issues/21296
|
||||
$redis.expire(key, 259200)
|
||||
Discourse.redis.expire(key, 259200)
|
||||
|
||||
autoflush = (opts && opts[:autoflush]) || self.autoflush
|
||||
if autoflush > 0 && val >= autoflush
|
||||
@@ -51,9 +51,9 @@ module CachedCounting
|
||||
# this may seem a bit fancy but in so it allows
|
||||
# for concurrent calls without double counting
|
||||
def get_and_reset(key)
|
||||
namespaced_key = $redis.namespace_key(key)
|
||||
val = $redis.without_namespace.eval(GET_AND_RESET, keys: [namespaced_key]).to_i
|
||||
$redis.expire(key, 259200) # SET removes expiry, so set it again
|
||||
namespaced_key = Discourse.redis.namespace_key(key)
|
||||
val = Discourse.redis.without_namespace.eval(GET_AND_RESET, keys: [namespaced_key]).to_i
|
||||
Discourse.redis.expire(key, 259200) # SET removes expiry, so set it again
|
||||
val
|
||||
end
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ module StatsCacheable
|
||||
|
||||
def fetch_cached_stats
|
||||
# The scheduled Stats job is responsible for generating and caching this.
|
||||
stats = $redis.get(stats_cache_key)
|
||||
stats = Discourse.redis.get(stats_cache_key)
|
||||
stats = refresh_stats if !stats
|
||||
JSON.parse(stats).with_indifferent_access
|
||||
end
|
||||
@@ -35,7 +35,7 @@ module StatsCacheable
|
||||
def set_cache(stats)
|
||||
# Add some extra time to the expiry so that the next job run has plenty of time to
|
||||
# finish before previous cached value expires.
|
||||
$redis.setex stats_cache_key, (recalculate_stats_interval + 5).minutes, stats
|
||||
Discourse.redis.setex stats_cache_key, (recalculate_stats_interval + 5).minutes, stats
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user