我理解为你用的是 django-redis 这个模块做的缓存。
你可以在配置文件的连接字符串里直接指定库的索引:
redis://127.0.0.1:6379/1
# 或者
unix:///your_redis_path/redis.sock?db=1
要是有多个缓存来源,配置多个就好了;
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379"
},
"db1": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1"
},
"db2": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/2"
}
}