-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support HSET
in redis
#3768
Changes from 18 commits
9d696e3
abd20ac
4807867
7ea0bec
bd3e3d3
87bc649
a53e4d1
d4a8bb1
cbde9a8
6773e1f
00c4a95
44f4b17
194682d
08ddb4e
9c98d8f
f52188c
d6e5ae6
9b8191c
189e91a
9a9cf61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ type KVStoreManager interface { | |
Connect() | ||
Close() error | ||
HMSet(key string, fields map[string]interface{}) error | ||
HSet(key, field string, value interface{}) error | ||
StatusCode(err error) int | ||
DeleteKey(key string) (err error) | ||
HMGet(key string, fields ...string) (result []interface{}, err error) | ||
|
@@ -21,6 +22,12 @@ type SettingsT struct { | |
Config map[string]interface{} | ||
} | ||
|
||
const ( | ||
hashPath = "message.hash" | ||
keyPath = "message.key" | ||
valuePath = "message.value" | ||
) | ||
|
||
func New(provider string, config map[string]interface{}) (m KVStoreManager) { | ||
return newManager(SettingsT{ | ||
Provider: provider, | ||
|
@@ -49,3 +56,21 @@ func EventToKeyValue(jsonData json.RawMessage) (string, map[string]interface{}) | |
|
||
return key, fields | ||
} | ||
|
||
// IsHSETCompatibleEvent identifies if the event supports HSET operation | ||
// To support HSET, the event must have the following fields: | ||
// - message.key | ||
// - message.value | ||
// - message.hash | ||
// It doesn't account for the value of the fields. | ||
func IsHSETCompatibleEvent(jsonData json.RawMessage) bool { | ||
return gjson.GetBytes(jsonData, hashPath).Exists() && gjson.GetBytes(jsonData, keyPath).Exists() && gjson.GetBytes(jsonData, valuePath).Exists() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would avoid the extensive and repeated usage of Using a go struct type HSetEvent struct {
Hash string `json:"<hash_path>"`
Key string `json:"<key_path>"`
Value string `json:"<value_path>"`
} It would be safer and faster (assuming fastjson library is used) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if I understand I can use fastjson's Exists but that doesn't require a go struct to unmarshal to. |
||
} | ||
|
||
func ExtractHashKeyValueFromEvent(jsonData json.RawMessage) (hash, key, value string) { | ||
hash = gjson.GetBytes(jsonData, hashPath).String() | ||
key = gjson.GetBytes(jsonData, keyPath).String() | ||
value = gjson.GetBytes(jsonData, valuePath).String() | ||
|
||
return hash, key, value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Optional] Maybe we can remove duplicate code and compact these tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed