/
README
124 lines (85 loc) · 2.32 KB
/
README
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
--------------------------------
NGINX MySQL Handlersocket module
--------------------------------
Provides MySQL InnoDB access via Handlersocket protocol
Implemented as non-blocking upstream module
(c) 2011 Roman Arutyunyan, arut@qip.ru
Build:
======
Add this when configuring NGNIX:
./configure --add-module=$PATH_TO_MODULE
Usage:
=========
Suppose you have an InnoDB table in database "mydbname" named "mytable"
with 4 fields (of any type):
* "key" (this is primary key field as the name says :) )
* "field1"
* "field2"
* "field3"
These are settings you should add to nginx.conf file
to work with the table directly from NGINX.
# first create upstreams (read & write) with keepalive enabled
upstream hsock_rsrv {
server 127.0.0.1:9998;
keepalive 1024;
}
upstream hsock_wsrv {
server 127.0.0.1:9999;
keepalive 1024;
}
# then create operation locations within server block.
# 4 operations are supported: select, update, insert, delete
# Note there should be different upstreams for each of them
# (the module performs index initialization based on particular
# location data)
location ~ /select.* {
hsock_pass hsock_rsrv;
hsock_db mydbname;
hsock_table mytable;
# Yes, you should copy variables like this
# if you need to use arg_, http_ etc variables.
# They are not accessed directly so far.
set $key $arg_key;
hsock_select field1 field2 field3;
hsock_key $key;
}
location ~ /insert.* {
hsock_pass hsock_wsrv;
hsock_db mydbname;
hsock_table mytable;
set $key $arg_key;
set $field1 $arg_field1;
set $field2 $arg_field2;
set $field3 $arg_field3;
hsock_insert key $key
field1 $field1
field2 $field2
field3 $field3;
}
location ~ /update.* {
hsock_pass hsock_wsrv;
hsock_db mydbname;
hsock_table mytable;
set $key $arg_key;
set $field1 $arg_field1;
set $field2 $arg_field2;
set $field3 $arg_field3;
hsock_update
field1 $field1
field2 $field2
field3 $field3;
hsock_key $key;
}
location ~ /delete.* {
hsock_pass hsock_wsrv;
hsock_db mydbname;
hsock_table mytable;
set $key $arg_key;
hsock_delete;
hsock_key $key;
}
Data is returned line-by-line
1 line - errorcode (0=OK, >0=error)
2 line - number of data lines
3 ... - data lines; data fields are returned on a field-per-line basis.
Multiple rows are returned the same way as a single row.