Configuration method of redis database used by spring boot and kotlin
In addition to providing excellent automation support for commonly used relational databases, spring boot also provides automatic configuration support for many NoSQL databases, including redis, mongodb, elasticsearch, Solr and Cassandra.
Using redis
Redis is an open source log and key value database written in ANSI C language, supporting network, memory based and persistent.
Introduce dependency
Spring data redis, the data access framework provided by spring boot, is based on jedis. You can configure dependencies by introducing spring boot starter data redis.
Note: after spring boot 1.4, it will be renamed spring boot starter data redis. Before spring boot 1.4, spring boot starter redis will be used
With kotlin, you need to add a plug-in
Complete build Gradle file
Parameter configuration
According to the Convention, in application The redis server configuration is added to YML. The details are as follows:
Where spring redis. 0 is usually used for database configuration. Redis can set the number of databases during configuration. The default is 16, which can be understood as the schema of the database
Just use the above configuration for the test
Create user entity class
Test access
Write test cases to illustrate how to access redis.