Redis C client API

Source: Internet
Author: User

Redis installation steps:

1. Install redis Server

Wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz # download files
Tar xzf redis-2.4.6.tar.gz
CD redis-2.4.6
Make
CP src/redis-server src/redis-cli/usr/bin/# It is convenient to run directly on the terminal anywhere
CP redis. CONF/etc/
UFW allow 6379 # enable port in Ubuntu

Modify/etc/redis. conf to enable the server to run in the background as a daemon.
Daemonize Yes

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

3. Check whether the redis service is properly started

PS-Ef | grep redis

Hiredis client: https://github.com/antirez/hiredis/zipball/master

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 # dynamically connect libhiredis. So to/usr/lib/hiredis
Mkdir/usr/include/hiredis
CP hiredis. h/usr/include/hiredis

1. Connect to the hiredis Server
# Include <stdio. h>
# Include

Rediscontext * conn = redisconnect ("127.0.0.1", 6379); // default port of the redis Server
If (Conn-> ERR ){
Printf ("connection error: % s", Conn-> Str );
}

2. send commands to the server
Redisreply * reply = rediscommand (Conn, "set key value ");

3. Disable the reply object
Freereplyobject (reply );

4. Close the connection
Redisfree (conn );

For more information, see the readme. md file.

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.