About redis database quantity configuration, switching and specifying database
The following column Redis Tutorial will introduce to you the configuration, switching and specifying the number of redis databases. I hope it will be helpful to friends in need!
The number of redis databases can be configured, the default is 16, see databases 16 in redis.windows.conf/redis.conf.
The index value of the corresponding database is 0 - (databases -1), that is, 16 databases, the index value is 0-15. The default stored database is 0.
1. Command line switching
redis-cli -a 123456
Log in to redis, database 0 is selected by default. If you need to switch to other databases, use the select index value. For example, select 1 means switching to the index. Database with value 1.
D:\software\redis>redis-cli -a 123456 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]>
After the switch, the new database will be operated until the next switch takes effect.
2. Springboot specifies redis database
#redis spring.redis.host=localhost spring.redis.password=123456 spring.redis.port=6380 //redis ssl端口 spring.redis.database=2 //使用的数据库索引 spring.redis.ssl=true //是否使用ssl,默认为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 configuring redis in springboot If you do not specify a database, database No. 0 will be used by default. If you configure this value, your own configured database will be used.
3. Python specifies the redis database
Set the database to be used through the db parameter. For example, db=1 means using the database with index value 1.
redis-py provides two classes, Redis and StrictRedis, for implementing Redis commands. StrictRedis is used to implement most official commands and uses official syntax and commands (for example, the SET command corresponds to StrictRedis.set method).
Redis is a subclass of StrictRedis and is used for backward compatibility with older versions of redis-py. Simply put, the official recommendation is to use the StrictRedis method.
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:
If redis enables ssl connection, add ssl=True to enable ssl connection.
Such as redis.StrictRedis(host='127.0.0.1', port=6380, password='123456', db=2, ssl=True). Then use SSLConnection when creating the connection.
Connection pool connection:
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password='123456', db=2) r = redis.Redis(connection_pool=pool)
Remarks:
Using the above method to initialize the connection pool cannot enable ssl connection through the ssl parameter:
class ConnectionPool(object): def __init__(self, connection_class=Connection, max_connections=None, **connection_kwargs):
Connection is used here.
If you need to use ssl connection, use the from_url method to initialize the connection pool when initializing the connection pool. The parameter format is as follows:
rediss://[:password]@localhost:6379/0 ,6379表示端口,0表示使用的数据库索引值。 pool = redis.ConnectionPool.from_url('rediss://:123456@localhost:6380/2') r = redis.StrictRedis(connection_pool=pool) ret = r.get('test') pool.disconnect() //断开连接池的所有连接。
In addition, you can download the RedisDesktopManager visual UI tool to connect to redis for management.
The above is the detailed content of About redis database quantity configuration, switching and specifying database. For more information, please follow other related articles on the PHP Chinese website!

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.