Merge pull request #196 from redis/warn-index-on-non-zero-database

Adds error if user attempts to create an index in DB > 0.
This commit is contained in:
Simon Prickett 2022-04-07 10:26:26 +01:00 committed by GitHub
commit 0841d9ff7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,6 +40,12 @@ def schema_hash_key(index_name):
async def create_index(redis: Redis, index_name, schema, current_hash):
db_number = redis.connection_pool.connection_kwargs.get("db")
if db_number and db_number > 0:
raise MigrationError(
"Creating search indexes is only supported in database 0. "
f"You attempted to create an index in database {db_number}"
)
try:
await redis.execute_command(f"ft.info {index_name}")
except ResponseError: