Annotations
Hint
This article is generated by AI translation.
Define Redis commands with dbVisitor annotations directly on interface methods so they serve as the data-access layer without extra code.
Tip
All core annotation APIs are supported on Redis data sources except @Call.
1. Define the object and bind JSON serialization
@BindTypeHandler(JsonTypeHandler.class)
public class UserInfo {
private String uid;
private String name;
... // getters/setters omitted
}
2. Define the Mapper interface
// Use prefix "user_" + UID for the user key name
@SimpleMapper()
public interface UserInfoMapper {
// Command: SET ? ?
@Insert("set #{'user_' + info.uid} #{info}")
int saveUser(@Param("info") UserInfo info);
// Command: GET ?
@Query("get #{'user_' + uid}")
UserInfo loadUser(@Param("uid") String uid);
// Command: DEL ?
@Delete("del #{'user_' + uid}")
int deleteUser(@Param("uid") String uid);
}
3. Create the Mapper
// 1. Create Configuration
Configuration config = new Configuration();
// 2. Create Session
Session session = config.newSession(dataSource);
// or
Session session = config.newSession(connection);
// 3. Create UserInfoMapper
UserInfoMapper mapper = session.createMapper(UserInfoMapper.class);
Supported Commands
See the full supported command list for Redis coverage.