Last active
April 25, 2026 23:35
-
-
Save kuc-arc-f/bb185150b28927db6406e128251e8a5a to your computer and use it in GitHub Desktop.
C++ windows LLVM CLang , Redis example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <chrono> | |
| #include <string> | |
| #include <thread> | |
| #include <hiredis/hiredis.h> | |
| int main() { | |
| try{ | |
| // 開始時刻 | |
| auto start = std::chrono::high_resolution_clock::now(); | |
| // Redis接続 | |
| redisContext* c = redisConnect("127.0.0.1", 6379); | |
| if (c == nullptr || c->err) { | |
| if (c) { | |
| std::cerr << "Connection error: " << c->errstr << std::endl; | |
| redisFree(c); | |
| } else { | |
| std::cerr << "Connection error: can't allocate redis context" << std::endl; | |
| } | |
| return 1; | |
| } | |
| // SET | |
| redisReply* reply = (redisReply*)redisCommand(c, "SET mykey TestValue"); | |
| int i; | |
| for (i = 0; i < 1000; i++) { | |
| std::string str_key = "SET k" + std::to_string(i) + ": value "; | |
| //std::cout << "str_key:" << str_key << std::endl; | |
| reply = (redisReply*)redisCommand(c, str_key.c_str()); | |
| //std::cout << "SET: " << reply->str << std::endl; | |
| } | |
| freeReplyObject(reply); | |
| std::cout << "#end-set" << std::endl; | |
| // 切断 | |
| redisFree(c); | |
| // 終了時刻 | |
| auto end = std::chrono::high_resolution_clock::now(); | |
| // 差分(ミリ秒) | |
| auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | |
| std::cout << "time: " << duration.count() << " ms" << std::endl; | |
| } catch (const std::exception& ex) { | |
| std::cerr << ex.what() << std::endl; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CXX = clang++ | |
| CXXFLAG_1= -I./include -I/prog/vcpkg/installed/x64-windows/include | |
| CXXFLAG_LIB_1= -L/prog/vcpkg/installed/x64-windows/lib -lhiredis | |
| CXXFLAGS = -std=c++17 $(CXXFLAG_1) $(CXXFLAG_LIB_1) | |
| all: main.exe | |
| main.exe: main.o | |
| $(CXX) $(CXXFLAGS) main.o -o main.exe | |
| main.o: main.cpp | |
| $(CXX) $(CXXFLAGS) -c main.cpp | |
| clean: | |
| del *.o *.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment