Redis Specifics
Hint
This article is generated by AI translation.
dbVisitor accesses Redis over the JDBC protocol via the JDBC-Redis driver. Keep these points in mind:
- Use native Redis commands to operate on data; supported commands are listed in the Commands.
- Three access styles are available: JdbcTemplate, Annotations, and Mapper File.
- Rules and Arguments help build complex commands and pass arguments.
- Query results can be handled with interfaces such as ResultSetExtractor, RowMapper.
- Mapper files support Dynamic Command tags to build executable commands.
- Fluent API and BaseMapper APIs are not supported.
- ObjectMapping and ResultMapping are not supported.
JdbcTemplatedoes not supportexecuteBatch.JdbcTemplatestored procedure APIs are not supported.
Tip
Even though Redis usage does not support ObjectMapping, you can still synchronize data between relational databases and Redis by first setting up object mappings and then reusing existing APIs.
Conceptual Mapping
Commands in the Redis driver return three kinds of results: UpdateCount, Single Result, and ResultSet.
- Update count behaves like INSERT/UPDATE/DELETE in relational databases and should be obtained with
executeUpdate. - Single-row and multi-row results are similar to a SELECT returning a result set; all read commands and commands that cannot return an update count use result sets.
Guide
Execute commands
- Command: use
JdbcTemplateto run raw Redis commands for reads and writes. - Annotations: place
@Insert,@Update, and@Deleteon Mapper interface methods to encapsulate Redis operations. - File Mapper: configure commands in Mapper files via tags.
Read/write Redis data types
- String: read/write Redis String values with dbVisitor.
- Hash: read/write Redis Hash values with dbVisitor.
- List: read/write Redis List values with dbVisitor.
- Set: read/write Redis Set values with dbVisitor.
- Sorted Set: read/write Redis Sorted Set values with dbVisitor.