Golang(8)Database NOSQL

前端之家收集整理的这篇文章主要介绍了Golang(8)Database NOSQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Golang(8)Database NOsql

Redis
I am using redis 2.9.11

https://github.com/hoisie/redis
https://github.com/astaxie/goredis

Install the Driver
>go get github.com/astaxie/goredis

First of all,easily set up my Redis DB on my local machine. I will not demo the cluster mode. Just use the easiest one.

>cd /opt/redis
>./redis-server ./redis.conf

Once the server is started,we will see the log information as follow:
09 May 23:18:45.226 * The server is now ready to accept connections on port 7000

Then I can connect to the localhost server on the port 7000
>./redis-cli -h 127.0.0.1 -p 7000

Then running my go program to connect to the DB
package main

import (
"fmt"
"github.com/astaxie/goredis"
)

func main() {
var client goredis.Client
//set the address and port
client.Addr = "127.0.0.1:7000"

//string operation
client.Set("a",[]byte("hello"))
val,_ := client.Get("a")
fmt.Println(string(val))
client.Del("a")

//list
vals := []string{"a","b","c","d","e"}
for _,v := range vals {
client.Rpush("l",[]byte(v))
}
dbvals,_ := client.Lrange("l",4)
for i,v := range dbvals {
println(i,":",string(v))
}
client.Del("l")
}

Here is the console output
hello 0 : a 1 : b 2 : c 3 : d 4 : e


MongoDB
Upgrade to 2.6.0
>mv mongodb-osx-x86_64-2.6.0 /Users/carl/tool/
>sudo ln -s /Users/carl/tool/mongodb-osx-x86_64-2.6.0 /opt/mongodb-2.6.0
>sudo rm -fr /opt/mongodb
>sudo ln -s /opt/mongodb-2.6.0 /opt/mongodb

>mongod -f mongodb.conf
>mongo --host 127.0.0.1 --port 27017

I saw some warning messages as follow:
2014-05-11T13:58:01.765-0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256,should be at least 1000

Solution:
First of all,check the max of the open files
>ulimit -n
256

It really small number.
I can set it to a high number.
>ulimit -n 1024

But it will only working before we reboot the system.
>launchctl limit maxfiles 1024 1024

This command can make it working forever.

mgo is not official supported.
http://docs.mongodb.org/ecosystem/drivers/go/

http://godoc.org/labix.org/v2/mgo

…TODO

References:
Redis 1~ 7
http://sillycat.iteye.com/blog/1549504
http://sillycat.iteye.com/blog/1553507
http://sillycat.iteye.com/blog/1553508
http://sillycat.iteye.com/blog/1553509
http://sillycat.iteye.com/blog/2028180
http://sillycat.iteye.com/blog/2033094
http://sillycat.iteye.com/blog/2059166

MongoDB 1 ~ 5
http://sillycat.iteye.com/blog/1547291 Concept and Installation on windows and ubuntu
http://sillycat.iteye.com/blog/1547292 Java DAO Layer Example
http://sillycat.iteye.com/blog/1547294 Java DAO Layer Example
http://sillycat.iteye.com/blog/1965857 Installation on MAC and Replication,1 Master,2 Secondaries
http://sillycat.iteye.com/blog/1965880 Scala Clients

https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/05.6.md

原文链接:https://www.f2er.com/go/190948.html

猜你在找的Go相关文章