【发布时间】:2019-05-14 07:53:27
【问题描述】:
我是 Micronaut 的新手。我正在尝试将项目移植到 Micronaut (v1.1.1),但发现 Redis 存在问题。
我只是想在 Redis 中保存一个简单的 POJO,但是当我尝试“保存”它时出现以下错误:
io.lettuce.core.RedisException: io.netty.handler.codec.EncoderException: Cannot encode command. Please close the connection as the connection state may be out of sync.
代码很简单(HERE你可以找到完整的测试。):
class DummyTest {
@Test
public void testIssue() throws Exception {
final Date now = Date.from(Instant.now());
CatalogContent expectedContentOne = CatalogContent.builder()
.contentId(1)
.status(ContentStatus.AVAILABLE)
.title("uno")
.streamId(1)
.available(now)
.tags(Set.of("tag1", "tag2"))
.build();
repository.save(expectedContentOne);
}
}
/.../
class CatalogContentRepository {
private StatefulRedisConnection<String, CatalogContent> connection;
public CatalogContentRepository(StatefulRedisConnection<String, CatalogContent> connection) {
this.connection = connection;
}
public void save(CatalogContent content) {
RedisCommands<String, CatalogContent> redisApi = connection.sync();
redisApi.set(String.valueOf(content.getContentId()),content); //Error here!
}
}
欢迎任何想法。
提前致谢。
【问题讨论】: