7.1 Redis源码下载与编译

  Redis源码下载与编译在前面已经说过了,同学们可以去第04课:GDB常用命令详解(上)学习。

  编译成功后,会在src目录下生成多个可执行程序,其中redis-server和redis-cli使我们即将调试的程序,进入src目录,使用GDB启动redis-server这个程序。

wzq@wzq-PC:~/Desktop/redis-5.0.3/src$ gdb redis-server
GNU gdb (Debian 7.12-6+b2) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from redis-server...done.
(gdb) r
Starting program: /home/wzq/Desktop/redis-5.0.3/src/redis-server
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
8073:C 14 Jan 2019 10:30:29.039 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8073:C 14 Jan 2019 10:30:29.039 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=8073, just started
8073:C 14 Jan 2019 10:30:29.040 # Warning: no config file specified, using the default config. In order to specify a config file use /home/wzq/Desktop/redis-5.0.3/src/redis-server /path/to/redis.conf
8073:M 14 Jan 2019 10:30:29.040 * Increased maximum number of open files to 10032 (it was originally set to 1024).
[New Thread 0x7ffff67ff700 (LWP 8077)]
[New Thread 0x7ffff5ffe700 (LWP 8078)]
[New Thread 0x7ffff57fd700 (LWP 8079)]
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8073
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' 8073:M 14 Jan 2019 10:30:29.042 # Server initialized
8073:M 14 Jan 2019 10:30:29.042 # 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.
8073:M 14 Jan 2019 10:30:29.042 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
8073:M 14 Jan 2019 10:30:29.042 * Ready to accept connections

  以上是redis-server启动成功后的画面。

  我们再开一个session,再次进入Redis源码所在的src目录,然后使用GDB启动Redis客户端redis-cli:

wzq@wzq-PC:~/Desktop/redis-5.0.3/src$ gdb redis-cli
GNU gdb (Debian 7.12-6+b2) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from redis-cli...done.
(gdb) r
Starting program: /home/wzq/Desktop/redis-5.0.3/src/redis-cli
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
127.0.0.1:6379>

  以上是redis-cli启动成功后的画面。

7.2 通信示例

  本课程的学习目的是研究Redis的网络通信模块,为了说明问题方便,我们使用一个简单的通信实例,即通过redis-cli产生一个可以为“hello”,值为“world”的key-value数据,然后得到redis-server的响应。

127.0.0.1:6379> set hello world
OK
127.0.0.1:6379>

  读者需要注意的是,我这里说是一个“简单”的实例,其实并不简单。有两个原因:

  -我们是在redis-cli(Redis客户端)输入的命令,这个命令经redis-cli处理后封装成网络通信包,通过客户端的网络通信模块发给redis-server,然后redis-server网络通信模块收到后解析出命令,执行命令后得到结果再封装成相关的网络数据包,返回给redis-cli。这个过程中涉及到两端的网络通信模块使我们研究和学习的重点。

  -redis-server基本的数据类型都是可以通过类似的命令产生,因此这个例子是一个典型的研究redis的典范。

7.3小结

  这节课介绍了我们利用调试Redis源码来学习GDB的一些准备工作和实例代码,有兴趣的读者可以根据本节课中介绍的内容准备一些学习材料,以备后面的进一步学习,从下一课开始我们正式利用GDB来调试Redis。

  

