本文整理匯總了Golang中github.com/fzzbt/radix/redis.Client類的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: test
func test(c *redis.Client, ch chan struct{}, doneChan chan struct{}, command string, params ...interface{}) {
for _ = range ch {
r := c.Call(command, params...)
if r.Err != nil {
fmt.Println(r.Err)
os.Exit(1)
}
}
doneChan <- struct{}{}
}
示例2: 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
//.........這裏部分代碼省略.........
示例3: setHandle
func setHandle(data string, c *redis.Client, ch chan struct{}) {
for _ = range ch {
c.Set(key, data)
}
}
示例4: getHandle
func getHandle(data string, c *redis.Client, ch chan struct{}) {
for _ = range ch {
c.Get(key)
}
}
示例5: pingHandle
func pingHandle(data string, c *redis.Client, ch chan struct{}) {
for _ = range ch {
c.Ping()
}
}