//我尝试使用XAdd命令将多个值发送到流。
公共类LettuceDemo {
public static void main(String[] args) {
RedisClient redisClient = RedisClient.create("redis://password@localhost:6739/0");
StatefulRedisConnection<String, String> connection =redisClient.connect();
RedisStreamCommands<String, String> streamCommands = connection.sync();
List<String> supplierNames1 = new ArrayList<String>();
supplierNames1.add("PaymentOption");
supplierNames1.add("StartDate");
supplierNames1.add("EndDate");
supplierNames1.add("RateOfInterest");
supplierNames1.add("RequiredLoanAmmount");
List<String> supplierNames2 = new ArrayList<String>();
supplierNames2.add(String.valueOf(123));
supplierNames2.add(String.valueOf(765));
supplierNames2.add(String.valueOf(347746));
supplierNames2.add(String.valueOf(8347674));
supplierNames2.add(String.valueOf(34875645));
Map<List<String>, List<String>> body1 = Collections.singletonMap(supplierNames1, supplierNames2);
String messageId = streamCommands.xadd("demo", body1);
System.out.println("my-stream code reference " + messageId);
connection.close();
redisClient.shutdown();
}
}
//我在执行程序时遇到了问题。
线程“ main”中的异常java.lang.IllegalArgumentException:消息> body.length必须为2的倍数,并且包含以下字段的序列:field1,> value1,field2,value2,fieldN,valueN 在io.lettuce.core.internal.LettuceAssert.isTrue(LettuceAssert.java:131) 在io.lettuce.core.RedisCommandBuilder.xadd(RedisCommandBuilder.java:2110) 在io.lettuce.core.AbstractRedisAsyncCommands.xadd(AbstractRedisAsyncCommands.java:1499) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498) 在io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:57) 在io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) 在com.sun.proxy。$ Proxy0.xadd(未知来源) 在com.excent.experiences.tinnumber.LettuceDemo.main(LettuceDemo.java:48)