sewenew / redis-protobuf

Redis module for reading and writing Protobuf messages
Apache License 2.0
204 stars 22 forks source link

redis crash on map key set #17

Closed karabakin closed 4 years ago

karabakin commented 4 years ago

Hi! Thank you for such awesome module. Everything is great, but as inexperienced dev i have some troubles with maps:

127.0.0.1:6379>
127.0.0.1:6379> PB.SCHEMA Msg
"message Msg {\n  int32 i = 1;\n  SubMsg sub = 2;\n  repeated string str_arr = 3;\n  repeated SubMsg msg_arr = 4;\n  map<string, SubMsg> m = 5;\n}\n"
127.0.0.1:6379> PB.SCHEMA SubMsg
"message SubMsg {\n  string s = 1;\n}\n"
127.0.0.1:6379> PB.GET testkey Msg.m[key].s
(nil)
127.0.0.1:6379> PB.SET testkey Msg.m[key].s teststring
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
[libprotobuf FATAL /usr/local/include/google/protobuf/map_field.h:675] Protocol Buffer map usage error:
MapValueRef::type MapValueRef is not initialized.
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  Protocol Buffer map usage error:
MapValueRef::type MapValueRef is not initialized.

Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=2273, just started

Any thoughts/suggestions what am i do wrong? Thank you in advance!

sewenew commented 4 years ago

Hi @karabakin

I'm sorry, it's a bug... Thanks for finding it!

I've already fixed it. Please try the latest code, and it should be fixed.

Sorry again... Also if you still have any problem with redis-protobuf, feel free to let me know :)

Regards

karabakin commented 4 years ago

Works like a charm now, thank you! :)

And could you please suggest how to correctly escape some strange symbols map key name may contain (dots for example):

127.0.0.1:6379> PB.SCHEMA TaskReport
"message TaskReport {\n  string id = 1;\n  string hostname = 2;\n  map<string, int64> report = 3;\n}\n"
127.0.0.1:6379> PB.SET testkey1 TaskReport.report[new_report] 123
(integer) 1
127.0.0.1:6379> PB.SET testkey1 TaskReport.report[new_report.something_strange] 123
(error) ERR field not found: report[new_report
127.0.0.1:6379>
sewenew commented 4 years ago

Sorry, but so far, there's no way to do the escape on redis-protobuf side. You have to do the escape manually, and you need to escape the following characters: ., [, ]

However, it's a good idea to do the escape on redis-protobuf side. I opened a new issue to track this problem.

Thanks for this nice suggestion!

Regards

karabakin commented 4 years ago

Thank you @sewenew for such quick reply!