-
Notifications
You must be signed in to change notification settings - Fork 47
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
JSONQGet + JSON.INDEX ADD #40
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,14 @@ func NewReJSONHandler() *Handler { | |
type ReJSON interface { | ||
JSONSet(key, path string, obj interface{}, opts ...rjs.SetOption) (res interface{}, err error) | ||
|
||
JSONSetWithIndex(key, path string, obj interface{}, index string) (res interface{}, err error) | ||
|
||
JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error) | ||
|
||
JSONQGet(key string, params ...string) (res interface{}, err error) | ||
|
||
JSONIndexAdd(key, field, path string) (res interface{}, err error) | ||
|
||
JSONMGet(path string, keys ...string) (res interface{}, err error) | ||
|
||
JSONDel(key, path string) (res interface{}, err error) | ||
|
@@ -71,6 +77,20 @@ func (r *Handler) JSONSet(key string, path string, obj interface{}, opts ...rjs. | |
return r.implementation.JSONSet(key, path, obj, opts...) | ||
} | ||
|
||
// JSONSetWithIndex used to set a json object | ||
// | ||
// ReJSON syntax: | ||
// JSON.SET <key> <path> <json> <index> | ||
// | ||
func (r *Handler) JSONSetWithIndex(key string, path string, obj interface{}, index string) ( | ||
res interface{}, err error) { | ||
|
||
if r.clientName == rjs.ClientInactive { | ||
return nil, rjs.ErrNoClientSet | ||
} | ||
return r.implementation.JSONSetWithIndex(key, path, obj, index) | ||
} | ||
|
||
Comment on lines
+85
to
+93
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. Create a separate handler for the ReJSON2, and implement the |
||
// JSONGet used to get a json object | ||
// | ||
// ReJSON syntax: | ||
|
@@ -88,6 +108,31 @@ func (r *Handler) JSONGet(key, path string, opts ...rjs.GetOption) (res interfac | |
return r.implementation.JSONGet(key, path, opts...) | ||
} | ||
|
||
// JSONQGet used to get a json object | ||
// | ||
// ReJSON syntax: | ||
// JSON.QGET <index> | ||
// [params ...] | ||
//Pass params like "@name:Tom" | ||
func (r *Handler) JSONQGet(key string, params ...string) (res interface{}, err error) { | ||
if r.clientName == rjs.ClientInactive { | ||
return nil, rjs.ErrNoClientSet | ||
} | ||
return r.implementation.JSONQGet(key, params...) | ||
} | ||
|
||
// JSONAddIndex used to get a json object | ||
// | ||
// ReJSON syntax: | ||
// JSON.INDEX ADD <index> <field> <path> | ||
// | ||
func (r *Handler) JSONIndexAdd(index, field, path string) (res interface{}, err error) { | ||
if r.clientName == rjs.ClientInactive { | ||
return nil, rjs.ErrNoClientSet | ||
} | ||
return r.implementation.JSONIndexAdd(index, field, path) | ||
} | ||
Comment on lines
+117
to
+134
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. Same for all new methods |
||
|
||
// JSONMGet used to get path values from multiple keys | ||
// | ||
// ReJSON syntax: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -50,6 +50,9 @@ const ( | |||||||||||||
ReJSONCommandDEBUG ReJSONCommandID = 17 | ||||||||||||||
ReJSONCommandFORGET ReJSONCommandID = 18 | ||||||||||||||
ReJSONCommandRESP ReJSONCommandID = 19 | ||||||||||||||
ReJSONCommandQGET ReJSONCommandID = 20 | ||||||||||||||
ReJSONCommandINDEXADD ReJSONCommandID = 21 | ||||||||||||||
ReJSONCommandSETINDEX ReJSONCommandID = 22 | ||||||||||||||
Comment on lines
+53
to
+55
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. Just a suggestion to differentiate from others
Suggested change
|
||||||||||||||
|
||||||||||||||
// JSONSET command Options | ||||||||||||||
SetOptionNX SetOption = "NX" | ||||||||||||||
|
@@ -86,12 +89,18 @@ var commandName = map[ReJSONCommandID]string{ | |||||||||||||
ReJSONCommandDEBUG: "JSON.DEBUG", | ||||||||||||||
ReJSONCommandFORGET: "JSON.FORGET", | ||||||||||||||
ReJSONCommandRESP: "JSON.RESP", | ||||||||||||||
ReJSONCommandQGET: "JSON.QGET", | ||||||||||||||
ReJSONCommandINDEXADD: "JSON.INDEX", | ||||||||||||||
ReJSONCommandSETINDEX: "JSON.SET", | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// commandMux maps command id to their Command Builder functions | ||||||||||||||
var commandMux = map[ReJSONCommandID]CommandBuilderFunc{ | ||||||||||||||
ReJSONCommandSET: commandJSONSet, | ||||||||||||||
ReJSONCommandSETINDEX: commandJSONSetWithIndex, | ||||||||||||||
ReJSONCommandGET: commandJSONGet, | ||||||||||||||
ReJSONCommandQGET: commandJSONQGet, | ||||||||||||||
ReJSONCommandINDEXADD: commandJSONIndexAdd, | ||||||||||||||
ReJSONCommandDEL: commandJSONGeneric, | ||||||||||||||
ReJSONCommandMGET: commandJSONMGet, | ||||||||||||||
ReJSONCommandTYPE: commandJSONGeneric, | ||||||||||||||
|
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.
Instead of adding these methods in
ReJSON
interface create a separate interfaceReJSON2
and embedReJSON
interfaces in it along with the new methods. And create a separate handler for the ReJSON2, so that the new module won't affect the original one.Something like this: