-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add command docs impl #1642
add command docs impl #1642
Changes from all commits
33d2689
c0fa8f3
5d248b3
60c7d4a
3196b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
#ifndef PIKA_COMMAND_H_ | ||
#define PIKA_COMMAND_H_ | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <utility> | ||
#include <memory> | ||
|
||
#include "net/include/net_conn.h" | ||
#include "net/include/redis_conn.h" | ||
|
@@ -47,8 +48,9 @@ const std::string kCmdNamePKPatternMatchDel = "pkpatternmatchdel"; | |
const std::string kCmdDummy = "dummy"; | ||
const std::string kCmdNameQuit = "quit"; | ||
const std::string kCmdNameHello = "hello"; | ||
const std::string kCmdNameCommand = "command"; | ||
|
||
//Migrate slot | ||
// Migrate slot | ||
const std::string kCmdNameSlotsMgrtSlot = "slotsmgrtslot"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the code patch you provided, here are a few observations and suggestions:
Remember that this review is based solely on the provided code patch, and there might be other aspects of your software that need attention but aren't visible here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch you provided appears to be an addition of a new constant string variable called
Remember, code reviews benefit from multiple perspectives, so it's always valuable to have your peers or experienced developers review your code as well. |
||
const std::string kCmdNameSlotsMgrtTagSlot = "slotsmgrttagslot"; | ||
const std::string kCmdNameSlotsMgrtOne = "slotsmgrtone"; | ||
|
@@ -410,15 +412,13 @@ class Cmd : public std::enable_shared_from_this<Cmd> { | |
}; | ||
struct ProcessArg { | ||
ProcessArg() = default; | ||
ProcessArg(std::shared_ptr<Slot> _slot, std::shared_ptr<SyncMasterSlot> _sync_slot, | ||
HintKeys _hint_keys) | ||
ProcessArg(std::shared_ptr<Slot> _slot, std::shared_ptr<SyncMasterSlot> _sync_slot, HintKeys _hint_keys) | ||
: slot(std::move(_slot)), sync_slot(std::move(_sync_slot)), hint_keys(std::move(_hint_keys)) {} | ||
std::shared_ptr<Slot> slot; | ||
std::shared_ptr<SyncMasterSlot> sync_slot; | ||
HintKeys hint_keys; | ||
}; | ||
Cmd(std::string name, int arity, uint16_t flag) | ||
: name_(std::move(name)), arity_(arity), flag_(flag) {} | ||
Cmd(std::string name, int arity, uint16_t flag) : name_(std::move(name)), arity_(arity), flag_(flag) {} | ||
virtual ~Cmd() = default; | ||
|
||
virtual std::vector<std::string> current_key() const; | ||
|
@@ -463,6 +463,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> { | |
void SetStage(CmdStage stage); | ||
|
||
virtual void DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot); | ||
|
||
protected: | ||
// enable copy, used default copy | ||
// Cmd(const Cmd&); | ||
|
@@ -478,7 +479,6 @@ class Cmd : public std::enable_shared_from_this<Cmd> { | |
int arity_ = -2; | ||
uint16_t flag_ = 0; | ||
|
||
|
||
protected: | ||
CmdRes res_; | ||
PikaCmdArgsType argv_; | ||
|
@@ -496,7 +496,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> { | |
Cmd& operator=(const Cmd&); | ||
}; | ||
|
||
using CmdTable = std::unordered_map<std::string, std::unique_ptr<Cmd>>; | ||
using CmdTable = std::unordered_map<std::string, std::unique_ptr<Cmd>>; | ||
|
||
// Method for Cmd Table | ||
void InitCmdTable(CmdTable* cmd_table); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code patch appears to be a section of code related to command handling in a project. Here are some suggestions for improvement:
These suggestions aim to enhance the code quality, but ultimately, the specific improvements depend on the context and requirements of your project. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the code patch seems to introduce a few changes related to the
PikaCmdTableManager
class. Here's an overview of the changes:The destructor for
PikaCmdTableManager
has been modified from a virtual non-default destructor (virtual ~PikaCmdTableManager(){}
) to a default virtual destructor (virtual ~PikaCmdTableManager() = default;
). This change utilizes the default destructor implementation provided by the compiler.A new member function
bool CmdExist(const std::string& cmd) const;
has been added to the class. This function is used to check if a command exists.The existing member function
std::shared_ptr<Cmd> NewCommand(const std::string& opt);
remains without any apparent changes.Based on this information, here are some observations and suggestions for improvement:
Since the destructor was changed to a default virtual destructor, you should ensure that there are no explicit calls to delete objects of
PikaCmdTableManager
through a pointer to the base class. If you don't need polymorphic behavior or subclasses derived fromPikaCmdTableManager
, making the destructor non-virtual may be more appropriate.It's difficult to provide detailed feedback or identify potential issues without being able to see the full code context (e.g., definition and usage of
Cmd
class). Ensure that the class's implementation aligns with its intended functionality.Consider adding proper error handling and validation mechanisms to
GetCmd
andDistributeKey
member functions to handle exceptional cases or invalid inputs. It's important to ensure that these functions behave predictably and are resilient to unexpected scenarios.Verify that the addition of
CmdExist
doesn't introduce unnecessary overhead or redundancy. Ensure that it provides value and is used appropriately in your codebase.Remember that a thorough code review would require an understanding of the complete codebase, the surrounding context, and the requirements it serves. These suggestions are based solely on the information provided in the code patch you provided.