问题描述
我正在使用带有spring-data-redis的spring-boot 2.3.3。我使用Jedis作为Redis客户。我有一个扩展CrudRepository的@Repository类。
@Repository
public interface BackedEventRepository extends CrudRepository<BackedEvent,String>{}
我要存储的redis哈希如下:
@RedisHash("backedEvent")
public class BackedEvent implements Serializable{
private static final long serialVersionUID = 4264000518258689567L;
@Id
private String id;
private byte[] value;
}
存储库类插入小数据的测试通过。
@Test
void whenSavingBackedMessageThenSuccessfullyRetrieveMsg() throws Exception {
String id = RandomStringUtils.random(10);
BackedEvent backedMsg = BackedEvent.builder().id(id)
.value("this is a test".getBytes()).build();
repo.save(backedMsg);
Optional<BackedEvent> retBackedMsg = repo.findById(id);
assertThat(retBackedMsg.get().getId()).isEqualTo(backedMsg.getId());
assertThat(retBackedMsg.get().getValue()).isEqualTo(backedMsg.getValue());
}
我有一个集成测试,该测试进入一个1.8MB的xml文件的inputstream中,并将这些字节用作redis哈希对象中的值。测试失败
当它执行backedEventRepository.save(backedEvent)时,出现以下错误:
org.springframework.data.redis.RedisConnectionFailureException: ERR Protocol error: invalid multibulk length; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: ERR Protocol error: invalid multibulk length
尽管hmset redis命令已被弃用,但似乎spring-data-redis正在发出hmset命令事件。
org.springframework.data.redis.connection.jedis.JedisHashCommands.hMSet(JedisHashCommands.java:345)
我知道redis的批量长度为1MB。关于如何克服这个想法?我希望能够只发出一个保存命令来保存“大”数据。这样做的目的是在Redis中存储大于1MB的大量数据,因为1MB是Kafka主题的大小限制。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)