forked from navy1125/gostudy
/
redistest.go
47 lines (40 loc) · 1.06 KB
/
redistest.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
package main
import (
"fmt"
"github.com/simonz05/godis/redis"
"os"
)
func main() {
// new client on default port 6379, select db 0 and use no password
c := redis.New("tcp:112.65.197.72:6379", 0, "")
// set the key "foo" to "Hello Redis"
if err := c.Set("foo1", "Hello Redis"); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
c.Set("hxsg_uid_max", 300000)
c.Set("hxsg_sid_max", 3000000)
// retrieve the value of "foo". Returns an Elem obj
elem, _ := c.Get("max_id")
elem1, _ := c.Get("foo1")
// convert the obj to a string and print it
fmt.Println("foo:", elem.String())
fmt.Println("foo1:", elem1.String())
if _, err := c.Hset("myhash", "field", "field"); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
elem2, _ := c.Get("name")
elem3, _ := c.Hget("myhash", "field1")
size, _ := c.Hlen("myhash")
fmt.Println("name:", elem2.String())
fmt.Println("field:", elem3.String())
fmt.Println("size:", size)
TestType("asdfdf")
}
func TestType(value interface{}) {
switch v := value.(type) {
case string:
fmt.Println("type:", v, value)
}
}