Golang(8)Database NOSQL

Golang(8)Database NOSQL,第1张

概述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

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

总结

以上是内存溢出为你收集整理的Golang(8)Database NOSQL全部内容,希望文章能够帮你解决Golang(8)Database NOSQL所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存