diff options
Diffstat (limited to 'redigo.go')
| -rw-r--r-- | redigo.go | 51 |
1 files changed, 47 insertions, 4 deletions
@@ -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 <nil> } + 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") +// } +//} |
