承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601

Redis源码环境构建进程详解

管理员 2023-08-02 08:16:55 互联网圈 0 ℃ 0 评论 5768字 收藏

Redis源码环境构建

​ 近日,蒋德钧新上了一门Redis源码剖析的课程,应好友沈架构师的约请,又重拾起了Redis源码学习。不过作为正经的JAVA工程师,大概在大学毕业后再也没写过C语言的源码了(或者看过一些的)。搭建一个Redis浏览环境我都好意思写一篇博客记录一下了。

​ 不过,不是在windows环境下构建了,是在deepin系统下进行的构建,或许windows用户可以出门右拐了。本次搭建环境主要参考以下两篇windows搭建环境的博客:

https://juejin.cn/post/6924329599568445447

#

C语言环境

​ 大学时期,用过vc 6.0、 vs 2012等软件写过C++语言。也在linux上编译过c语言代码。linux环境下,自带有gcc,make工具。而在windows环境下,可以选择MinGW、cygwin提供编译环境,make、cmake可以用来履行makefile文件。

​ 不过呢,我用的是Linux系统嘛,也就没有C语言环境搭建的进程了。。。

C语言IDE

​ VC 6.0这样的老古董应当是只合适语言初学者来强行记忆自己的语法了吧。vs 2012安装包很大,在linux环境上有无安装包还两说。这里选择的事jetbrains家族下的Clion。官网有提供安装包,固然,像Deepin提供了利用市场,也能够直接一键安装。

​ 第一次启动时,CLION就会让你选择C语言环境的履行器,固然它默许会扫描到,一路确认就行。

克隆源码

​ 打开Clion,选择 “get from version control”,直接键入URL:https://github.com/redis/redis.git 进行clone。

配置工程

makefile

在工程根目录,输入命令make对makefile进行履行:

wanglh@dark:~/CLionProjects/redis$ make
cd src && make all
make[1]: 进入目录“/home/wanglh/CLionProjects/redis/src”
    CC Makefile.dep
    CC adlist.o

固然,在工程里点击Makefile 文件,Clion也会提示你安装Makefile的插件 Makefile Support。 然后点击文件右边绿色的履行键便可。

以后,就会在/src目录中生成许多.o文件。

配置DEBUG命令

在CLion右上角的窗口,点击Edit Run/Debug Configurations 进行以下配置(选择框进行选择便可):

在这里插入图片描述

Target选择redis-serverExecuteable选择redis-server

履行DEBUG

点击DEBUG按钮后,就会在DEBUG的CONSOLE出输出:

/home/wanglh/CLionProjects/redis/src/redis-server
19707:C 27 Jul 2021 23:24:49.989 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19707:C 27 Jul 2021 23:24:49.989 # Redis version=255.255.255, bits=64, commit=17511df5, modified=0, pid=19707, just started
19707:C 27 Jul 2021 23:24:49.989 # Warning: no config file specified, using the default config. In order to specify a config file use /home/wanglh/CLionProjects/redis/src/redis-server /path/to/redis.conf
19707:M 27 Jul 2021 23:24:49.990 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 255.255.255 (17511df5/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 19707
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

19707:M 27 Jul 2021 23:24:49.990 # Server initialized
19707:M 27 Jul 2021 23:24:49.990 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
19707:M 27 Jul 2021 23:24:49.992 * Loading RDB produced by version 255.255.255
19707:M 27 Jul 2021 23:24:49.992 * RDB age 14593 seconds
19707:M 27 Jul 2021 23:24:49.992 * RDB memory usage when created 0.77 Mb
19707:M 27 Jul 2021 23:24:49.992 * DB loaded from disk: 0.000 seconds
19707:M 27 Jul 2021 23:24:49.992 * Ready to accept connections

这样就表示启动成功了,我们也能够用redis客户端,redis-cli进行验证:

wanglh@dark:~/CLionProjects/redis/src$ pwd
/home/wanglh/CLionProjects/redis/src
wanglh@dark:~/CLionProjects/redis/src$ ls -l redis-cli
-rwxr-xr-x 1 wanglh wanglh 6689040 7月  27 23:15 redis-cli
wanglh@dark:~/CLionProjects/redis/src$ redis-cli 
127.0.0.1:6379> set a nn
OK
127.0.0.1:6379> get a
"nn"
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

到此这篇关于Redis源码环境构建的文章就介绍到这了,更多相关Redis源码环境内容请搜索之前的文章或继续浏览下面的相关文章希望大家以后多多支持!

文章来源:丸子建站

文章标题:Redis源码环境构建进程详解

https://www.wanzijz.com/view/68580.html

X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信