-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add key to the responses #24
Comments
FYI. I'm trying to implement a reasonably agnostic cache manager at https://github.com/chippyash/go-cache-manager |
Hi @chippyash, Are you looking for these? Line 40 in 92107ce
Line 12 in 92107ce
|
I guess you would probably interested in https://github.com/valkey-io/valkey-go/tree/main/valkeyaside. |
@rueian I'll take a look and get back to you I just read your docs and saw that I can do a DoMulti, so considered this a suitable construct. The problem is with Go handling of slices, so I hand the function a slice of key names, but the responses are, as far as I can tell, not necessarily coming back in the order I expect them. So if the response can contain the 'sent' key name, that would allow a quick match. |
Simply put, Change to type ValkeyResult struct { With the function to retrieve the key. |
The MGet helper I mentioned previously can help you retrieve the corresponding keys. |
But it isn't clear in your readme docs. I'll take a look, but it should not be hidden away Please consider the change, hopefully it's really simple. Kind regards |
The
Do you mean adding a Adding a field in the response struct to echo the command is also unnecessary because, besides the cmds := make(valkey.Commands, 0, 10)
for i := 0; i < 10; i++ {
cmds = append(cmds, client.B().Get().Key(strconv.Itoa(i)).Build().Pin())
}
for i, resp := range client.DoMulti(context.Background(), cmds...) {
fmt.Println(resp.ToString()) // this is the result
fmt.Println(cmds[i].Commands()[1]) // this is the corresponding key
} |
@rueian Thanks for that. That is what I am after. How do I recycle the command manually after it has been pinned? Also for other readers, if you are doing client side caching, the incantation is:
|
Recycling a command is tricky. You shouldn’t recycle it if In summary, you can only recycle a command after receiving its response from Valkey. However, handling this condition is too complex for users, so we don’t have an API for it. |
@rueian Thank you for your very timely help, which has been invaluable. I have now released a pre-production version of the library at https://github.com/chippyash/go-cache-manager. It will go through some battle testing in 3 other applications. I think you can consider this topic closed. Thanks again. |
I'm having difficulty in using the DoMulti methods. This is not because the command doesn't work, but because Go does not honor order in maps etc.
I have a workaround which is to use ordered maps, but it's a lot of weight to add.
It appears that
cacheResponses := cl.DoMulti(context.TODO(), cmds...)
will return the responses in the order they were sent, but matching them to the original request is difficult because of Go vagaries about map and slice order, hence the need for ordered mapsIf I may suggest, add the sent key to the responses, so that we can match the two.
Kind regards
Ashley
The text was updated successfully, but these errors were encountered: