When learning to use Redis, downloading the Redis source code from GitHub is a good choice. After downloading, by creating two files, task.json and launch.json, you can easily compile, run and debug Redis locally. Through these steps, you can better understand the internal implementation of Redis and get started using Redis quickly.
First, download the Redis source code from GitHub:
Redis GitHub link: https://github.com/redis/redis
Second, create these two files in the root directory:
create task.json
file
{
"version": "2.0.0",
"tasks": [
{
"label": "Clean",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"problemMatcher": []
},
{
"label": "Compile",
"type": "shell",
"command": "make",
"problemMatcher": []
},
{
"label": "Build",
"dependsOn": [
"Clean",
"Compile"
]
},
{
"label": "writeRedisPID",
"type": "shell",
"command": "ps -ef | grep 'redis-server' | grep -v grep | awk '{print $2}' > /tmp/redis.pid"
}
]
}
create launch.json
file
{
"version": "0.2.0",
"configurations": [
{
"name": "Redis Server Run",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/redis-server",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "Build"
},
{
"name": "Redis Server Attach",
"type": "cppdbg",
"request": "attach",
"processId": "${input:redisPID}",
"program": "${workspaceFolder}/src/redis-server",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "writeRedisPID",
"subProcess": true,
"justMyCode": true,
"redirectOutput": true,
}
],
"inputs": [
{
"id": "redisPID",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "/tmp/redis.pid"
}
}
]
}
Press F5
to run, you can see that Redis runs in the form of Debugger: