removed all the footers; formated all the files
This commit is contained in:
78
5.6.md
78
5.6.md
@@ -28,7 +28,7 @@ https://github.com/astaxie/goredis
|
||||
)
|
||||
|
||||
func main() {
|
||||
var client goredis.Client
|
||||
var client goredis.Client
|
||||
//字符串操作
|
||||
var client goredis.Client
|
||||
client.Set("a", []byte("hello"))
|
||||
@@ -41,15 +41,15 @@ https://github.com/astaxie/goredis
|
||||
var client goredis.Client
|
||||
vals := []string{"a", "b", "c", "d", "e"}
|
||||
for _, v := range vals {
|
||||
client.Rpush("l", []byte(v))
|
||||
client.Rpush("l", []byte(v))
|
||||
}
|
||||
dbvals,_ := client.Lrange("l", 0, 4)
|
||||
for i, v := range dbvals {
|
||||
println(i,":",string(v))
|
||||
println(i,":",string(v))
|
||||
}
|
||||
client.Del("l")
|
||||
}
|
||||
|
||||
|
||||
我们可以看到操作redis非常的方便,而且我实际项目中应用下来性能也很高。client的命令和redis的命令基本保持一致。所以和原生态操作redis非常类似。
|
||||
|
||||
## mongoDB
|
||||
@@ -64,53 +64,49 @@ MongoDB是一个高性能,开源,无模式的文档型数据库,是一个
|
||||
|
||||
下面我将演示如果通过Go来操作mongoDB:
|
||||
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"labix.org/v2/mgo"
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
import (
|
||||
"fmt"
|
||||
"labix.org/v2/mgo"
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
Phone string
|
||||
}
|
||||
type Person struct {
|
||||
Name string
|
||||
Phone string
|
||||
}
|
||||
|
||||
func main() {
|
||||
session, err := mgo.Dial("server1.example.com,server2.example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer session.Close()
|
||||
func main() {
|
||||
session, err := mgo.Dial("server1.example.com,server2.example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer session.Close()
|
||||
|
||||
session.SetMode(mgo.Monotonic, true)
|
||||
session.SetMode(mgo.Monotonic, true)
|
||||
|
||||
c := session.DB("test").C("people")
|
||||
err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
|
||||
&Person{"Cla", "+55 53 8402 8510"})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c := session.DB("test").C("people")
|
||||
err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
|
||||
&Person{"Cla", "+55 53 8402 8510"})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
result := Person{}
|
||||
err = c.Find(bson.M{"name": "Ale"}).One(&result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
result := Person{}
|
||||
err = c.Find(bson.M{"name": "Ale"}).One(&result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Phone:", result.Phone)
|
||||
}
|
||||
fmt.Println("Phone:", result.Phone)
|
||||
}
|
||||
|
||||
我们可以看出来mgo的操作方式和beedb的操作方式几乎类似,都是基于strcut的操作方式,这个就是Go Style。
|
||||
|
||||
|
||||
|
||||
## links
|
||||
* [目录](<preface.md>)
|
||||
* 上一节: [使用beedb库进行ORM开发](<5.5.md>)
|
||||
* 下一节: [小结](<5.7.md>)
|
||||
|
||||
## LastModified
|
||||
* $Id$
|
||||
## links
|
||||
* [目录](<preface.md>)
|
||||
* 上一节: [使用beedb库进行ORM开发](<5.5.md>)
|
||||
* 下一节: [小结](<5.7.md>)
|
||||
|
||||
Reference in New Issue
Block a user