forked from RedisCppTeam/redis-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisClientScript.cpp
147 lines (118 loc) · 3.06 KB
/
RedisClientScript.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
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
147
/**
* Copyright (c) 2015, 爱wifi(版权声明)
*
* @file RedisClientScript.cpp
* @brief 实现redis客户端Script指令
*
*
* @author: Stanley Huang
* @date: Aug 12, 2015
*
* 修订说明:初始版本
*/
#include "Command.h"
#include "CRedisClient.h"
void CRedisClient::eval(const string& script , const VecString& keysVec ,
const VecString& argsVec , CResult& result )
{
Command cmd("EVAL");
cmd << script << keysVec.size();
VecString::const_iterator it = keysVec.begin();
VecString::const_iterator end = keysVec.end();
for ( ; it != end; ++it )
{
cmd << *it;
}
it = argsVec.begin();
end = argsVec.end();
for( ; it != end; ++it )
{
cmd << *it;
}
_getResult( cmd, result );
}
void CRedisClient::eval(const std::string &script, CResult &result)
{
VecString keysVec;
VecString argsVec;
eval( script,keysVec,argsVec,result );
}
void CRedisClient::eval(const std::string &script, const CRedisClient::VecString &keysVec, CResult &result)
{
VecString argsVec;
eval( script,keysVec,argsVec,result );
}
void CRedisClient::evalSha(const string& sha , const VecString& keysVec ,
const VecString& argsVec , CResult& result )
{
Command cmd("EVALSHA");
cmd << sha << keysVec.size();
VecString::const_iterator it = keysVec.begin();
VecString::const_iterator end = keysVec.end();
for ( ; it != end; ++it )
{
cmd << *it;
}
it = argsVec.begin();
it = argsVec.end();
for ( ; it != end; ++it )
{
cmd << *it;
}
_getResult( cmd, result );
}
void CRedisClient::evalSha(const std::string &script, CResult &result)
{
VecString keysVec;
VecString argsVec;
evalSha( script, keysVec, argsVec, result );
}
void CRedisClient::evalSha(const std::string &script,const VecString& keys,CResult &result)
{
VecString argsVec;
evalSha( script, keys, argsVec, result );
}
void CRedisClient::scriptLoad(const string& script , string& values )
{
Command cmd("SCRIPT");
cmd << "LOAD" << script;
_getString(cmd, values);
}
void CRedisClient::scriptExists( const VecString& script , VecBool& result )
{
Command cmd("SCRIPT");
cmd << "EXISTS";
VecString::const_iterator sit = script.begin();
VecString::const_iterator send = script.end();
for ( ; sit != send; ++sit )
{
cmd << *sit;
}
CResult res;
_getArry( cmd, res );
CResult::ListCResult::const_iterator it = res.getArry().begin();
CResult::ListCResult::const_iterator end = res.getArry().end();
for ( ; it != end; ++it )
{
result.push_back( it->getInt()) ;
}
return;
}
void CRedisClient::scriptFlush( void )
{
Command cmd("SCRIPT");
string status;
cmd << "FLUSH";
_getStatus(cmd, status);
if ( "OK"!=status)
throw ProtocolErr( "CONFIG RESETSTAT: data recved is not OK" );
}
void CRedisClient::scriptKill()
{
Command cmd("SCRIPT");
cmd << "KILL";
string status;
_getStatus( cmd, status );
if ( "OK"!=status)
throw ProtocolErr( "CONFIG RESETSTAT: data recved is not OK" );
}