第07课:【实战】调试Redis准备工作的更多相关文章

  1. 第07课:GDB 常用命令详解(下)

    本课的核心内容: disassemble 命令 set args 和 show args 命令 tbreak 命令 watch 命令 display 命令 disassemble 命令 当进行一些高级 ...

  2. net core 实战之 redis 负载均衡和"高可用"实现

    net core 实战之 redis 负载均衡和"高可用"实现 1.概述 分布式系统缓存已经变得不可或缺,本文主要阐述如何实现redis主从复制集群的负载均衡,以及 redis的& ...

  3. Redis实战之Redis + Jedis

    用Memcached,对于缓存对象大小有要求,单个对象不得大于1MB,且不支持复杂的数据类型,譬如SET 等.基于这些限制,有必要考虑Redis! 相关链接: Redis实战 Redis实战之Redi ...

  4. 手把手教你写电商爬虫-第三课 实战尚妆网AJAX请求处理和内容提取

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 看完两篇,相信大家已经从开始的 ...

  5. Redis实战之Redis + Jedis[转]

    http://blog.csdn.net/it_man/article/details/9730605 2013-08-03 11:01 1786人阅读 评论(0) 收藏 举报   目录(?)[-] ...

  6. 像调试java一样来调试Redis lua

    高并发的系统中,redis的使用是非常频繁的,而lua脚本则更是锦上添花.因为lua脚本本身执行的时候是一个事务性的操作,不会掺杂其他外部的命令,所以很多关键的系统节点都会用redis+lua来实现一 ...

  7. 第七课 GDB调试 (下)

    1序言: 通过前面一节第六课 GDB调试 (下)文章,可以掌握理解了gdb调试:怎么启动.运行,打断点.查看变量.甚至改变变量等的知识,今天来大概讲解下调试bug的类型. 2知识点: 2.1 就像之前 ...

  8. html5--6-68 实战前的准备工作:了解HTML5大纲算法

    html5--6-68 实战前的准备工作:了解HTML5大纲算法 学习要点 了解HTML5大纲算法 在html5中有一个很重要的概念,叫做HTML5大纲算法(HTML5 Outliner),它的用途为 ...

  9. kubebuilder实战之一:准备工作kubebuilder实战之一:准备工作

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

随机推荐

  1. php register_shutdown_function响应error 配合error_get_last 捕获错误

    转自: http://blog.csdn.net/a757291228/article/details/62231125 //一个函数,用来响应 register_shutdown_function ...

  2. ubuntu install themes && use it

    one step: I am going to show you the installation of a theme with Numix theme and Unity Tweak Tool. ...

  3. Django下orm学习 一对多

    概念说明 ORM:关系对象映射的全称是 Object Relational Mapping, 简称ORM SQLAlchemy: 是Python编程语言下的一款ORM框架,该框架建立在数据库API之上 ...

  4. ASP.NET Core 入门笔记2,建立项目

    1.建立项目 2.项目结构 1.项目结构说明 根目录/文件 说明 .vscode目录 VS Code项目配置目录,相当于.vs..idea文件夹 bin目录 编译输出目录 obj目录 编译配置与中间目 ...

  5. Python知识点面试题

    一. DB类 索引相关: 1. mysql索引种类 2. 什么是覆盖索引? MySQL目前主要有以下几种索引类型:1.普通索引2.唯一索引3.主键索引4.组合索引:遵循最左前缀规则5.全文索引 其他: ...

  6. 【Python开发】Lambda表达式使用

    lambda只是一个表达式,函数体比def简单很多. lambda的主体是一个表达式,而不是一个代码块.仅仅能在lambda表达式中封装有限的逻辑进去. lambda表达式是起到一个函数速写的作用.允 ...

  7. linux下安转nodejs

    转载自:https://www.cnblogs.com/zhuawang/p/7617176.html 在Linux系统安装Nodejs 最简单步骤 1.去官网下载和自己系统匹配的文件: 英文网址:h ...

  8. (5.4)mysql高可用系列——MySQL异步复制(实践)

    关键词:mysql复制,mysql异步复制,mysql传统异步复制 [1]实验环境 操作系统:CentOS linux 7.5 数据库版本:5.7.24 数据库架构:主从复制,主库用于生产,从库用于数 ...

  9. [转帖]docker清理日志

    docker清理日志 2017年05月03日 10:37:27 不想当码农的程序员 阅读数 12827    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn. ...

  10. Centos8 重启网卡方法

    问题情况: 1.虚机centos8 修改为静态ip后,由于网卡网段变更,无法上网 2.最小化安装,没有ifconfig 3.firewalld,selinux关闭 4.ping 不通物理机 根本原因: ...