go-redisでIncr
package main
import (
"fmt"
"strconv"
"time"
"github.com/go-redis/redis"
)
func getRedisClient() (*redis.Client) {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
return client
}
func check(key string) {
rc := getRedisClient()
v := rc.Incr(key)
fmt.Printf("key:%v,v(%d):%v,%v\n", key, v.Val(), v.Err(), v.Val())
if v.Err() != nil {
fmt.Print("error is not nil\n")
}
if v.Err() == redis.Nil {
fmt.Print("redis.Nil is coming\n")
}
}
func main() {
ts := strconv.Itoa(int(time.Now().Unix()))
key := "thekey:"+ts
check(key)
check(key)
}
$ go run main.go
key:thekey:1584105149,v(1):<nil>,1
key:thekey:1584105149,v(2):<nil>,2
Author And Source
この問題について(go-redisでIncr), 我々は、より多くの情報をここで見つけました https://qiita.com/adad/items/64a972b361fa6153728d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .