v6.2.0 (2025-11-22)
<dependency>
<groupId>net.hasor</groupId>
<artifactId>jdbc-redis</artifactId>
<version>6.2.0</version>
</dependency>
Impact
- JdbcOperations interface and JdbcTemplate class
- dbvisitor-driver project
- jdbc-redis driver
Changes
- Added
- Adapt jdbc-redis driver for Mapper annotations, Mapper File, and JdbcTemplate APIs.
- Restore
BindTypeHandlerannotation from 5.x. - Add
resultTypeHandlerto XmlMapper and@Queryfor TypeHandler configuration. TypeHandlerColumnRowMappercan be used as aRowMapper.- jdbc-redis adds PING, ECHO, SELECT, INFO commands.
- Support connecting Redis via jdbc-redis in DataGrip/IDEA Database plugin.
ResultSetExtractorgainsPairsResultSetExtractorto convert result sets to key-value collections.- JdbcOperations/JdbcTemplate add three
queryForPairsmethods to convert each row into a key-value pair. - New
pairsrule to iterate Map/List/Array and generate query conditions via template.
- Changed
queryForLongreturn type:Long(waslong).queryForIntreturn type:Integer(wasint).AbstractRowMapper.getResultSetTypeHandler(ResultSet, int, Class)moved toTypeHandlerRegistry.- jdbc-redis
MSET/MSETNXnow return number of added keys (previously always 1). - For StoreSet-related commands outputting SCORE and ELEMENT, field order becomes ELEMENT, SCORE. Applies to: ZPOPMAX, ZPOPMIN, ZDIFF, ZINTER, ZRANDMEMBER, ZRANGE, ZRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE, ZUNION, ZMPOP, BZMPOP, BZPOPMAX, BZPOPMIN, ZSCAN.
- Improved
- jdbc-redis supports
ResultSet.isLast. - Some commands now return results via
updateCount, including:- HKEYS, HDEL, DEL, SET, HSET, HMSET, HSETNX, EXPIRE, EXPIREAT, PEXPIRE, PEXPIREAT, PERSIST, RENAME, RENAMENX, TOUCH, LINSERT, LPUSH, LPUSHX, RPUSH, RPUSHX, LREM, LSET, LTRIM, MOVE, SADD, SDIFFSTORE, SINTERSTORE, SMOVE, SREM, SUNIONSTORE, ZDIFFSTORE, ZINTERSTORE, ZRANGESTORE, ZREM, ZREMRANGEBYLEX, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, MSET, MSETNX, PSETEX, SETEX, SETNX, SETRANGE
- antlr4 dependency is shaded into the jdbc-redis JAR to reduce external deps.
- Improved jdbc-redis error messages.
ConvertUtilsin dbvisitor-driver supportsByte[]intoBytes.
- jdbc-redis supports
- Fixed
- jdbc-redis
Statement.getLargeUpdateCount/getUpdateCountthrew SQLException when no result set; now return -1 per JDBC spec when no more results. - jdbc-redis
keyscommand execution failure.
- jdbc-redis
What does queryForPairs do?
Query Key-Value Pairs with JdbcTemplate
// Return user IDs and names as a Map
Map<Long, String> userMap = jdbc.queryForPairs("select uid, name from user", Long.class, String.class);
How to Use Redis Integration?
Read and Write Objects with JdbcTemplate
// 1. Annotate UserInfo with BindTypeHandler to use JsonTypeHandler for serialization and deserialization
@BindTypeHandler(JsonTypeHandler.class)
public class UserInfo {
...
}
// 2. Obtain a Redis connection and create JdbcTemplate
Connection redisConn = ...; // See Driver Adapters > JDBC Redis > Usage
JdbcTemplate jdbc = new JdbcTemplate(redisConn);
// 3. Create UserInfo and store it as JSON in Redis
UserInfo user = new UserInfo();
user.setUid("j1111");
user.setName("username");
user.setLoginName("login_123");
user.setLoginPassword("password");
// 4. Use user_ + uid as the key; arg0 is the user object
int affected = jdbc.executeUpdate("set #{'user_' + arg0.uid} #{arg0}", user);
// 5. Read and deserialize UserInfo from Redis
UserInfo info = jdbc.queryForObject("get #{'user_' + arg0}", "j1111", UserInfo.class);
// 6. Delete UserInfo from Redis
int deleteCount = jdbc.executeUpdate("del #{'user_' + arg0.uid}", user);
Read and Write Objects with Mapper Annotations
// 1. Annotate UserInfo with BindTypeHandler to use JsonTypeHandler for serialization and deserialization
@BindTypeHandler(JsonTypeHandler.class)
public class UserInfo {
...
}
@SimpleMapper()
public interface UserInfo1Mapper {
// 1. Generated parameterized command: set ? ?
// 2. Key expression: #{'user_' + info.uid}
// 3. Value: #{info}
@Insert("set #{'user_' + info.uid} #{info}")
int saveUser(@Param("info") UserInfo info);
// 1. Generated parameterized command: get ?
// 2. Key expression: #{'user_' + uid}
@Query("get #{'user_' + uid}")
UserInfo loadUser(@Param("uid") String uid);
// 1. Generated parameterized command: del ?
// 2. Key expression: #{'user_' + uid}
@Delete("del #{'user_' + uid}")
int deleteUser(@Param("uid") String uid);
}
Manage Commands with Mapper Files(Mapper)
@RefMapper("dbvisitor_scene/redis/user-mapper.xml")
public interface UserInfoMapper {
int saveUser(@Param("info") UserInfo info);
UserInfo loadUser(@Param("uid") String uid);
int deleteUser(@Param("uid") String uid);
}
Manage Commands with Mapper Files(Mapper File)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//dbvisitor.net//DTD Mapper 1.0//EN"
"https://www.dbvisitor.net/schema/dbvisitor-mapper.dtd">
<mapper namespace="net.hasor.scene.UserInfoMapper">
<insert id="saveUser">
set #{'user_' + info.uid} #{info}
</insert>
<select id="loadUser" resultType="net.hasor.scene.UserInfo">
get #{'user_' + uid}
</select>
<delete id="deleteUser">
del #{'user_' + uid}
</delete>
</mapper>