-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement FUNCTION
group of commands
#2475
Conversation
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.
Good, please continue...
@vmihailenco , @monkey92t, if the approach I had with |
|
Indeed. I was reluctant to name it just |
|
Ok, fixed. Thanks for the insight. |
Looks good so far 👍 |
Looking at the Option 1 redis.FunctionsList() // []Library{}
redis.FunctionsListWithCode() // []Library{}
redis.FunctionList("mylib") // Library{}
redis.FunctionListWithCode("mylib") // Library{} Option 2 redis.FunctionListAll() // []Library{}
redis.FunctionListAllWithCode() // []Library{}
redis.FunctionList("mylib") // Library{}
redis.FunctionListWithCode("mylib") // Library{} Option 3 redis.Libraries() // []Library{}
redis.LibrariesWithCode() // []Library{}
redis.Library("mylib") // Library{}
redis.LibraryWithCode("mylib") // Library{} Option 4 redis.ListLibraries() // []Library{}
redis.ListLibrariesWithCode() // []Library{}
redis.ListLibrary("mylib") // Library{}
redis.ListLibraryWithCode("mylib") // Library{} Option 5 q := FunctionListQuery{
LibraryName: "mylib",
WithCode: true
}
redis.FunctionList(q) // []Library{} Options 1 and 2
Options 3 and 4
Option 5
|
I think: func FunctionList(libraryNamePattern string, withCode bool) []Library We should try to keep consistent with redis commands, and should not increase the cost for users to learn go-redis. |
Yeah, I definitely see the point there; I just feel that it wouldn't look very pretty when we call the method without the optional arguments:
The following would actually be equivalent, and it looks better, but then we would have to teach people to use it that way; it's not obvious:
At the very minimum, I could make the library name pattern its own struct and pass nil. Still not great, but I think it looks a bit better than an empty string. What do you think?
|
I think it should be either func FunctionList(libraryNamePattern string, withCode bool) []Library or Option 5 rdb.FunctionList(FunctionList{
LibraryName: "mylib",
WithCode: true,
}) // []Library{} The latter is somewhat more readable.
We could add a helper function to retrieve a single library: rdb.FunctionList(...).Result() // []Library
rdb.FunctionList(...).First() // *Library |
Also check: // SORT list LIMIT 0 2 ASC
vals, err := rdb.Sort(ctx, "list", &redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
// ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
vals, err := rdb.ZRangeByScoreWithScores(ctx, "zset", &redis.ZRangeBy{
Min: "-inf",
Max: "+inf",
Offset: 0,
Count: 2,
}).Result()
// ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM
vals, err := rdb.ZInterStore(ctx, "out", &redis.ZStore{
Keys: []string{"zset1", "zset2"},
Weights: []int64{2, 3}
}).Result() |
I've considered "Option 5" too, if you all like it then we'll use it. 😄 |
Great that we have an agreement :) I implemented everything as you suggested, with the only difference being that the I also implemented a |
Library is large enough that we can use ptr. What is the point of adding FirstVal()? |
Ok, I'll change it to a pointer then. Re: FirstVal(), my reasoning was to have the matching "single-library" method for
|
Signed-off-by: monkey92t <golang@88.com>
@elena-kolevska I tidied up the code.....I hope you won't mind. 😊 |
Of course not! Quite the contrary, it’s great for my learning. 🙏 |
@elena-kolevska Do you want to add more commands? such: |
Since I'll only be able to come back to this next week, I'd suggest we close this PR now, and I'll add what's missing next week. There was also a PR on |
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.
OK, we don't need to close it, this PR can already do some work, we will add function kill
, function status
later.
@elena-kolevska Waiting for you to finish the rest of the work. 😄 |
Yeah, sorry, I meant "merge it" I'm very much looking forward to it too ;) |
@elena-kolevska thanks for your contribution and putting an extra effort into API design! It's clean and simple 👍 |
Implemented load, delete and flush. Working on
function list