Skip to content

Commit d981d60

Browse files
committed
Update 05.6.md
Updated the Redis example to match the latest from the chinese edition.
1 parent 6c0ff44 commit d981d60

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

eBook/05.6.md

+26-25
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,34 @@ I forked the last one and fixed some bugs, and use it in my short URL service(2
2020
Let's see how to use the driver that I forked to operate database:
2121

2222
package main
23-
23+
2424
import (
25-
"github.com/astaxie/goredis"
26-
"fmt"
25+
"github.com/astaxie/goredis"
26+
"fmt"
2727
)
28-
28+
2929
func main() {
30-
var client goredis.Client
31-
// string
32-
var client goredis.Client
33-
client.Set("a", []byte("hello"))
34-
val, _ := client.Get("a")
35-
fmt.Println(string(val))
36-
client.Del("a")
37-
38-
// list
39-
40-
var client goredis.Client
41-
vals := []string{"a", "b", "c", "d", "e"}
42-
for _, v := range vals {
43-
client.Rpush("l", []byte(v))
44-
}
45-
dbvals,_ := client.Lrange("l", 0, 4)
46-
for i, v := range dbvals {
47-
println(i,":",string(v))
48-
}
49-
client.Del("l")
30+
var client goredis.Client
31+
32+
// Set the default port in Redis
33+
client.Addr = "127.0.0.1:6379"
34+
35+
// string manipulation
36+
client.Set("a", []byte("hello"))
37+
val, _ := client.Get("a")
38+
fmt.Println(string(val))
39+
client.Del("a")
40+
41+
// list operation
42+
vals := []string{"a", "b", "c", "d", "e"}
43+
for _, v := range vals {
44+
client.Rpush("l", []byte(v))
45+
}
46+
dbvals,_ := client.Lrange("l", 0, 4)
47+
for i, v := range dbvals {
48+
println(i,":",string(v))
49+
}
50+
client.Del("l")
5051
}
5152

5253
We can see that it's quite easy to operate redis in Go, and it has high performance. Its client commands are almost the same as redis built-in commands.
@@ -105,4 +106,4 @@ We can see that there is no big different to operate database between mgo and be
105106
##Links
106107
- [Directory](preface.md)
107108
- Previous section: [Develop ORM based on beedb](05.5.md)
108-
- Next section: [Summary](05.7.md)
109+
- Next section: [Summary](05.7.md)

0 commit comments

Comments
 (0)