The example in this article describes the Go language operation Redis usage. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
Package Main
Import (
"FMT"
"Log"
"Redis"
)
Func Main () {
Defaultspec () Create a connection specification
Spec: = Redis. Defaultspec (). Db (0). Password ("");
Create a new syncclient and connect to the Redis server to use to specify the Connectionspec interface.
Client, Err: = Redis. Newsynchclientwithspec (spec);
If Err!= nil {
Log. PRINTLN ("Connect Server failed >", err);
Return
}
Dbkey: = "GAME:TEST:info";
Value, Err: = client. Get (Dbkey);
If err!= Nil {
Log. PRINTLN ("Error on Get", err);
Return
}
//
if value = = Nil {
Value: =[]byte ("Hello world!");
Client. Set (Dbkey, value);
Fmt. Printf ("Insert data >%s \ n", value)
} else {
Fmt. Printf ("received data >%s \ n", value);
Return
}
}
I hope this article will help you with your go language program.