-
Notifications
You must be signed in to change notification settings - Fork 952
Expand file tree
/
Copy pathredis_connection.cpp
More file actions
115 lines (87 loc) · 2.08 KB
/
redis_connection.cpp
File metadata and controls
115 lines (87 loc) · 2.08 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
#include "acl_stdafx.hpp"
#ifndef ACL_PREPARE_COMPILE
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/stdlib/snprintf.hpp"
#include "acl_cpp/redis/redis_client.hpp"
#include "acl_cpp/redis/redis_connection.hpp"
#endif
#if !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
namespace acl {
redis_connection::redis_connection()
{
}
redis_connection::redis_connection(redis_client* conn)
: redis_command(conn)
{
}
redis_connection::redis_connection(redis_client_cluster* cluster)
: redis_command(cluster)
{
}
redis_connection::redis_connection(redis_client_cluster* cluster, size_t)
: redis_command(cluster)
{
}
redis_connection::redis_connection(redis_client_pipeline* pipeline)
: redis_command(pipeline)
{
}
redis_connection::~redis_connection()
{
}
bool redis_connection::auth(const char* passwd)
{
const char* argv[2];
size_t lens[2];
argv[0] = "AUTH";
lens[0] = sizeof("AUTH") - 1;
argv[1] = passwd;
lens[1] = strlen(passwd);
build_request(2, argv, lens);
return check_status();
}
bool redis_connection::select(int dbnum)
{
const char* argv[2];
size_t lens[2];
argv[0] = "SELECT";
lens[0] = strlen(argv[0]);
char* buf = (char*) dbuf_->dbuf_alloc(21);
safe_snprintf(buf, 21, "%d", dbnum);
argv[1] = buf;
lens[1] = strlen(argv[1]);
build_request(2, argv, lens);
return check_status();
}
bool redis_connection::ping()
{
const char* argv[1];
size_t lens[1];
argv[0] = "PING";
lens[0] = strlen(argv[0]);
build_request(1, argv, lens);
return check_status("PONG");
}
bool redis_connection::echo(const char* s)
{
const char* argv[2];
size_t lens[2];
argv[0] = "ECHO";
lens[0] = strlen(argv[0]);
argv[1] = s;
lens[1] = strlen(argv[1]);
string buf;
build_request(2, argv, lens);
return get_string(buf) >= 0 ? true : false;
}
bool redis_connection::quit()
{
const char* argv[1];
size_t lens[1];
argv[0] = "QUIT";
lens[0] = strlen(argv[0]);
build_request(1, argv, lens);
return check_status();
}
} // namespace acl
#endif // ACL_CLIENT_ONLY