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