dengliming/redis-modules-java

Get multiple properties of object

501956430 opened this issue · 4 comments

How does Java get multiple attributes?

127.0.0.1:6379> json.set b . '{"name":"abcd","age":1,"type":1}'
ok
127.0.0.1:6379> json.get a
"{"name":"abcd","age":1,"type":1}"
//Get multiple properties
127.0.0.1:6379> json.get a name age
"{"age":1,"name":"abcd"}"

How to obtain multiple attributes? I don't see a corresponding method in the source code

截屏2022-01-21 18 15 00

redisJSON.get(key, Map.class, new GetArgs().path("name", "age"))

thank

Object serialization excludes null attributes, which will cause an exception when obtaining multiple attributes

User class {
private String name;
private Integer age;
}
redisJSON.set(key, new SetArgs().json("{\"name\":\"test\"}"))
redisJSON.get(key,User.class, new GetArgs().path("name", "age"))

error Exception:

org.redisson.client.RedisException: ERR Path 'age' does not exist. channel: [id: 0xaf7d7702, L:/127.0.0.1:57296 - R:127.0.0.1/127.0.0.1:6379] command: (JSON.GET), promise: RedissonPromise [promise=ImmediateEventExecutor$ImmediatePromise@62ccff0e(incomplete)], params: [key, name, age]
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:370)
	at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:198)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:137)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:113)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)
	at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:745)

@dengliming

127.0.0.1:6379> json.set b . '{"name":"abcd"}'
OK
127.0.0.1:6379> json.get b name age
(error) ERR Path 'age' does not exist

This should not be a client issue.