本文整理汇总了Golang中redis.AsyncClient.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang AsyncClient.Set方法的具体用法?Golang AsyncClient.Set怎么用?Golang AsyncClient.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.AsyncClient
的用法示例。
在下文中一共展示了AsyncClient.Set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: save
func save(r redis.AsyncClient, key string, obj interface{}, w http.ResponseWriter) {
var b bytes.Buffer
z := zlib.NewWriter(&b)
defer z.Close()
je := json.NewEncoder(z)
err := je.Encode(obj)
if err != nil {
log.Fatal("Failed to json Encode with error: ", err)
}
z.Flush()
f, rerr := r.Set(key, b.Bytes())
if rerr != nil {
panic(rerr)
}
_, rerr, timeout := f.TryGet(50000000000)
if rerr != nil {
panic(rerr)
}
if timeout {
savetimeout++
log.Println("save timeout! count: ", savetimeout)
fmt.Fprintf(w, "Save failed for %s", key)
}
}
示例2: primeKey
func primeKey(key string, r redis.AsyncClient) {
path := "document.json"
file, err := os.Open(path)
if err != nil {
panic(err)
}
reader := bufio.NewReader(file)
document, _ := ioutil.ReadAll(reader)
var b bytes.Buffer
z := zlib.NewWriter(&b)
z.Write(document)
z.Close()
f, rerr := r.Set(key, b.Bytes())
if rerr != nil {
panic(rerr)
}
_, rerr, timeout := f.TryGet(50000000000)
if rerr != nil {
panic(rerr)
}
if timeout {
savetimeout++
log.Println("save timeout! count: ", savetimeout)
}
}
示例3: load
func load(r redis.AsyncClient, k string, w http.ResponseWriter) (obj interface{}) {
f, rerr := r.Get(k)
if rerr != nil {
panic(rerr)
}
val, rerr, timeout := f.TryGet(50000000000)
if rerr != nil {
panic(rerr)
}
if timeout {
loadtimeout++
log.Println("load timeout! count: ", loadtimeout)
fmt.Fprintf(w, "Save failed for %s", key)
return
}
setPromise, srerr := r.Set(key, val)
if srerr != nil {
panic(rerr)
}
_, grerr, timeout := setPromise.TryGet(50000000000)
if grerr != nil {
panic(rerr)
}
if timeout {
savetimeout++
log.Println("save timeout! count: ", savetimeout)
fmt.Fprintf(w, "Save failed for %s", key)
}
return
}
示例4: doSet
func doSet(id string, signal chan int, client redis.AsyncClient, cnt int) {
key := "set-" + id
value := []byte("foo")
for i := 0; i < cnt; i++ {
client.Set(key, value)
}
signal <- 1
}