As of 91685eeeb1462edfc12da2e079e76bdbeec0eddb, when e.g. databases 16 is configured, the SELECT command checks to make sure that the provided index is valid:
127.0.0.1:6379> select 500
(error) ERR DB index is out of range
But when connecting to redis with the -n command line argument appears to connect to the requested database, while actually connecting to database 0:
$ redis-cli -n 500
127.0.0.1:6379[500]> info keyspace
# Keyspace
db0:keys=1,expires=0,avg_ttl=0
127.0.0.1:6379[500]> set xyzzy plugh
OK
127.0.0.1:6379[500]> info keyspace
# Keyspace
db0:keys=2,expires=0,avg_ttl=0
This seems like confusing behavior, at best; it seems preferable for an invalid -n argument to cause the connection to fail with behavior similar to an invalid SELECT command.
Comment From: huangzhw
Fixed by https://github.com/redis/redis/pull/8898