In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of redis database quantity configuration, switching and database designation, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
The number of databases in redis is configurable. The default is 16, as shown in redis.windows.conf/redis.conf 's databases 16.
The index value of the corresponding database is 0-(databases-1), that is, 16 databases, and the index value is 0-15. The default stored database is 0.
1. Command line switch
Redis-cli-a 123456
Log in to redis and select database 0 by default. If you need to switch to another database, use the select index value, such as select 1, to switch to the database with an index value of 1.
D:\ software\ redis > redis-cli-a 123456127.0.1 redis-cli 6379 > select 1OK127.0.0.1:6379 [1] >
After the switch, the new database will be operated until the next switch takes effect.
2. Springboot specifies the redis database
# redis spring.redis.host=localhost spring.redis.password=123456 spring.redis.port=6380 / / redis ssl port spring.redis.database=2 / / Database index spring.redis.ssl=true / / whether to use ssl. Default is false spring.redis.pool.maxActive=100 spring.redis.pool.maxWait=1000000 spring.redis.pool.maxIdle=10 spring.redis.pool.minIdle=0 spring.redis.timeout=0 spring.redis.testOnBorrow=true spring.redis.testOnReturn=true spring.redis.testWhileIdle=true.
In the source code RedisProperties.java, the initial value of database is 0 (private int database = 0;), so when springboot configures redis without specifying a database, it defaults to database 0, and configuring this value uses its own configured database.
3. Python specifies the redis database
The database used is set through the db parameter. For example, db=1 means to use a database with an index value of 1.
Redis-py provides two classes, Redis and StrictRedis, to implement Redis commands, while StrictRedis implements most official commands and uses official syntax and commands (for example, SET commands correspond to StrictRedis.set methods).
Redis is a subclass of StrictRedis and is used for backward compatibility with older versions of redis-py. To put it simply, the StrictRedis method is officially recommended.
R = redis.StrictRedis (host='127.0.0.1', port=6379, password='123456', db=2, ssl=False) r = redis.Redis (host='127.0.0.1', port=6379, password='123456', db=2, ssl=False)
Note:
Redis if ssl connection is enabled, adding ssl=True means that ssl connection is enabled.
Such as redis.StrictRedis (host='127.0.0.1', port=6380, password='123456', db=2, ssl=True). SSLConnection is used when creating the connection.
Connection pooled connections:
Pool= redis.ConnectionPool (host='127.0.0.1', port=6379, password='123456', db=2) r = redis.Redis (connection_pool=pool)
Note:
Using the above method to initialize connection pooling cannot enable ssl connections through the ssl parameter:
Class ConnectionPool (object): def _ _ init__ (self, connection_class=Connection, max_connections=None, * * connection_kwargs):
Connection is used for the connection here.
If you need to use ssl connections, initialize the connection pool using the from_url method when initializing the connection pool, as shown in the format of the parameters:
Rediss:// [: password] @ localhost:6379/0, 6379 indicates the port, and 0 indicates the database index value used. Pool= redis.ConnectionPool.from_url ('rediss://:123456@localhost:6380/2') r = redis.StrictRedis (connection_pool=pool) ret = r.get (' test') pool.disconnect () / / disconnect all connections from the connection pool.
In addition, you can download the RedisDesktopManager visualization UI tool to connect with redis for management.
Thank you for reading this article carefully. I hope it will be helpful for everyone to share the methods and contents of redis database quantity configuration, switching and specifying database. At the same time, I also hope that you will support more, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.