目录
1 Redis简介
Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。
Redis 与其他 key - value 缓存产品有以下三个特点:
- Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。
- Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
- Redis支持数据的备份,即master-slave模式的数据备份。
redis官网:Redis中文网
git仓库:https://github.com/redis/redis.git
2 配置步骤
在Mac电脑上安装好vscode,下载必要的插件,开启linux虚拟机,ssh命令连接到linux虚拟机上git clone redis软件,然后使用vscode打开redis文件夹。
在redis文件夹中新建.vscode文件夹,并新建tasks.json和launch.json
launch.json如下
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "redis",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/redis-server",
"args": [
"redis.conf"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
tasks.json如下
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"args": [
"CFLAGS=\"-g -O0\""
]
}
]
}
接着便可以进行调试了,在src/server.c中的main函数增加断点就可以单步调试了。
附redis命令:
使用redis-server命令启动服务器程序,然后在新建的命令窗口中启动redis-cli便可以使用了。
3 函数调用链
我们可以使用单步调试来追踪redis函数调用链,如果我们想追踪set命令的调用链,可以在setCommand函数中打一个断点,然后在redis-cli中输入set name 1000。这样就可以在setCommand中端住了。
这样就可以很清晰的看到整个set命令的函数调用链。
×