I have several key patterns
redis ruby gem version 4.2.5
app:namespace1:{id}
app:namespace2:{id}
app:namespace1:{id}:nested1
app:namespace2:{id}:nested2
app:whatever1
app:whatever2
How can I scan for everything app:*
?
so far if i can for app:*
I only get top level non nested values, like
app:whatever1
app:whatever2
def match_keys(pattern)
@redis ||= init_connection
all_keys = []
cursor = 0
loop do
cursor, keys = @redis.scan(cursor, match: pattern)
all_keys += keys
break if cursor == '0'
end
all_keys.uniq
end
match_keys 'app:*'
#=> ["app:whatever1", "app:whatever2"]
I need it to return the entire app:*
namespace keys including all the children keys
Discovery
it looks like my issue is not related to the search string, its because my redis environment runs in a clustered environment, so the keys are spread across multiple clusters, and the cluster responds back with the keys on its own node but not from the others
so how can I get my redis ruby cluster to scan all matching keys across clusters?
here is my cluster config
def init_connection
config = {
cluster: [
"redis://#{ENV['REDIS_HOST_1']}",
"redis://#{ENV['REDIS_HOST_2']}",
"redis://#{ENV['REDIS_HOST_3']}"
],
replica: true
}
@redis ||= ::Redis.new(config)
end
according to this post how to use redis scan in cluster enviroment?
it seems like I need to figure out a way to loop over each node, but i cant find any documentation for doing that