200 Redis instances are turned on on a single server, and it crashes when you look at it. The only way to do this is to make different types of data belong to different applications and separate from each other.
So, is there a way for Redis to keep different application data separate from each other and stored on the same instance? is equivalent to the MySQL database, different application data is stored under different databases.
Under Redis, a database is identified by an integer index, not by a database name. By default, one client connects to database 0. The following parameters in the Redis configuration file control the total number of databases:
You can switch to a different database by using the following command
Subsequently, all commands will use database 3, knowing that you explicitly switch to another database.
Each database has its own space, and there is no need to worry about key conflicts.
Under different databases, the same key is taken to the respective value.
The FLUSHDB command clears the data and clears only the data under the current database, without affecting other databases.
The Flushall command clears the data for this instance. Take extra care before executing this command.
The number of databases is configurable and is 16 by default. Modify the Databases directive under redis.conf:
Redis does not provide any way to correlate the identities of different databases. Therefore, you need to keep track of what data is stored under which database.
As a result, the above 200-instance scenario can be stored using a different database instead of having so many instances open.
Reprint please specify from Operation Survival time: http://www.ttlsa.com/html/4010.html
---
In practical programming, Redis shard operations, referencing the Jedis jar package
Import Redis.clients.jedis.JedisShardInfo;
Jedisshardinfo shard = new Jedisshardinfo (Node.gethost (), Node.getport (), Node.getname ());
Shard.setpassword (Node.getpassword ());
Shard.setdb (dbindex);
Shards.add (shard);
Here the Shard.setdb (2) corresponds to the input "select 2" in the console Select Database 2 (starting from database 0)