2019-07-28 10:31:56 +08:00
|
|
|
#pragma once
|
2016-04-12 20:11:15 +08:00
|
|
|
|
2016-04-15 14:51:45 +08:00
|
|
|
struct REDIS_CMD
|
|
|
|
{
|
|
|
|
acl::string cmd;
|
2016-08-27 18:34:02 +08:00
|
|
|
acl::string broadcast;
|
2016-04-16 12:25:41 +08:00
|
|
|
acl::string perm;
|
2016-04-15 14:51:45 +08:00
|
|
|
};
|
|
|
|
|
2016-04-12 20:11:15 +08:00
|
|
|
class redis_commands
|
|
|
|
{
|
|
|
|
public:
|
2016-04-15 14:51:45 +08:00
|
|
|
redis_commands(const char* addr, const char* passwd, int conn_timeout,
|
|
|
|
int rw_timeout, bool prefer_master, const char* cmds_file);
|
2016-04-12 20:11:15 +08:00
|
|
|
~redis_commands(void);
|
|
|
|
|
|
|
|
void run(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
acl::string addr_;
|
|
|
|
acl::string passwd_;
|
|
|
|
int conn_timeout_;
|
|
|
|
int rw_timeout_;
|
|
|
|
bool prefer_master_;
|
|
|
|
acl::redis_client_cluster* conns_;
|
2023-04-03 22:04:13 +08:00
|
|
|
acl::redis_client_pipeline* pipeline_;
|
2016-04-15 14:51:45 +08:00
|
|
|
std::map<acl::string, REDIS_CMD> redis_cmds_;
|
2016-04-16 12:25:41 +08:00
|
|
|
acl::string all_cmds_perm_;
|
2016-04-15 14:51:45 +08:00
|
|
|
|
|
|
|
void init(const char* cmds_file);
|
|
|
|
void set_commands(void);
|
|
|
|
void load_commands(acl::istream& in);
|
|
|
|
void add_cmdline(acl::string& line, size_t i);
|
|
|
|
void show_commands(void);
|
|
|
|
bool check(const char* command);
|
2016-04-12 20:11:15 +08:00
|
|
|
|
2019-06-17 10:51:28 +08:00
|
|
|
bool parse(acl::string& line, std::vector<acl::string>& out);
|
2016-04-12 20:11:15 +08:00
|
|
|
void set_addr(const char* in, acl::string& out);
|
|
|
|
void getline(acl::string& buf, const char* prompt = NULL);
|
2019-07-08 11:49:19 +08:00
|
|
|
void create_cluster(void);
|
2016-04-12 20:11:15 +08:00
|
|
|
void help(void);
|
|
|
|
void set_server(const std::vector<acl::string>& tokens);
|
|
|
|
void show_nodes(void);
|
|
|
|
void show_date(void);
|
|
|
|
|
|
|
|
void get_keys(const std::vector<acl::string>& tokens);
|
|
|
|
int get_keys(const char* addr, const char* pattern, int max);
|
|
|
|
|
2016-04-30 11:49:41 +08:00
|
|
|
void scan_keys(const std::vector<acl::string>& tokens);
|
|
|
|
int scan(const char* addr, const char* pattern, size_t display_count);
|
|
|
|
|
2016-04-12 20:11:15 +08:00
|
|
|
void getn(const std::vector<acl::string>& tokens);
|
|
|
|
void get(const std::vector<acl::string>& tokens);
|
|
|
|
void get(const char* key, int max);
|
|
|
|
void hash_get(const std::vector<acl::string>& tokens);
|
|
|
|
void hash_get(const char* key, size_t max);
|
|
|
|
void string_get(const std::vector<acl::string>& tokens);
|
|
|
|
void string_get(const char* key);
|
|
|
|
void list_get(const std::vector<acl::string>& tokens);
|
|
|
|
void list_get(const char* key, size_t max);
|
|
|
|
void set_get(const std::vector<acl::string>& tokens);
|
|
|
|
void set_get(const char* key, size_t max);
|
|
|
|
void zset_get(const std::vector<acl::string>& tokens);
|
|
|
|
void zset_get(const char* key, size_t max);
|
|
|
|
|
|
|
|
void pattern_remove(const std::vector<acl::string>& tokens);
|
2019-03-28 11:35:19 +08:00
|
|
|
long long pattern_remove(const char* addr, const char* pattern,
|
|
|
|
int cocurrent);
|
2019-03-28 11:20:05 +08:00
|
|
|
void remove(const std::vector<acl::string>& keys,
|
|
|
|
acl::atomic_long& deleted, acl::atomic_long& error,
|
|
|
|
acl::atomic_long& notfound);
|
2019-03-28 11:35:19 +08:00
|
|
|
void parallel_remove(int cocurrent,
|
|
|
|
const std::vector<acl::string>& keys,
|
2019-03-28 11:20:05 +08:00
|
|
|
acl::atomic_long& deleted, acl::atomic_long& error,
|
|
|
|
acl::atomic_long& notfound);
|
2023-04-03 22:04:13 +08:00
|
|
|
void parallel_remove(acl::thread_pool& threads,
|
|
|
|
const std::vector<acl::string>& keys,
|
|
|
|
acl::atomic_long& deleted, acl::atomic_long& error,
|
|
|
|
acl::atomic_long& notfound);
|
|
|
|
void remove(acl::redis& redis,
|
|
|
|
const std::vector<acl::string>& keys,
|
|
|
|
acl::atomic_long& deleted, acl::atomic_long& error,
|
|
|
|
acl::atomic_long& notfound);
|
2016-04-12 20:11:15 +08:00
|
|
|
|
|
|
|
void check_type(const std::vector<acl::string>& tokens);
|
|
|
|
void check_ttl(const std::vector<acl::string>& tokens);
|
|
|
|
void get_dbsize(const std::vector<acl::string>& tokens);
|
|
|
|
void request(const std::vector<acl::string>& tokens);
|
2016-04-15 14:51:45 +08:00
|
|
|
void request_one(const std::vector<acl::string>& tokens);
|
|
|
|
void request_all(const std::vector<acl::string>& tokens);
|
2016-08-27 18:34:02 +08:00
|
|
|
void request_masters(const std::vector<acl::string>& tokens);
|
|
|
|
void request_slaves(const std::vector<acl::string>& tokens);
|
2016-04-14 23:39:09 +08:00
|
|
|
bool show_result(const acl::redis_result& result, const char* addr);
|
2016-04-14 22:39:11 +08:00
|
|
|
|
|
|
|
void show_request(const std::vector<acl::string>& tokens);
|
|
|
|
|
|
|
|
void config(const std::vector<acl::string>& tokens);
|
|
|
|
void config(const char* addr, const std::vector<acl::string>& tokens);
|
|
|
|
void config_usage(void);
|
|
|
|
void request_one(const char* addr,
|
|
|
|
const std::vector<acl::string>& tokens);
|
2016-04-12 20:11:15 +08:00
|
|
|
};
|