underyx / flask-redis

A Flask extension for using Redis
Other
436 stars 71 forks source link

How to use more than one redis database? #40

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hello my friends,

REDIS_URL = "redis://localhost:6379/0" <- here we select the database

But what can i do when i want to use Database 0 for cache and Database 1 for data. Is there a way to connect with both? My problem is that i need to use randomkey command and i don't want to get keys from my cached data.

A big thanks if someone knows a solution!

Solution:

in our config: app.config['DBA_URL'] = 'redis://localhost:6379/1' app.config['DBB_URL'] = 'redis://localhost:6379/2'

and we load each instance with "config_prefix": redis_a = FlaskRedis(app, config_prefix='DBA') redis_b = FlaskRedis(app, config_prefix='DBB')

source: unit tests