0

With Redis (I'm using Python redis) you can scan keys like this:

 keys = redis_client.scan_iter(match='{string}*')

However how would I do this if I want to get all keys excluding a certain string? So in this example I would like all keys not starting with '{string}'.

user3605780
  • 6,542
  • 13
  • 42
  • 67
  • 1
    There are some useful answers in this post, you may take a look https://stackoverflow.com/questions/29942541/how-to-get-keys-which-does-not-match-a-particular-pattern-in-redis – Ersoy Apr 30 '20 at 10:56
  • You might need to use Lua script or RedisGears – Guy Korland Apr 30 '20 at 11:10

2 Answers2

0

According to the documentation, the Redis SCAN command uses glob-style syntax. There is no way in that syntax to specify all strings that don't start with a certain string. So you can't do it.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
-2

Redis' pattern matching is glob-like so there's no real way to do that. Instead, you can match * and use Python's capabilities (e.g. not str.startswith('s'))

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117