3

I need to get all the databases stored in redis server using python-redis Thanks

EdWarD
  • 63
  • 1
  • 5

2 Answers2

9

Look here List All Redis Databases

Then in python you can do:

In [3]: r = redis.StrictRedis()
In [4]: r.config_get('databases')
Out[4]: {'databases': '16'}

In [5]: r.info('keyspace')
Out[5]: {'db0': {'avg_ttl': 0, 'expires': 0, 'keys': 4}}
Community
  • 1
  • 1
eran
  • 6,731
  • 6
  • 35
  • 52
1

i've tried this

import redis
ser = redis.Redis()
print ser.config_get('databases')

and the console return this

{}

and if i put this

import redis
ser = redis.StrictRedis()
print ser.config_get('databases')

it return this

ser = redis.StrictRedis()
AttributeError: 'module' object has no attribute 'StrictRedis'
EdWarD
  • 63
  • 1
  • 5
  • [official doc](https://pypi.python.org/pypi/redis) redis-py exposes two client classes that implement these commands The StrictRedis class attempts to adhere to the official command syntax. and In addition to the changes above, the Redis class, a subclass of StrictRedis, overrides several other commands to provide backwards compatibility with older versions of redis-py [question answered in stackoverflow](http://stackoverflow.com/questions/19021765/redis-py-whats-the-difference-between-strictredis-and-redis) – ashim888 Jan 25 '16 at 06:35