Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

JSONQGet + JSON.INDEX ADD #40

wants to merge 3 commits into from

Conversation

gatomazi
Copy link

Created functions to use the RedisJSON2 JSON.QGet, JSON.INDEX add and a JSON.SETWithIndex

@gatomazi gatomazi requested a review from nitishm January 21, 2020 15:04
@coveralls
Copy link

coveralls commented Jan 21, 2020

Pull Request Test Coverage Report for Build 97

  • 0 of 16 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-11.9%) to 88.06%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rejson.go 0 16 0.0%
Totals Coverage Status
Change from base Build 96: -11.9%
Covered Lines: 118
Relevant Lines: 134

💛 - Coveralls

Copy link
Collaborator

@Shivam010 Shivam010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether to implement the RedisJSON2 methods or not.
But I think the interface ReJSON and the current Handler must not be updated as the users using RedisJSON does not have support for new methods in RedisJSON2.

Comment on lines 17 to +27
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)

Copy link
Collaborator

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 interface ReJSON2 and embed ReJSON 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:

Suggested change
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)
type ReJSON2 interface {
ReJSON
JSONSetWithIndex(key, path string, obj interface{}, index string) (res interface{}, err error)
JSONQGet(key string, params ...string) (res interface{}, err error)
JSONIndexAdd(key, field, path string) (res interface{}, err error)
}

Comment on lines +85 to +93
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)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate handler for the ReJSON2, and implement the ReJSON2 interface on it.
You can also wrap the original handler and create a new handler for ReJSON2.

Comment on lines +117 to +134
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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all new methods

Comment on lines +53 to +55
ReJSONCommandQGET ReJSONCommandID = 20
ReJSONCommandINDEXADD ReJSONCommandID = 21
ReJSONCommandSETINDEX ReJSONCommandID = 22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion to differentiate from others

Suggested change
ReJSONCommandQGET ReJSONCommandID = 20
ReJSONCommandINDEXADD ReJSONCommandID = 21
ReJSONCommandSETINDEX ReJSONCommandID = 22
ReJSON2CommandQGET ReJSONCommandID = 20
ReJSON2CommandINDEXADD ReJSONCommandID = 21
ReJSON2CommandSETINDEX ReJSONCommandID = 22

Copy link
Collaborator

@Shivam010 Shivam010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, update the test cases to achieve significant code coverage.

@Shivam010 Shivam010 self-requested a review March 4, 2020 20:27
@Shivam010
Copy link
Collaborator

Hey @breno12321 👋
Would you like to try this one? It appears @gatomazi has gone inactive.
Considering #60 (comment) it would be helpful 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants