-
Notifications
You must be signed in to change notification settings - Fork 6
HMGET error #4
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
base: master
Are you sure you want to change the base?
HMGET error #4
Conversation
func Do need a interface{} slice, not a string and a []interface{}. If input k1,f1,f2, hmget get [k1, [f1, f2]], this is not work, hmget need [k1, f1, f2].
After test, append(args, hashKeys) will return [string, []string]. So only can use for loop to get [string, string, string...]
connection.go
Outdated
|
|
||
| func HMGet(RConn *redigo.Conn, key string, hashKeys ...string) ([]interface{}, error) { | ||
| args := []interface{}{key} | ||
| args = append(args, hashKeys) |
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.
Have you tried this? - args = append(args, hasKeys...)
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.
of course, but cannot use hasKeys(type []string) as type []interface{}, unless change the hasKeys to ...interface{}
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.
func HMGet1(key string, hashKeys ...string) {
args := []interface{}{key}
for _, v := range hashKeys {
args = append(args, v)
}
}
func HMGet2(key string, hashKeys ...string) {
args := make([]interface{}, 1+len(hashKeys))
args[0] = key
for i, v := range hashKeys {
args[i+1] = v
}
}
func HMGet3(key string, hashKeys ...interface{}) {
args := []interface{}{key}
args = append(args, hashKeys...)
}
3000000 602 ns/op
3000000 417 ns/op
5000000 259 ns/op
I bench test the three method make a string and []string to a []string. The HMGet3 is best, so i suggest modifying the function parameter type to ...interface{}.
like this
func HMGet(RConn *redigo.Conn, key string, hashKeys ...interface{})
func HMGet1(key string, hashKeys ...string) {
args := []interface{}{key}
for _, v := range hashKeys {
args = append(args, v)
}
}
func HMGet2(key string, hashKeys ...string) {
args := make([]interface{}, 1+len(hashKeys))
args[0] = key
for i, v := range hashKeys {
args[i+1] = v
}
}
func HMGet3(key string, hashKeys ...interface{}) {
args := []interface{}{key}
args = append(args, hashKeys...)
}
3000000 602 ns/op
3000000 417 ns/op
5000000 259 ns/op
HMGet3 is best
After test, append(args, hashKeys) will return [string, []string]. So only can use ‘for loop‘ to get [string, string, string...], then hmget can get the well return