【Redis】安装redis-plus-plus

embedded/2024/10/18 8:13:45/

目录

redis-plus-plus-toc" style="margin-left:0px;">安装redis-plus-plus

redis-toc" style="margin-left:40px;">安装hiredis

redis-plus-plus%E6%9C%AC%E4%BD%93-toc" style="margin-left:40px;">安装redis-plus-plus本体

具体步骤

​编辑编写一个hello程序


redis-plus-plus">安装redis-plus-plus

C++操作redis的第三方库有很多,咱们此处使用redis-plus-plus,安装链接如下:

GitHub - sewenew/redis-plus-plus: Redis client written in C++icon-default.png?t=O83Ahttps://github.com/sewenew/redis-plus-plus

redis">安装hiredis

但在安装redis-plus-plus之前,我们需要先安装hiredis,因为redis-plus-plus依赖了hiredis(C语言的redis客户端库),如下是hiredis源码安装:

git clone https://github.com/redis/hiredis.git

cd hiredis

make

make install

在Linux中可以使用包管理其直接安装 

Ubuntu

apt install libhiredis-dev

Centos 

yum install hiredis-devel.x86_64 

redis-plus-plus%E6%9C%AC%E4%BD%93">安装redis-plus-plus本体

redis-plus-plus本体,只能编译安装,使用编译安装ubuntu会比centos方便很多

Centos

Centos自带的cmake版本较低,需要先安装cmake3

yum install cmake3

然后使用cmake3构建项目

cd redis-plus-plus

mkdir build  //创建一个build目录是为了让编译生成的临时文件都放到这里,避免污染源代码目录

cd build

cmake3 ..

make

make install

构建成功后,会在/usr/local/include/中多出sw目录,并且内部包含redis-plus-plus一系列头文件,会在/usr/local/lib/中多出一系列libredis库文件

Ubuntu

安装cmake

apt install cmake

具体步骤

git clone https://github.com/sewenew/redis-plus-plus.git
cd redis-plus-plus

mkdir build

cd build

cmake .. //生成makefile,此处..指向CMakeLists.txt文件所在的目录

make

make install //把刚才的库拷贝到系统目录

redis-plus-plus的头文件路径

root@VM-24-2-ubuntu:~# cd /usr/local/include/sw/redis++/

 redis++.h 

动态库文件路径

/usr/local/lib/libredis++.a

端口号6379是redis服务器默认的端口号,可以通过netstat命令查看

编写一个hello程序

hello.cc

#include <sw/redis++/redis++.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <iostream>
using std::cout;
using std::endl;
using std::vector;
using std::string;
using std::unordered_map;int main()
{//创建一个redis对象,需要在构造函数中指定redis服务器的地址和端口,这里因为redis的服务器和客户端在一台机器上//使用localhost,6379sw::redis::Redis redis("tcp://127.0.0.1:6379");//调用ping方法,让客户端给服务器发了一个PING,然后服务器就会返回一个PONG,就通过返回值获取到string results=redis.ping();std::cout<<results<<std::endl;return 0;
}

使用Malefile编译程序

编译程序的时候,需要引入库文件

  1. redis++自己的静态库
  2. hiredis的静态库
  3. 线程库 

查找对应库的路径方法如下:

root@VM-24-2-ubuntu:~# find /usr/ -name libhiredis*
/usr/lib/x86_64-linux-gnu/libhiredis.a
/usr/lib/x86_64-linux-gnu/libhiredis.so
/usr/lib/x86_64-linux-gnu/libhiredis.so.0.14
/usr/share/doc/libhiredis0.14
/usr/share/doc/libhiredis-dev

Makefile:

hello::hello.ccg++ -std=c++17 -o $@ $^ /usr/local/lib/libredis++.a /usr/lib/x86_64-linux-gnu/libhiredis.a -pthread.PHONY:clean
clean:rm hello

结果如下:


http://www.ppmy.cn/embedded/120485.html

相关文章

MySQL安装与环境配置(Windows系统 MySQL8.0.39)

目录 MySQL8.0.39工具下载安装开启方式可视化开启命令方式开启 环境配置 MySQL8.0.39 工具 系统&#xff1a;Windows 11 参考视频&#xff1a; 黑马程序员 MySQL数据库入门到精通&#xff0c;从mysql安装到mysql高级、mysql优化全囊括 P3 https://www.bilibili.com/video/BV1…

MongoDB 工具包安装(mongodb-database-tools)

首先到官网下载工具包&#xff0c;进入下面页面&#xff0c;复制连接地址&#xff0c;使用wget下载 cd /usr/local/mongodb5.0.14/wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.6.1.tgz 安装 tar -zxvf mongodb-database-tools-rhel70-…

基于微信小程序的宿舍报修系统的设计与实现(lw+演示+源码+运行)

摘 要 互联网发展至今&#xff0c;无论是其理论还是技术都已经成熟&#xff0c;而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播&#xff0c;搭配信息管理工具可以很好地为人们提供服务。针对成果信息管理混乱&#xff0c;出错率高&#xff0c;信息安全性差&am…

打点 - 泛微 E-Cology WorkflowServiceXml

请求路径 /services%20/WorkflowServiceXml显示如下&#xff0c;漏洞可能存在 利用&#xff1a; 根据提示在 CMD 处输入 Memshell 注入内存马&#xff0c;并点击执行&#xff0c;成功注入 冰蝎配置&#xff0c;输入内存马地址 成功连接 命令执行

依赖倒置原则(学习笔记)

抽象不应该依赖细节&#xff0c;细节应该依赖抽象。简单的说就是要求对抽象进行编程&#xff0c;不要对实现进行编程&#xff0c;这样就降低了客户与实现模块间的耦合。 依赖倒转原则是基于这样的设计理念&#xff1a;相对于细节的多变性&#xff0c;抽象的东西要稳定的多。 以…

pysim-1

pySim 简介 pySim 是一个 Python 实现的软件套件&#xff0c;旨在帮助您管理蜂窝网络的用户身份卡&#xff0c;即 SIM 卡。许多 Osmocom&#xff08;开源移动通信&#xff09;项目都与运行私有/定制蜂窝网络有关&#xff0c;为这些网络提供 SIM 卡是运营这些网络的常见要求。要…

C++学习笔记----8、掌握类与对象(二)---- 成员函数的更多知识(1)

c提供了成员函数的更多选择&#xff0c;我们来进行更多解密 1、静态成员函数 成员函数&#xff0c;与数据成员一样&#xff0c;有时候整体应用于类&#xff0c;而不是每个对象。可以写与数据成员一样的静态成员函数。举个例子&#xff0c;考虑上一章的SpreadsheetCell类。有两…

人工智能知识体系

文章目录 一、数学基础二、编程技能三、机器学习四、自然语言处理五、计算机视觉六、数据管理和工程 一、数学基础 线性代数&#xff1a;掌握向量、矩阵、线性变换等概念&#xff0c;理解矩阵运算在机器学习中的应用。概率论与统计学&#xff1a;了解概率分布、期望、方差等概…