Home > Software engineering >  Redis-protobuf: Err type mismatch seen with protos having nested messages
Redis-protobuf: Err type mismatch seen with protos having nested messages

Time:07-28

When there are more than one proto files with nested messages loaded by libredis-protobuf.so, unable to set any fields of the second proto message. Both proto files are proto3 version.

127.0.0.1:6379> PB.SCHEMA Msg   
"message Msg {\n  int32 i = 1;\n  .SubMsg sub = 2;\n  repeated int32 arr = 3;\n}\n"    
127.0.0.1:6379> PB.SET key Msg '{"i" : 1, "sub" : {"s" : "string", "i" : 2}, "arr" : [1, 2, 3]}'   
(integer) 1   
127.0.0.1:6379> PB.GET key --FORMAT JSON Msg   
"{\"i\":1,\"sub\":{\"s\":\"string\",\"i\":2},\"arr\":[1,2,3]}"    
127.0.0.1:6379>    
127.0.0.1:6379> PB.SCHEMA Rsg2   
"message Rsg2 {\n  int32 i = 1;\n  .SubRsg2 sub = 2;\n  repeated int32 arr = 3;\n}\n"    
127.0.0.1:6379>    
127.0.0.1:6379> PB.SET key Rsg2 '{"i" : 1, "sub" : {"s" : "string", "i" : 2}, "arr" : [10, 20, 30]}'   
(error) ERR type mismatch  
127.0.0.1:6379>   
127.0.0.1:6379> PB.SET key Rsg2 /i 10   
(error) ERR type missmatch    
127.0.0.1:6379> PB.SET key Rsg2 /arr/0 2   
(error) ERR type missmatch    
127.0.0.1:6379>    

Same issue seen when using protobuf-3.8.0-map-reflection.tar.gz and latest protobuf. Any help/info appreciated.

CodePudding user response:

Because you've already set key as an object of Msg type. When you try to set key to an object of another type, e.g. Rsg2, it returns error reply: type mismatch. It behaviors like trying to set a key of which the type is HASH.

You need to delete the key, and then you can set it to an object of another type. Or just setting another key.

PB.SET another-key Rsg2 '{"i" : 1, "sub" : {"s" : "string", "i" : 2}, "arr" : [10, 20, 30]}'   

B.T.W. there's a plan to set (key, value) pair without checking the type, i.e. an option: --FORCE.

  • Related