第07课:【实战】调试Redis准备工作
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。
?
?
轉載于:https://www.cnblogs.com/wzqstudy/p/10265722.html
總結
以上是生活随笔為你收集整理的第07课:【实战】调试Redis准备工作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: B站、豆瓣都崩了,还有啥技术能靠得住?
- 下一篇: faker.js 登 GitHub 趋势