Using the C-language client (Hiredis) connection redis--Huawei Cloud DCs for Redis experience series

Source: Internet
Author: User
Tags redis version

Key words: Hiredis, Credis, Redis clients, Redis client, C client, Huawei Cloud distributed cache service

Hiredis is a very comprehensive C-language version of the Redis interface library that supports all commands, pipelines, and scripts. The Huawei Cloud distributed cache Service Redis version supports Hiredis client connections.

Using the C language Client (Hiredis) to connect to Redis, you need to install the build environment and Hiredis, and in CentOS as an example, introduce the C client environment setup.

No. 0 Step: Prepare for work

Huawei Cloud purchased 1 ECS (I chose CentOS 6.3), a distributed cache instance (DCS for Redis), I chose a standalone instance.

Note that ECS and cache instances are configured with the same VPC and security groups to ensure network interoperability.

1th step: Installing GCC, make, and Hiredis

If your system does not have a compiled environment, you can install it using YUM.

Yum Install gcc make

Download and unzip Hiredis

Wget Https://github.com/redis/hiredis/archive/master.zip;

Go to the Unzip directory and compile the installation

Make

Make install

Once the installation is complete, you can try the connection.

2nd step: Connect to Redis

With regard to the use of Hiredis, the Redis official website gives a detailed introduction to use. Here is a simple example of connection, password authentication, set, and get methods.

Edit Connect demo instance, such as:

Vim CONNREDIS.C

#include <stdio.h> #include <stdlib.h> #include <string.h> #include 

To exit after saving, execute the following command to compile:

GCC Connredis.c-o connredis-i/usr/local/include/hiredis-lhiredis

If there is an error, look for the Hiredis.h file path and modify the compile command.

After compiling, get an executable file Connredis,

Test the connection by testing the following command:

./connredis {redis_ip_address} 6379 {password}

Get the following echo, then the demo works:

[Email protected] heru]#  

Note that if you run an error to find the Hiredis library file, you can refer to the following, copy the relevant files to the system directory, and add dynamic links.

Mkdir/usr/lib/hirediscp/usr/local/lib/libhiredis.so.0.13/usr/lib/hiredis/mkdir/usr/include/hirediscp/usr/local /include/hiredis/hiredis.h/usr/include/hiredis/echo '/usr/local/lib ' >>/etc/ld.so.confldconfig

The location of the above so file and the. h file needs to be replaced by the actual file location.

Using the C-language client (Hiredis) connection redis--Huawei Cloud DCs for Redis experience series

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.