-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
349 lines (244 loc) · 9.52 KB
/
README
File metadata and controls
349 lines (244 loc) · 9.52 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
Hi!
This is the memcached mysql UDFs (user defined functions) to work with libmemcached, Brian Aker's super duper
new fast client library for memcached.
Original repo: https://github.com/smira/memcached_functions_mysql
Prerequisites
* MySQL 5.0 and greater
* Latest memcached (svn co http://code.sixapart.com/svn/memcached/trunk)
* libmemcached (hg clone http://hg.tangent.org/libmemcached/)
* latest autoconf tools
To build:
./config/bootstrap
./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
make
make install
To then load the functions that you need:
Please keep in mind that for your UDF to be loaded, it must be in the
library path for your server (and yes, we should fix this). On Linux you can
set this by exporting the correct path in LD_LIBRARY_PATH for your mysql
server.
You can install the functions as listed below by cutting and pasting,or
optionally there now are two ways to install these easily:
* sql/install_functions.sql - this loads the functions with simple CREATE FUNCTION
commands as shown below
* utils/install.pl - This is a perl script that queries your mysql.func table to see what
functions are already installed and installs them if not yet installed. It will ask you
each time for every function not installed, if you want to install, or you can run it with
-s/--silent to have it not prompt you. It runs as the 'root' database user (required).
memc_servers_add()
CREATE FUNCTION memc_servers_add RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_servers_add_by_key()
CREATE FUNCTION memc_servers_add_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_servers_set()
CREATE FUNCTION memc_servers_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_set()
CREATE FUNCTION memc_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_set_by_key()
CREATE FUNCTION memc_set_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_cas()
CREATE FUNCTION memc_cas RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_cas_by_key()
CREATE FUNCTION memc_cas_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_get()
CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
memc_get_by_key()
CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
memc_delete()
CREATE FUNCTION memc_delete RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_delete_by_key()
CREATE FUNCTION memc_delete_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_append()
CREATE FUNCTION memc_append RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_append_by_key()
CREATE FUNCTION memc_append_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_prepend()
CREATE FUNCTION memc_prepend RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_prepend_by_key()
CREATE FUNCTION memc_prepend_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_increment()
CREATE FUNCTION memc_increment RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_decrement()
CREATE FUNCTION memc_decrement RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_replace()
CREATE FUNCTION memc_replace RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_replace_by_key()
CREATE FUNCTION memc_replace_by_key RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_servers_behavior_set()
CREATE FUNCTION memc_servers_behavior_set RETURNS INT SONAME "libmemcached_functions_mysql.so";
memc_list_behaviors()
CREATE FUNCTION memc_list_behaviors RETURNS STRING SONAME "libmemcached_functions_mysql.so";
memc_stats()
CREATE FUNCTION memc_stats RETURNS STRING SONAME "libmemcached_functions_mysql.so";
memc_stats_get_keys()
CREATE FUNCTION memc_stats_get_keys RETURNS STRING SONAME "libmemcached_functions_mysql.so";
memc_stats_get_value()
CREATE FUNCTION memc_stats_get_value RETURNS STRING SONAME "libmemcached_functions_mysql.so";
Usage of functions
memc_servers_set()
I want to set the server I'm using to localhost:
select memc_servers_set('127.0.0.1');
I have several servers, mem1.grazr.com, mem2.grazr.com:
select memc_servers_set('mem1.grazr.com,mem2.grazr.com');
memc_set()
mysql> select memc_set('abc', 'cool new memcached udf in mysql');
+----------------------------------------------------+
| memc_set('abc', 'cool new memcached udf in mysql') |
+----------------------------------------------------+
| 0 |
+----------------------------------------------------+
1 row in set (0.00 sec)
memc_get()
mysql> select memc_get('abc');
+---------------------------------+
| memc_get('abc') |
+---------------------------------+
| cool new memcached udf in mysql |
+---------------------------------+
1 row in set (0.00 sec)
memc_delete()
mysql> select memc_delete('abc');
+--------------------+
| memc_delete('abc') |
+--------------------+
| 0 |
+--------------------+
1 row in set (0.00 sec)
mysql> select memc_get('abc');
+-----------------+
| memc_get('abc') |
+-----------------+
| NULL |
+-----------------+
1 row in set (0.00 sec)
memc_append() and memc_prepend()
mysql> select memc_set('abc', ' Spot ');
+---------------------------+
| memc_set('abc', ' Spot ') |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select memc_append('abc', ' run.');
+-----------------------------+
| memc_append('abc', ' run.') |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.00 sec)
mysql> select memc_get('abc');
+-----------------+
| memc_get('abc') |
+-----------------+
| Spot run. |
+-----------------+
1 row in set (0.00 sec)
mysql> select memc_prepend('abc', 'See');
+----------------------------+
| memc_prepend('abc', 'See') |
+----------------------------+
| 0 |
+----------------------------+
1 row in set (0.00 sec)
mysql> select memc_get('abc');
+-----------------+
| memc_get('abc') |
+-----------------+
| See Spot run. |
+-----------------+
1 row in set (0.00 sec)
memc_increment() and memc_decrement()
mysql> select memc_set('sequence:1', 1);
+---------------------------+
| memc_set('sequence:1', 1) |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select memc_get('sequence:1');
+------------------------+
| memc_get('sequence:1') |
+------------------------+
| 1 |
+------------------------+
1 row in set (0.00 sec)
mysql> select memc_increment('sequence:1', 5);
+---------------------------------+
| memc_increment('sequence:1', 5) |
+---------------------------------+
| 6 |
+---------------------------------+
1 row in set (0.00 sec)
mysql> select memc_increment('sequence:1', 10);
]+----------------------------------+
| memc_increment('sequence:1', 10) |
+----------------------------------+
| 16 |
+----------------------------------+
1 row in set (0.01 sec)
mysql> select memc_increment('sequence:1');
+------------------------------+
| memc_increment('sequence:1') |
+------------------------------+
| 17 |
+------------------------------+
1 row in set (0.00 sec)
mysql> select memc_decrement('sequence:1');
+------------------------------+
| memc_decrement('sequence:1') |
+------------------------------+
| 16 |
+------------------------------+
1 row in set (0.00 sec)
mysql> select memc_decrement('sequence:1', 15);
+----------------------------------+
| memc_decrement('sequence:1', 15) |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set (0.00 sec)
memc_replace()
mysql> select memc_replace('sequence:1', 'String value');
+--------------------------------------------+
| memc_replace('sequence:1', 'String value') |
+--------------------------------------------+
| 0 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_get('sequence:1');
+------------------------+
| memc_get('sequence:1') |
+------------------------+
| String value |
+------------------------+
1 row in set (0.01 sec)
memc_list_behaviors()
Use this to see what behaviors you have to chose from
memc_servers_behavior_set()
You use this to set the type of behavior your client has to the memcached server
mysql> select memc_list_behaviors()\G
*************************** 1. row ***************************
memc_list_behaviors():
+-------------------------------------+
| MEMCACHED SERVER BEHAVIORS |
+-------------------------------------+
| MEMCACHED_BEHAVIOR_SUPPORT_CAS |
| MEMCACHED_BEHAVIOR_NO_BLOCK |
| MEMCACHED_BEHAVIOR_TCP_NODELAY |
| MEMCACHED_BEHAVIOR_HASH |
| MEMCACHED_BEHAVIOR_CACHE_LOOKUPS |
| MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE |
| MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE |
+-------------------------------------+
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1');
+-----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1') |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+
1 row in set (0.01 sec)
Have fun!
Cheers,
Brian,
Seattle, WA
Patrick,
Sharon, NH (Live Free or Die!).