本文整理匯總了Golang中github.com/fzzbt/radix/redis.Client.MultiCall方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.MultiCall方法的具體用法?Golang Client.MultiCall怎麽用?Golang Client.MultiCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fzzbt/radix/redis.Client
的用法示例。
在下文中一共展示了Client.MultiCall方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
//.........這裏部分代碼省略.........
fmt.Println("mykeys values:", ls)
//* List handling
mylist := []string{"foo", "bar", "qux"}
// Alternativaly:
// c.Rpush("mylist", "foo", "bar", "qux")
c.Rpush("mylist", mylist)
mylist, err = c.Lrange("mylist_may_not_exist", 0, -1).List()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("mylist:", mylist)
//* Hash handling
// Alternatively:
// c.Hmset("myhash", ""mykey1", "myval1", "mykey2", "myval2", "mykey3", "myval3")
c.Hmset("myhash", myhash)
myhash, err = c.Hgetall("myhash").Hash()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("myhash:", myhash)
//* Multicalls
rep = c.MultiCall(func(mc *redis.MultiCall) {
mc.Set("multikey", "multival")
mc.Get("multikey")
})
// Multicall reply is guaranteed to have the same number of sub-replies as calls,
// if it succeeds. They can be accessed through Reply.Elems.
if rep.Err != nil {
fmt.Println(rep.Err)
return
}
s, err = rep.Elems[1].Str()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("multikey:", s)
//* Transactions
rep = c.Transaction(func(mc *redis.MultiCall) {
mc.Set("trankey", "tranval")
mc.Get("trankey")
})
if rep.Err != nil {
fmt.Println(rep.Err)
return
}
s, err = rep.Elems[1].Str()
if err != nil {
fmt.Println(err)
return