Go language Operation Redis Usage instance _golang

Source: Internet
Author: User
Tags redis redis server

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.