Use vscode to read and step through redis

Table of contents

1 Introduction to Redis

2 configuration steps

3 function call chain


1 Introduction to Redis

Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.

Redis and other key-value cache products have the following three characteristics:

  • Redis supports data persistence, which can keep the data in memory on the disk, and can be loaded again for use when restarting.
  • Redis not only supports simple key-value type data, but also provides storage of data structures such as list, set, zset, and hash.
  • Redis supports data backup, that is, data backup in master-slave mode.

Redis official website: Redis Chinese website

git repository: https://github.com/redis/redis.git

2 configuration steps

Install vscode on the Mac computer, download the necessary plug-ins, start the linux virtual machine, connect to the git clone redis software on the linux virtual machine with the ssh command, and then use vscode to open the redis folder.

Create a new .vscode folder in the redis folder, and create new tasks.json and launch.json

launch.json is as follows

{
    // 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 is as follows

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build", 
            "type": "shell", 
            "command": "make",
            "args": [
                "CFLAGS=\"-g -O0\""
            ]
        }
    ]
} 

Then you can debug, and you can single-step debug by adding a breakpoint to the main function in src/server.c.

Attached redis command:

Use the redis-server command to start the server program, and then start redis-cli in the newly created command window to use it.

3 function call chain

We can use single-step debugging to trace the redis function call chain. If we want to trace the call chain of the set command, we can set a breakpoint in the setCommand function, and then enter set name 1000 in redis-cli. In this way, it can be stopped in setCommand.

 In this way, you can clearly see the function call chain of the entire set command.

×

Guess you like

Origin blog.csdn.net/daida2008/article/details/124553506