C++接入redis
项目地址
# 1、编译安装 hiredis 项目
wget https://github.com/redis/hiredis/archive/refs/tags/v1.2.0.tar.gz
tar -xvf v1.2.0.tar.gz
mv hiredis-1.2.0 hiredis && rm -rf v1.2.0.tar.gz && cd hiredis
# 编译安装到 build 目录下
make && make PREFIX=./build install
# 2、编译安装 redis-plus-plus 项目
wget https://github.com/sewenew/redis-plus-plus/archive/refs/tags/1.3.10.tar.gz
tar -xvf redis-plus-plus-1.3.10.tar.gz && rm redis-plus-plus-1.3.10.tar.gz
cd redis-plus-plus-1.3.10 && mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH=hiredis的静/动态库所在的目录 -DCMAKE_INSTALL_PREFIX=redis-plus-plus的安装目录 ..
# cmake -DCMAKE_PREFIX_PATH=hiredis的静/动态库所在的目录 -DCMAKE_INSTALL_PREFIX=. ..
make && make install
使用
#include <iostream>
#include "sw/redis++/redis++.h"
int main(int argc, char const *argv[]) {
sw::redis::ConnectionOptions option{};
option.host = "0.0.0.0";
option.port = 6379;
option.password = "jtzlredis";
sw::redis::Redis redis = sw::redis::Redis(option);
std::cout << redis.ping() << std::endl;
// 其它命令
return 0;
}
特别的编译选项
- -lredis++
- -lhiredis
- -std=c++17
- -lpthread
- -Wall
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2022-10-16 vue框架不同构建版本的理解