9 Feb
Memcached Functions for MySQL 1.1 released!
I’m pleased to announce the release of Memcached Functions for MySQL, version 1.1. It’s been a while since the 1.0 release, and I’ll use writing a book and having a baby as an excuse, but nevertheless, this release has several changes and new features:
- Fixed all the calls to libmemcached that were broken when libmemcached changed. This release works with Libmemcached 0.44
- Added my own string functions as the libmemcached string functions I relied on before were made local/private from the shared library
- Added memc_get_cas() and memc_get_cas_by_key() functions. You can now obtain the CAS value of an item! For instance:
mysql> select memc_servers_set('localhost:11211');
+-------------------------------------+
| memc_servers_set('localhost:11211') |
+-------------------------------------+
| 0 |
+-------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_set('key1', 'test value');
+--------------------------------+
| memc_set('key1', 'test value') |
+--------------------------------+
| 1 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select memc_get_cas('key1');
+----------------------+
| memc_get_cas('key1') |
+----------------------+
| 81 |
+----------------------+
1 row in set (0.00 sec)
mysql> select memc_set('key1', 'test new value');
+------------------------------------+
| memc_set('key1', 'test new value') |
+------------------------------------+
| 1 |
+------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_get_cas('key1');
+----------------------+
| memc_get_cas('key1') |
+----------------------+
| 82 |
+----------------------+
1 row in set (0.00 sec)
mysql> select memc_get_cas('key1');
+----------------------+
| memc_get_cas('key1') |
+----------------------+
| 83 |
+----------------------+
1 row in set (0.00 sec)
mysql> select memc_get('key1');
+----------------------------------+
| memc_get('key1') |
+----------------------------------+
| ah! someone else changed "key1"! |
+----------------------------------+
1 row in set (0.00 sec)
mysql> select memc_cas('key1', 'change this value using cas', 83);
+-----------------------------------------------------+
| memc_cas('key1', 'change this value using cas', 83) |
+-----------------------------------------------------+
| 1 |
+-----------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_get('key1');
+-----------------------------+
| memc_get('key1') |
+-----------------------------+
| change this value using cas |
+-----------------------------+
1 row in set (0.01 sec)
mysql> select memc_get_cas('key1');
+----------------------+
| memc_get_cas('key1') |
+----------------------+
| 84 |
+----------------------+
mysql> select memc_cas('key1','this value will not change because the cas is not the 84', 83);
+---------------------------------------------------------------------------------+
| memc_cas('key1','this value will not change because the cas is not the 84', 83) |
+---------------------------------------------------------------------------------+
| 0 |
+---------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_get_cas('key1');
+----------------------+
| memc_get_cas('key1') |
+----------------------+
| 84 |
+----------------------+
1 row in set (0.00 sec)
mysql> select memc_get('key1');
+-----------------------------+
| memc_get('key1') |
+-----------------------------+
| change this value using cas |
+-----------------------------+
1 row in set (0.00 sec)
This is convenient to know if someone else changed an item since you last updated it yourself, hence the usefulness of CAS, which is a check and set operation which means “store this data but only if no one else has updated since I last fetched it.”
Enjoy the code! You can find the release at:
http://patg.net/downloads/memcached_functions_mysql-1.1.tar.gz

Great! I’ve been missing something like the cas functions .. thanks for the relase
Sheer Awesomeness! Thanks!
Hi,
It’s very nice!
Libmemcached 0.44 + memcached_functions_mysql-1.1 + CentOS 5
But I can’t complete it:
common.h:3:18: error: util.h: No such file or directory
Do you have any idear?
Thank you.
Tim,
Hmm… Is there a util.h in the distribution? If not, try commenting that out of common.h and recompiling.
Hi! It does not help when I comment out of common.h
You use my_string_st but I cannot find any declaration of it and the compiler complains:
util.c:172: error: `my_string_st’ undeclared (first use in this function)
This happens when I comment out util.h
Please advice.
Thank you, Peter
Hi there,
what version of libmemcached are you using?
regards,
Patrick
About the util.h include I fixed it by using:
#include <libmemcached/util.h>
I installed: libmemcached-1.0.3
And then tryied to installed: memcached_functions_mysql-1.1
While "configure" run fine, the make failed with:
make[2]: Entering directory `/root/Install/mysql_memcach/memcached_functions_mysql-1.1/src’
/bin/sh ../libtool –preserve-dup-deps –tag=CC –mode=compile gcc -DHAVE_CONFIG_H -I. -I../include -I/opt/mysql/mysql/include -g -DUNIV_LINUX -DUNIV_LINUX -g -O2 -MT util.lo -MD -MP -MF .deps/util.Tpo -c -o util.lo util.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../include -I/opt/mysql/mysql/include -g -DUNIV_LINUX -DUNIV_LINUX -g -O2 -MT util.lo -MD -MP -MF .deps/util.Tpo -c util.c -fPIC -DPIC -o .libs/util.o
util.c: In function ‘string_create’:
util.c:172: error: invalid application of ‘sizeof’ to incomplete type ‘my_string_st’
util.c:173: error: dereferencing pointer to incomplete type
util.c:174: error: dereferencing pointer to incomplete type
util.c:175: error: dereferencing pointer to incomplete type
util.c:176: error: dereferencing pointer to incomplete type
util.c:177: error: dereferencing pointer to incomplete type
util.c:178: error: dereferencing pointer to incomplete type
util.c:178: error: dereferencing pointer to incomplete type
util.c: In function ‘string_append’:
util.c:185: error: dereferencing pointer to incomplete type
util.c:185: error: dereferencing pointer to incomplete type
util.c:188: error: dereferencing pointer to incomplete type
util.c:190: error: dereferencing pointer to incomplete type
util.c:197: error: dereferencing pointer to incomplete type
util.c:202: error: dereferencing pointer to incomplete type
util.c:202: error: dereferencing pointer to incomplete type
util.c:202: error: dereferencing pointer to incomplete type
util.c:204: error: dereferencing pointer to incomplete type
util.c:207: error: dereferencing pointer to incomplete type
util.c:208: error: dereferencing pointer to incomplete type
util.c:209: error: dereferencing pointer to incomplete type
util.c: In function ‘free_string’:
util.c:216: error: dereferencing pointer to incomplete type
util.c: In function ‘string_reset’:
util.c:222: error: dereferencing pointer to incomplete type
util.c:222: error: dereferencing pointer to incomplete type
util.c:223: error: dereferencing pointer to incomplete type
util.c:224: error: dereferencing pointer to incomplete type
util.c:224: error: dereferencing pointer to incomplete type
make[2]: *** [util.lo] Error 1
make[2]: Leaving directory `/root/Install/mysql_memcach/memcached_functions_mysql-1.1/src’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/Install/mysql_memcach/memcached_functions_mysql-1.1/src’
make: *** [all-recursive] Error 1
Currently this is whats working in my environment:
http://buzznt.blogspot.com/2012/02/memcached-and-udf-for-mysql-on-centos.html