-
Notifications
You must be signed in to change notification settings - Fork 952
Expand file tree
/
Copy pathredis_transaction.cpp
More file actions
147 lines (116 loc) · 2.68 KB
/
redis_transaction.cpp
File metadata and controls
147 lines (116 loc) · 2.68 KB
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
#include "acl_stdafx.hpp"
#ifndef ACL_PREPARE_COMPILE
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/redis/redis_client.hpp"
#include "acl_cpp/redis/redis_result.hpp"
#include "acl_cpp/redis/redis_transaction.hpp"
#endif
#if !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
namespace acl {
redis_transaction::redis_transaction()
{
}
redis_transaction::redis_transaction(redis_client* conn)
: redis_command(conn)
{
}
redis_transaction::redis_transaction(redis_client_cluster* cluster)
: redis_command(cluster)
{
}
redis_transaction::redis_transaction(redis_client_cluster* cluster, size_t)
: redis_command(cluster)
{
}
redis_transaction::redis_transaction(redis_client_pipeline* pipeline)
: redis_command(pipeline)
{
}
redis_transaction::~redis_transaction()
{
}
bool redis_transaction::watch(const std::vector<string>& keys)
{
build("WATCH", NULL, keys);
return check_status();
}
bool redis_transaction::unwatch()
{
const char* argv[1];
size_t lens[1];
argv[0] = "UNWATCH";
lens[0] = strlen(argv[0]);
build_request(1, argv, lens);
return check_status();
}
bool redis_transaction::multi()
{
cmds_.clear();
const char* argv[1];
size_t lens[1];
argv[0] = "MULTI";
lens[0] = sizeof("MULTI") - 1;
build_request(1, argv, lens);
return check_status();
}
bool redis_transaction::exec()
{
const char* argv[1];
size_t lens[1];
argv[0] = "EXEC";
lens[0] = sizeof("EXEC") - 1;
build_request(1, argv, lens);
const redis_result* result = run();
if(result == NULL || result->get_type() != REDIS_RESULT_ARRAY) {
return false;
}
size_t size = result->get_size();
if (size != cmds_.size()) {
return false;
}
return true;
}
bool redis_transaction::discard()
{
const char* argv[1];
size_t lens[1];
argv[0] = "DISCARD";
lens[0] = sizeof("DISCARD") - 1;
build_request(1, argv, lens);
return check_status();
}
bool redis_transaction::run_cmd(const char* cmd, const char* argv[],
const size_t lens[], size_t argc)
{
build(cmd, NULL, argv, lens, argc);
if (!check_status("QUEUED")) {
return false;
}
cmds_.push_back(cmd);
return true;
}
bool redis_transaction::run_cmd(const char* cmd,
const std::vector<string>& args)
{
build(cmd, NULL, args);
if (!check_status("QUEUED")) {
return false;
}
cmds_.push_back(cmd);
return true;
}
size_t redis_transaction::get_size() const
{
return result_size();
}
const redis_result* redis_transaction::get_child(size_t i, string* cmd) const
{
if (cmd != NULL) {
if (i < cmds_.size()) {
*cmd = cmds_[i];
}
}
return result_child(i);
}
} // namespace acl
#endif // ACL_CLIENT_ONLY