From e043d7a4772e08ce158645199c7dc14908589e51 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Sat, 30 Sep 2017 01:36:55 +0200 Subject: redis functions renaming --- redigo.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'redigo.go') diff --git a/redigo.go b/redigo.go index ff1bf3f..f83b174 100644 --- a/redigo.go +++ b/redigo.go @@ -3,8 +3,47 @@ package main import ( "github.com/go-redis/redis" "fmt" + "time" ) +var client *redis.Client + +func init() { + client = redis.NewClient(&redis.Options{ + Addr: "192.168.0.16:6379", + Password: "", // no password set + DB: 0, // use default DB + + // DialTimeout: 10 * time.Second, + // ReadTimeout: 30 * time.Second, + // WriteTimeout: 30 * time.Second, + // PoolSize: 10, + // PoolTimeout: 30 * time.Second, + }) + //client.FlushDB() +} + +func getRed(key string) string { + val, err := client.Get(key).Result() + if err == redis.Nil { + return "nil" + } else if err != nil { + panic(err) + return err.Error() + } else { + return val + } +} + +func setRed(key string , val string, dur int) bool { + err := client.Set(key, val,time.Duration(dur)*time.Second).Err() + if err != nil { + panic(err) + return false + } + return true +} + func ExampleNewClient() { client := redis.NewClient(&redis.Options{ Addr: "192.168.0.16:6379", @@ -17,13 +56,14 @@ func ExampleNewClient() { // Output: PONG } + func ExampleClient() { client := redis.NewClient(&redis.Options{ Addr: "192.168.0.16:6379", Password: "", // no password set DB: 0, // use default DB }) - err := client.Set("key", "value", 0).Err() + err := client.Set("zack", "kack", 0).Err() if err != nil { panic(err) } @@ -46,6 +86,9 @@ func ExampleClient() { // key2 does not exists } -func main() { - ExampleNewClient() -} +//func main() { + //ExampleClient() +// if setRed("scheisse","geil",10) { +// fmt.Println("euda") +// } +//} -- cgit v1.2.3