The go language driver for Redis has matured, using Redigo to get an example.
Package main//redis Test//author:xiong Chuan liang//date:2015-3-5import ("FMT" "Time" "Log" "github.com/garyburd/redigo/ Redis ") Func main () {FMT. Println ("Redis:") Conn,err: = Redisconn ("", "" "," 6 "); if err! = Nil {log. Fatal ("Error:", err)}test (conn)}func test (conn *redisconn) {Conn. Do ("SET", "xxx", 1) if Xxx,err: =redis. INT (Conn. Do ("GET", "xxx")); Err = = Nil {fmt. Println ("XXX:", xxx)}conn. Flushclose ()}////////////////////////////////////////////////////////////////type RedisConn struct {dbid Stringredis. Conn}func (R *redisconn) flushclose () Error {_, Err: = R.conn.do ("select", r.dbid) if err! = Nil {return nil}_, err = R.conn . Do ("Flushdb") if err! = Nil {return Err}return r.conn.close ()}func (R *redisconn) Close () error {return r.conn.close ()}func Redisconn (Host,password,db string) (*redisconn, error) {if host = = "" {host = ": 6379"}//conn, err: = Redis. Dial ("TCP", host) conn, err: = Redis. Dialtimeout ("TCP", host, 0, 1*time. Second, 1*time. Second) If err! = Nil {return nil, err}if password! = "" {if _, err: = conn. Do ("AUTH", password); Err! = NIL {conn. Close () return nil, err}}if db! = "" {if _, err: = conn. Do ("select", db); Err! = NIL {conn. Close () return nil, Err}}return &redisconn{dbid:db,conn:conn}, nil}
You can see how easy it is to use.
Mail:[email protected]
blog:http://blogcsdn.net/xcl168
Go language Operation Redis