【C/C++】c++多进程与hiredis的浅使用-创新互联
#include
#include
#include
#include
#include
int main(){
pid_t pid;
pid = fork();
if(pid <0 ){
std::cout<< "fork error!"<
}
//父子进程都执行
redisContext* conn = redisConnect("10.1.175.130", 6379);
if(NULL==conn || conn->err){
if(conn){
std::cout<<"Error:"<
redisFree(conn);
} else {
std::cout<<"Error:Can't allocate redis context"<
}
return 0;
}
if(0==pid){
const char* command = "set name yuanzaixin";
redisReply* r = (redisReply*)redisCommand(conn, command);
if(NULL==r){
redisFree(conn);
return 0;
}
std::cout<<"fork child"<
}
if(pid >0){
//父进程执行不一样的命令
const char* command = "set name xinzaiyuan";
redisReply* r = (redisReply*)redisCommand(conn, command);
if(NULL==r){
redisFree(conn);
return 0;
}
std::cout<<"fork parent"<
}
//父子进程都执行
if (NULL!=conn){
redisFree(conn);
}
}
标题名称:【C/C++】c++多进程与hiredis的浅使用-创新互联
分享链接:http://pwwzsj.com/article/cejhgc.html