forked from jimingmin/frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_channel.h
142 lines (86 loc) · 5.04 KB
/
redis_channel.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
/*
* redis_channel.h
*
* Created on: Mar 11, 2015
* Author: jimm
*/
#ifndef REDIS_CHANNEL_H_
#define REDIS_CHANNEL_H_
#include "redis_raw.h"
#include "redis_session.h"
#include <string>
using namespace std;
using namespace FRAME;
class CRedisChannel : public CRedisRaw
{
public:
enum TimeUnit
{
enmTimeUnit_Second,
enmTimeUnit_MilliSecond,
};
enum SetType
{
enmSetType_NX, //只在键不存在时,才对键进行设置操作
enmSetType_XX, //只在键已经存在时,才对键进行设置操作
};
CRedisChannel(int32_t nServerID, char *pAddress, uint16_t nPort);
virtual int32_t OnConnected();
virtual void OnClosed();
//---------------------------transaction--------------------------------
void Multi();
void Exec(RedisSession *pSession);
//---------------------------key-----------------------------------------
int32_t Del(RedisSession *pSession, const char *szKey);
// int32_t Del(RedisSession *pSession, const char *szFormat, ...);
int32_t Expire(RedisSession *pSession, const char *szKey, int32_t nTimeout);
//---------------------------string--------------------------------------
int32_t Get(RedisSession *pSession, const char *szKey);
int32_t IncrBy(RedisSession *pSession, const char *szKey, int64_t nIncrement);
int32_t Incr(RedisSession *pSession, const char *szKey);
//SET key value [EX seconds] [PX milliseconds] [NX|XX]
int32_t Set(RedisSession *pSession, const char *szKey, const char *szValue);
int32_t Set(RedisSession *pSession, const char *szKey, int64_t nValue);
int32_t Set(RedisSession *pSession, const char *szKey, const char *szValue, enum TimeUnit nUnit, int64_t nTime);
int32_t Set(RedisSession *pSession, const char *szKey, const char *szValue, enum TimeUnit nUnit, int64_t nTime, enum SetType nType);
int32_t Set(RedisSession *pSession, const char *szKey, const char *szValue, enum SetType nType);
int32_t SetNX(RedisSession *pSession, const char *szKey, const char *szValue);
int32_t SetNX(RedisSession *pSession, const char *szKey, int64_t nValue);
int32_t GetSet(RedisSession *pSession, const char *szKey, const char *szValue);
int32_t GetSet(RedisSession *pSession, const char *szKey, int64_t nValue);
//---------------------------hash----------------------------------------
int32_t HDel(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t HMSet(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t HMSet(RedisSession *pSession, const char *szKey, int32_t nArgc, const char **Argv, const size_t *ArgvLen);
int32_t HMGet(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t HIncrBy(RedisSession *pSession, const char *szKey, const char *szField, int64_t nIncr);
int32_t HExists(RedisSession *pSession, const char *szKey, const char *szField);
//---------------------------list-----------------------------------------
int32_t BLPop(RedisSession *pSession, const char *szKey, int32_t nTimeout);
int32_t RPush(RedisSession *pSession, const char *szKey, const char *szValue, uint16_t nValueLen);
int32_t LPop(RedisSession *pSession, const char *szKey);
int32_t LPush(RedisSession *pSession, const char *szKey, const char *szValue, uint16_t nValueLen);
//---------------------------set-----------------------------------------
int32_t SAdd(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t SIsMember(RedisSession *pSession, const char *szKey, int64_t nField);
int32_t SIsMember(RedisSession *pSession, const char *szKey, const char *szField);
int32_t SRem(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
//---------------------------sortedset-------------------------------------
int32_t ZAdd(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t ZCard(RedisSession *pSession, const char *szKey);
int32_t ZCount(RedisSession *pSession, const char *szKey, int32_t nMinIndex = -1, int32_t nMaxIndex = -1);
int32_t ZRem(RedisSession *pSession, const char *szKey, const char *szFormat, ...);
int32_t ZRangeByScore(RedisSession *pSession, const char *szKey, int32_t nMinIndex = -1, int32_t nMaxIndex = -1,
bool bWithScores = false, int32_t nOffset = 0, int32_t nCount = -1);
int32_t ZRank(RedisSession *pSession, const char *szKey, int64_t nField);
int32_t ZRank(RedisSession *pSession, const char *szKey, const char *szField);
int32_t ZRemRangeByRank(RedisSession *pSession, const char *szKey, int32_t nStartIndex = 0, int32_t nStopIndex = -1);
int32_t ZScore(RedisSession *pSession, const char *szKey, int64_t nField);
int32_t ZScore(RedisSession *pSession, const char *szKey, const char *szField);
//----------------------------sub/pub--------------------------------------
int32_t Subscribe(RedisSession *pSession, const char *szKey);
int32_t Unsubscribe(RedisSession *pSession, const char *szKey);
void OnUnsubscribeReply(const redisAsyncContext *pContext, void *pReply, void *pSessionIndex);
int32_t Publish(RedisSession *pSession, const char *szKey, const char *szValue, int32_t nValueLen);
};
#endif /* REDIS_CHANNEL_H_ */