本文整理匯總了Golang中github.com/fzzbt/radix/redis.Client.Hgetall方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Hgetall方法的具體用法?Golang Client.Hgetall怎麽用?Golang Client.Hgetall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fzzbt/radix/redis.Client
的用法示例。
在下文中一共展示了Client.Hgetall方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
var c *redis.Client
conf := redis.DefaultConfig()
// Network and address
//
// Default are "tcp" and "127.0.0.1:6379" so these are commented out.
// TCP example:
// conf.Network = "tcp"
// conf.Address = "127.0.0.1:6379"
// Unix example:
// conf.Network = "unix"
// conf.Address = "/tmp/redis.sock"
conf.Database = 8 // Database number
conf.Timeout = time.Duration(10) * time.Second // Socket timeout
c = redis.NewClient(conf)
defer c.Close()
//** Blocking calls
rep := c.Flushdb()
if rep.Err != nil {
fmt.Println("redis:", rep.Err)
return
}
//* Strings
// It's generally good idea to check for errors like this,
// but for the sake of keeping this example short we'll omit these from now on.
if rep = c.Set("mykey0", "myval0"); rep.Err != nil {
fmt.Println("redis:", rep.Err)
return
}
var err error
var s string
if rep = c.Get("mykey0_may_not_exist"); rep.Type == redis.ReplyNil {
//key not found
fmt.Println("key not found ")
} else if s, err = rep.Str(); err != nil {
fmt.Println("Get error ", err)
return
}
fmt.Println("mykey0:", s)
myhash := map[string]string{
"mykey1": "myval1",
"mykey2": "myval2",
"mykey3": "myval3",
}
// Alternatively:
// c.Mset("mykey1", "myval1", "mykey2", "myval2", "mykey3", "myval3")
c.Mset(myhash)
ls, err := c.Mget("mykey1", "mykey2", "mykey3").List()
if err != nil {
fmt.Println(err)
return
}
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
//.........這裏部分代碼省略.........