Skip to content

Commit

Permalink
FIX: Respect redis namespace when fetching env using LUA
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaSayegh committed Feb 17, 2020
1 parent 932e510 commit df5a1d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 22 additions & 6 deletions lib/logster/redis_store.rb
Expand Up @@ -249,11 +249,11 @@ def bulk_get(message_keys, with_env: true)
envs = {}
@redis.eval(
BULK_ENV_GET_LUA,
keys: message_keys.map { |k| env_prefix(k) }
keys: message_keys.map { |k| env_prefix(k, with_namespace: true) }
).to_h.each do |k, v|
next if v.size == 0
parsed = v.size == 1 ? JSON.parse(v[0]) : v.map { |e| JSON.parse(e) }
envs[env_unprefix(k)] = parsed
envs[env_unprefix(k, with_namespace: true)] = parsed
end
end
messages = @redis.hmget(hash_key, message_keys).map! do |json|
Expand Down Expand Up @@ -647,12 +647,28 @@ def delete_env(message_key)
@redis.del(env_prefix(message_key))
end

def env_unprefix(key)
key.sub(ENV_PREFIX, "")
def env_unprefix(key, with_namespace: false)
prefix = ENV_PREFIX
if with_namespace && namespace
prefix = "#{namespace}:#{prefix}"
end
key.sub(prefix, "")
end

def env_prefix(key, with_namespace: false)
prefix = ENV_PREFIX
if with_namespace && namespace
prefix = "#{namespace}:#{prefix}"
end
prefix + key
end

def env_prefix(key)
ENV_PREFIX + key
def namespace
if @redis_prefix.respond_to?(:call)
@namespace ||= @redis_prefix.call
else
@namespace ||= @redis_prefix
end
end
end
end
4 changes: 2 additions & 2 deletions website/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
logster (2.6.1)
logster (2.6.2)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -31,4 +31,4 @@ DEPENDENCIES
sinatra

BUNDLED WITH
2.0.2
2.1.2

0 comments on commit df5a1d1

Please sign in to comment.