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.