Lettuce Core API的RedisClient类包含以下方法:
public StatefulRedisConnection<String,String> connect() {
return this.connect(this.newStringStringCodec());
}
public <K,V> StatefulRedisConnection<K,V> connect(RedisCodec<K,V> codec) {
this.checkForRedisURI();
return (StatefulRedisConnection)this.getconnection(this.connectStandaloneAsync(codec,this.redisURI,this.timeout));
}
我想调用方法connect(RedisCodec<K,V> codec)
,但我不知道如何配置应作为参数传递给此方法的编解码器对象。
我当前的代码:
val redisClient = RedisClient.create("redis://password@localhost:6379/0");
val connection = redisClient.connect();
// in this case type of connection is StatefulRedisConnection<String,String>
val redisCommands = connection.sync()
我也有我的自定义数据类。
data class MyCustomDataClassname {
val id: UUID,val something: String,val foo: String,val bar: String
}
我要编写这段代码:
val redisClient = RedisClient.create("redis://password@localhost:6379/0");
val codec = /* should be something that returns object of type StatefulRedisConnection<String,MyCustomDataClassname>*/
val connection = redisClient.connect(codec);
val redisCommands = connection.sync()