Redis C Client API

Source: Internet
Author: User
Tags mkdir redis redis server

Redis Installation steps:

1.redis Server Installation wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz #下载文件
Tar xzf redis-2.4.6.tar.gz
CD redis-2.4.6
Make
CP Src/redis-server src/redis-cli/usr/bin/#方便在终端在任何地方直接运行
CP redis.conf/etc/
UFW Allow 6379 #ubuntu下开启端口


Modify the/etc/redis.conf to have the server perform the daemon in the background.
Daemonize Yes


2. Start Redis Service
Redis-server/etc/redis.conf


3. Detect whether the Redis service starts normally

Ps-ef | grep Redis


Hiredis Client Download Address: Https://github.com/redis/hiredis


Hiredis installation steps:
Tar zxvf Antirez-hiredis-v0.10.1-0-g3cc6a7f.zip
CD antirez-hiredis-3cc6a7f
make


Mkdir/usr/lib/hiredis
CP Libhiredis.so/usr/lib/hiredis #将动态连接库libhiredis. So to/usr/lib/hiredis
Mkdir/usr/include/hiredis
CP Hiredis.h/usr/include/hiredis




1. Connect hiredis server
#include <stdio.h>
#include < Hiredis/hiredis.h>


Rediscontext *conn = Redisconnect ("127.0.0.1", 6379);//redis Server default port
if ( Conn->err) {
printf ("Connection error:%s", conn->str);
}


2. Send command to server
redisreply *reply = Rediscommand (conn, "set key value");


3. Close the Reply object
Freereplyobject (reply);


4. Close the connection
Redisfree (conn);




Specific Some other APIs can look at the file's readme.md

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.