public String load( String key )
{
PreparedStatement preparedStatement = conn.prepareStatement( “SELECT name FROM student where id = ?” );
try {
preparedStatement.setString( 1, key );
ResultSet result = preparedStatement.executeQuery();
if ( result.next() )
{
return(result.getString( 1 ) );
}
return(null);
} finally {
preparedStatement.close();
}
}
}
配置使用案例:
MapOptions<K, V> options = MapOptions.< K, V > defaults()
.loader( mapLoader );
RMap<K, V> map = redisson.getMap( “test”, options );
/* or */
RMapCache<K, V> map = redisson.getMapCache( “test”, options );
/* or with boost up to 45x times */
RLocalCachedMap<K, V> map = redisson.getLocalCachedMap( “test”, options );
/* or with boost up to 45x times */
RLocalCachedMapCache<K, V> map = redisson.getLocalCachedMapCache( “test”, options );
下面是一个Java示例,说明如何在Redis中使用Redis中的Redis使用直写缓存。
在MapWriter对象更新缓存和数据库之前,缓存更新方法不会返回:
MapWriter<String, String> mapWriter = new MapWriter<String, String>()
{
@Override
public void writeAll( Map<String, String> map )
{
PreparedStatement preparedStatement = conn.prepareStatement( “INSERT INTO student (id, name) val