[Go] hiredis:redis C Client Usage note

Source: Internet
Author: User

    1. compile
    2. use
      • initialize
      • to connect to a Redis database

        Rediscontext * pconn = Red Isconnect (Redisip.c_str (), redisport);
        if (m_clocal = = NULL)
        {
        return 1;
        }

        if (Pconn->err)
        {
        cout << "Connection to redis[" << redisip << "] Error:" << pCo nn->errstr;
        Redisfree (Pconn);
        Return 2;
        }

      • execute command

        String cmd= "Set foo bar;
        Redisreply * reply= (redisreply *) Rediscommand (Pconn, Cmd.c_str ());
        if (reply = = NULL)
        {
        cout << "redis[" << redisip << "] excute" << cmd << "fa iled, error is: "<< pconn->errstr;
        Redisfree (pconn);
        Pconn=null;
        Return 3;
        }
        Freereplyobject (reply);

      • Parse results
        • different commands return different types of results, which need to be resolved according to the Reply->type field
    3. Considerations

Once An error is returned the context cannot being reused and you should set up a new connection.

When the command is executed in the example above, if an error is returned, the connection is not available and the connection needs to be re-established.

For more articles, welcome to my Site: 01 streams.

[Go] hiredis:redis C Client Usage note

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.