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. Tensorflow 从文件中载入训练数据

    本节包含: 用纯文本文件准备训练数据 加载文件中的训练数据 一.用纯文本文件准备训练数据 1.数据的数字化 比如,“是” —— “1”,“否” —— “0” “优”,“中”,“差” —— 1 2 3  ...

  2. selenium三种断言以及异常类型

    elenium提供了三种模式的断言:assert .verify.waitfor 1)Assert(断言) 失败时,该测试将终止. 2)Verify(验证) 失败时,该测试将继续执行,并将错误记入日志 ...

  3. 【Linux开发】linux设备驱动归纳总结(九):1.platform总线的设备和驱动

    linux设备驱动归纳总结(九):1.platform总线的设备和驱动 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  4. 使用PowerShell 自动安装VC++补丁

    执行环境:Windows Server 2012 R2 VC++下载链接 这里有个问题,虽说可以静默安装,但是未对当前系统检测是否已安装vc++补丁,望大佬指点 # author:lttr <w ...

  5. Oracle密码过期(the password has expired)

    1.进入sqlplus模式--sqlplus / as sysdba; 2.查看用户密码的有效期设置(一般默认的配置文件是DEFAULT) SELECT * FROM dba_profiles WHE ...

  6. jmeter---导出文件接口测试

    在http请求下添加后置处理器--BeanShell PostProcessor,保存文件到本地 运行脚本,查看本地文件.

  7. Spring 自定义注解,结合AOP,配置简单日志注解 (转)

    java在jdk1.5中引入了注解,spring框架也正好把java注解发挥得淋漓尽致. 下面会讲解Spring中自定义注解的简单流程,其中会涉及到spring框架中的AOP(面向切面编程)相关概念. ...

  8. 分布式锁的几种实现方法:redis实现分布式锁

    使用失效的方式实现分布式锁(推荐) import redis.clients.jedis.Jedis; /** * 使用redis实现分布式锁(推荐) * */ public class JedLoc ...

  9. WordPress网站搬家数据迁移完整教程

    用本地环境搭建好的WordPress网站在做好之后如何从本地迁移到网络空间或者网络服务器上呢? 首先请确认你在本地建站的时候只做了themes里面的模版文件,如果只是自己改了下模版,那么网站在搬到服务 ...

  10. 大数据学习(1)-shell脚本注意事项

    1.变量=值 (例如STR=abc)  不用加引号,但此时空格不再是空格字符,特殊字符可用于转义 2.等号两侧不能有空格 3.变量名称一般习惯为大写 4.双引号和单引号有区别,双引号仅将空格脱意,单引 ...