clion redis-demo
Posted luckygxf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了clion redis-demo相关的知识,希望对你有一定的参考价值。
1. github hiredis安装
redis-demo.c
#include <stdio.h> #include <stdlib.h> #include <hiredis.h> int main(int argc, char **argv) { // if (argc < 3) { // printf("usage: connRedis hostname port password "); // return 1; // } // char *hostname = argv[1]; // int port = atoi(argv[2]); // char *password = argv[3]; char *hostname = "127.0.0.1"; int port = 6379; char *password = ""; redisContext *conn; redisReply *reply; struct timeval timeout = {1, 500000}; conn = redisConnectWithTimeout(hostname, port, timeout); // conn erro if (conn == NULL || conn->err) { if (conn) { printf("connection error %s ", conn->errstr); exit(1); } else { printf("cannot alloc redis context "); exit(1); } } // auth reply = redisCommand(conn, "AUTH %s", password); printf("auth is %s ", reply->str); freeReplyObject(reply); // set reply = redisCommand(conn, "set %s %s", "name", "hello world11111"); printf("set is %s ", reply->str); freeReplyObject(reply); // get reply = redisCommand(conn, "get name"); printf("name :%s ", reply->str); freeReplyObject(reply); // free conn redisFree(conn); return 0; }
cmklist.txt
include_directories(/usr/local/include/hiredis) link_directories(/usr/local/lib) link_libraries(hiredis) add_executable(redis-demo redis-demo.c)
以上是关于clion redis-demo的主要内容,如果未能解决你的问题,请参考以下文章
进程以退出代码 -1073741819 (0xC0000005) C++ clion 完成
在 windows 上使用 clion 调试 rust 代码