qredisclient
command.h
1 #pragma once
2 #include <functional>
3 #include <QString>
4 #include <QByteArray>
5 #include <QList>
6 #include <QObject>
7 
8 namespace RedisClient {
9 
10 class Response;
11 
18 class Command
19 {
20 public:
21  typedef std::function<void(Response, QString)> Callback;
22 
23 public:
27  Command();
28 
34  Command(const QList<QByteArray>& cmd, int db = -1);
35 
43  Command(const QList<QByteArray>& cmd, QObject * context, Callback callback, int db = -1);
44 
48  virtual ~Command();
49 
55  Command &append(const QByteArray& part);
56 
61  QByteArray getByteRepresentation() const;
62 
67  QByteArray getRawString(int limit=200) const;
68 
73  QList<QByteArray> getSplitedRepresentattion() const;
74 
80  QString getPartAsString(int i);
81 
86  int getDbIndex() const;
87 
92  bool hasDbIndex() const;
93 
98  QObject* getOwner() const;
99 
105  void setCallBack(QObject* context, Callback callback);
106 
111  Callback getCallBack() const;
112 
117  bool hasCallback() const;
118 
124 
129  bool isHiPriorityCommand() const;
130 
135  bool isValid() const;
136  bool isEmpty() const;
137 
138  /*
139  * Command type checks
140  */
141  bool isScanCommand() const;
142  bool isSelectCommand() const;
143  bool isSubscriptionCommand() const;
144  bool isUnSubscriptionCommand() const;
145 
146 public:
152  static QList<QByteArray> splitCommandString(const QString &);
153 
154 protected:
155  QObject * m_owner;
156  QList<QByteArray> m_commandWithArguments;
157  int m_dbIndex;
158  bool m_hiPriorityCommand;
159  Callback m_callback;
160 };
161 }
Definition: command.h:8
The Command class.
Definition: command.h:18
QList< QByteArray > getSplitedRepresentattion() const
Get source command as list of args.
Definition: command.cpp:155
bool isHiPriorityCommand() const
isHiPriorityCommand
Definition: command.cpp:133
QByteArray getRawString(int limit=200) const
Get source command as single string.
Definition: command.cpp:148
Command & append(const QByteArray &part)
Append additional arg/part to command ("SET 1" + "2")
Definition: command.cpp:30
QString getPartAsString(int i)
Get specific argument/part of the command.
Definition: command.cpp:160
QByteArray getByteRepresentation() const
Get command in RESP format.
Definition: command.cpp:173
void markAsHiPriorityCommand()
Mark this command as High Priority command. Command will be added to the begining of the Connection q...
Definition: command.cpp:189
virtual ~Command()
~Command
Definition: command.cpp:26
int getDbIndex() const
Get database index where this command should be executed.
Definition: command.cpp:138
Callback getCallBack() const
getCallBack
Definition: command.cpp:97
bool hasDbIndex() const
hasDbIndex
Definition: command.cpp:102
bool hasCallback() const
hasCallback
Definition: command.cpp:86
static QList< QByteArray > splitCommandString(const QString &)
Parse command from raw string. Useful for CLI clients.
Definition: command.cpp:36
Command()
Constructs empty command.
Definition: command.cpp:7
QObject * getOwner() const
Get callback context.
Definition: command.cpp:143
bool isValid() const
isValid
Definition: command.cpp:194
void setCallBack(QObject *context, Callback callback)
Set context and callback.
Definition: command.cpp:91