0

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

alilland
  • 2,039
  • 1
  • 21
  • 42

1 Answers1

0

Did you consider upgrading redis-rb?

In the latest versions clustering support was moved into a redis-clustering gem, which in turns uses redis-cluster-client under the hood.

It seems that the latter performs scan across all nodes, so high chances are that with the latest redis-rb you won't need to raise the sun manually.

Konstantin Strukov
  • 2,899
  • 1
  • 10
  • 14
  • main bummer is that i use ruby 2.4.1 in most of my older apps and this requires >= 2.7.0, but it might be something I will update for in order to use – alilland Nov 08 '22 at 21:53