9951 explained code solutions for 126 technologies


python-redisIterate through Redis keys


r = redis.Redis()

for k in r.scan_iter('*'):
  r.get(k)ctrl + c
redis.Redis

connect to Redis server

r.scan_iter

returns iterator with all keys matching specified pattern

'*'

pattern to search for keys (all keys in our case)

r.get

gets value by key from Redis (just random example of something to do with the key)


Usage example

import redis

r = redis.Redis()

for k in r.scan_iter("*"):
  print(k, ': ', r.get(k))
output
b'a' :  b'1'
b'bool' :  b'1'
b'd1' :  b'{"name": "Donald", "family": {"wife": "Melany"}}'
b'test' :  b'1'
b'c' :  b'3'
b'counter1' :  b'5'