作者:张立冰
出处:http://www.libing.name/2008/02/26/mysql-map-memcached.html
本文介绍利用MySQL UDFS For Memcached与MySQL触发程序结合实现将MySQL的数据映射到Memcached的一种方法,能实现当MySQL数据更新时,实时更新Memcache数据的效果,从而减少开发相应程序来维护Memcached数据。
MySQL UDFS For Memcached的官方介绍:
This is a set of MySQL UDFs (user defined functions) to work with memcached using libmemcached. With these functions you get, set, append, prepend, delete, increment, decrement objects in memcached, as well as set which servers to use and which behavior the server connections will use. Combine these functions with MySQL triggers and you can manage your memcached cache. The library makes use of libmemcached. You can also use memcached as a global sequence generator for MySQL by making use of the increment function. These functions are compatible with all versions of MySQL.
tar xzvf memcached_functions_mysql-0.2.tar.gz
cd memcached_functions_mysql-0.2
./configure –with-mysql=MYSQL_DIR/bin/mysql_config –libdir=MYSQL_DIR/lib/mysql/
make
make install
安装完成后将UDFs加载到MySQL中:
memc_servers_set()
mysql> create function memc_servers_set returns int soname “libmemcached_functions_mysql.so”;
memc_set()
mysql> create function memc_set returns int soname “libmemcached_functions_mysql.so”;
memc_get()
mysql> create function memc_get returns string soname “libmemcached_functions_mysql.so”;
memc_delete()
mysql> create function memc_delete returns string soname “libmemcached_functions_mysql.so”;