forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pika_slot.h
146 lines (100 loc) · 2.91 KB
/
pika_slot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef PIKA_SLOT_H_
#define PIKA_SLOT_H_
#include "pika_command.h"
#include "pika_client_conn.h"
#include "strings.h"
const std::string SlotKeyPrefix = "_internal:slotkey:4migrate:";
const size_t MaxKeySendSize = 10 * 1024;
//crc 32
#define HASH_SLOTS_MASK 0x000003ff
#define HASH_SLOTS_SIZE (HASH_SLOTS_MASK + 1)
const uint32_t IEEE_POLY = 0xedb88320;
extern uint32_t crc32tab[256];
void CRC32TableInit(uint32_t poly);
extern void InitCRC32Table();
extern uint32_t CRC32Update(uint32_t crc, const char *buf, int len);
extern int SlotNum(const std::string &str);
extern int KeyType(const std::string key, std::string &key_type);
extern void SlotKeyAdd(const std::string type, const std::string key);
extern void SlotKeyRem(const std::string key);
extern void KeyNotExistsRem(const std::string type, const std::string key);
class SlotsMgrtTagSlotCmd : public Cmd {
public:
SlotsMgrtTagSlotCmd() { }
virtual void Do();
private:
std::string dest_ip_;
int64_t dest_port_;
int64_t timeout_ms_;
int64_t slot_num_;
std::string key_;
char key_type_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
int SlotKeyPop();
};
class SlotsMgrtTagOneCmd : public Cmd {
public:
SlotsMgrtTagOneCmd() { }
virtual void Do();
private:
std::string dest_ip_;
int64_t dest_port_;
int64_t timeout_ms_;
std::string key_;
int64_t slot_num_;
char key_type_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
int KeyTypeCheck();
int SlotKeyRemCheck();
};
class SlotsInfoCmd : public Cmd {
public:
SlotsInfoCmd() { }
virtual void Do();
private:
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
};
class SlotsHashKeyCmd : public Cmd {
public:
SlotsHashKeyCmd() { }
virtual void Do();
private:
std::vector<std::string> keys_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
};
class SlotsReloadCmd : public Cmd {
public:
SlotsReloadCmd() { }
virtual void Do();
private:
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
};
class SlotsReloadOffCmd : public Cmd {
public:
SlotsReloadOffCmd() { }
virtual void Do();
private:
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
};
class SlotsDelCmd : public Cmd {
public:
SlotsDelCmd() { }
virtual void Do();
private:
std::vector<std::string> slots_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
};
class SlotsScanCmd : public Cmd {
public:
SlotsScanCmd() : pattern_("*"), count_(10) { }
virtual void Do();
private:
std::string key_, pattern_;
int64_t cursor_, count_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo *const ptr_info);
virtual void Clear() {
pattern_ = "*";
count_ = 10;
}
};
#endif