-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.go
50 lines (41 loc) · 939 Bytes
/
redis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"log"
"flag"
"time"
"github.com/gomodule/redigo/redis"
)
var (
pool *redis.Pool
redisServer = flag.String("redisServer" , ":6379" , "")
)
func newPool(addr string) *redis.Pool {
return &redis.Pool{
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
Dial: func ()(redis.Conn , error){
c , err := redis.Dial("tcp" , addr)
if err != nil {
return nil , err
}
return c , err
},
}
}
func main() {
flag.Parse()
pool = newPool(*redisServer)
conn := pool.Get()
defer conn.Close()
result , error := conn.Do("SET" , "test" , "888888")
if error != nil {
log.Fatal(error)
}
fmt.Println("result: " , result)
data , err := redis.String(conn.Do("GET" , "test"))
if err != nil {
log.Fatal(err)
}
fmt.Println("redis : " , data)
}