forked from jimingmin/frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_glue.cpp
93 lines (76 loc) · 2.29 KB
/
redis_glue.cpp
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
/*
* redis_bank.cpp
*
* Created on: Feb 10, 2015
* Author: jimm
*/
#include "redis_glue.h"
#include "logger/logger.h"
using namespace LOGGER;
FRAME_NAMESPACE_BEGIN
map<const redisAsyncContext*, CRedisRaw *> CRedisGlue::m_stRedisContextMap;
CRedisGlue::CRedisGlue()
{
}
CRedisGlue::~CRedisGlue()
{
}
void CRedisGlue::RegRedisContext(redisAsyncContext *pContext, CRedisRaw *pAgent)
{
CRedisGlue::m_stRedisContextMap[pContext] = pAgent;
redisAsyncSetConnectCallback(pContext, &CRedisGlue::CB_Connect);
redisAsyncSetDisconnectCallback(pContext, &CRedisGlue::CB_Close);
}
void CRedisGlue::UnregRedisContext(redisAsyncContext *pContext)
{
CRedisGlue::m_stRedisContextMap.erase(pContext);
}
void CRedisGlue::CB_Connect(const redisAsyncContext *pContext, int32_t nStatus)
{
map<const redisAsyncContext*, CRedisRaw *>::iterator it = CRedisGlue::m_stRedisContextMap.find(pContext);
if(it != CRedisGlue::m_stRedisContextMap.end())
{
it->second->Connected(pContext, nStatus);
}
else
{
WRITE_WARN_LOG(MODULE_NAME, "redis connected!but it's not found redis context!\n");
}
}
void CRedisGlue::CB_Close(const redisAsyncContext *pContext, int32_t nStatus)
{
map<const redisAsyncContext*, CRedisRaw *>::iterator it = CRedisGlue::m_stRedisContextMap.find(pContext);
if(it != CRedisGlue::m_stRedisContextMap.end())
{
it->second->Closed(pContext, nStatus);
}
else
{
WRITE_WARN_LOG(MODULE_NAME, "redis closed!but it's not found redis context!\n");
}
}
void CRedisGlue::CB_RedisReply(redisAsyncContext *pContext, void *pReply, void *pSession)
{
map<const redisAsyncContext*, CRedisRaw *>::iterator it = CRedisGlue::m_stRedisContextMap.find(pContext);
if(it != CRedisGlue::m_stRedisContextMap.end())
{
it->second->OnRedisReply(pContext, pReply, pSession);
}
else
{
WRITE_WARN_LOG(MODULE_NAME, "recv redis reply!but it's not found redis context!\n");
}
}
void CRedisGlue::CB_UnsubscribeReply(redisAsyncContext *pContext, void *pReply, void *pSession)
{
map<const redisAsyncContext*, CRedisRaw *>::iterator it = CRedisGlue::m_stRedisContextMap.find(pContext);
if(it != CRedisGlue::m_stRedisContextMap.end())
{
it->second->OnUnsubscribeReply(pContext, pReply, pSession);
}
else
{
WRITE_WARN_LOG(MODULE_NAME, "recv subscribe reply!but it's not found redis context!\n");
}
}
FRAME_NAMESPACE_END