forked from jimingmin/frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_lock.h
105 lines (77 loc) · 1.81 KB
/
redis_lock.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
/*
* redis_lock.h
*
* Created on: 2015年4月2日
* Author: jimm
*/
#ifndef REDIS_LOCK_H_
#define REDIS_LOCK_H_
#include "common/common_object.h"
#include "frame_timer.h"
#include "frame.h"
#include "redis_channel.h"
#include "redis_session.h"
#include <stddef.h>
#include <string>
using namespace std;
using namespace FRAME;
class RedisLock;
typedef void (CBaseObject::*LockResult)(int32_t nResult, RedisLock *pRedisLock);
class RedisLock : public CBaseObject
{
public:
enum
{
enmRedisLock_Success = 0x00,
enmRedisLock_Fail = 0x01,
enmRedisLock_RedisError = 0x02,
enmRedisLock_Timeout = 0x03,
};
RedisLock()
{
m_nSessionIndex = 0;
m_nLockExpireTime = 0;
m_pRedisChannel = NULL;
m_pHandlerObj = NULL;
m_fcLockResult = NULL;
}
virtual ~RedisLock()
{
Uninit();
}
virtual int32_t Init()
{
return 0;
}
virtual int32_t Uninit()
{
return 0;
}
virtual int32_t GetSize()
{
return 0;
}
void SetSessionIndex(uint32_t nSessionIndex);
uint32_t GetSessionIndex();
uint8_t *GetSessionData();
void SetRedisChannel(CRedisChannel *pRedisChannel);
CRedisChannel *GetRedisChannel();
void SetHandlerObj(CBaseObject *pObj);
CBaseObject *GetHandlerObj();
void SetLockResultCallback(LockResult result);
LockResult GetLockResultCallback();
int32_t Lock(char *szKey);
int32_t Unlock();
int32_t OnSessionSetNX(int32_t nResult, void *pReply, void *pSession);
int32_t OnSessionGet(int32_t nResult, void *pReply, void *pSession);
int32_t OnSessionGetSet(int32_t nResult, void *pReply, void *pSession);
// int32_t OnRedisSessionTimeout(void *pTimerData);
protected:
string m_strLockName;
int64_t m_nLockExpireTime;
uint32_t m_nSessionIndex;
CRedisChannel *m_pRedisChannel;
CBaseObject *m_pHandlerObj;
LockResult m_fcLockResult;
};
#endif /* REDIS_LOCK_H_ */