首页 > 互联网技术 > 使用mysql memcached 自定义函数

使用mysql memcached 自定义函数

2010年4月9日 2,835 views 发表评论 阅读评论

使用mysql memcached 自定义函数

The memcached MySQL User Defined Functions (UDFs) enable you to set and retrieve objects from within MySQL 5.0 or greater.
https://launchpad.net/memcached-udfs
这是一套Mysql自定义函数,可用来操作Memcached.当前版本1.1了.

我们由此可以在一个统一的接口更新数据,利用mysql的触发器来更新memcached. 这样可以减少研发同事的工作量.
理论上可靠性是没有问题的.因为libmemcached常用的算法也支持,和我们用php客户端也一样.
关于测试mysql的触发器更新memcached略.mysql的触发器发展许久了,应该是可以信赖的.
This is a set of MySQL UDFs (user defined functions) to work with memcached using libmemcached. With these functions you get, set, cas, 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. The major contributing author is Patrick Galbraith The functions:
memc_servers_set()
memc_set(), memc_set_by_key()
memc_cas(), memc_cas_by_key(),
memc_get(), memc_get_by_key(),
memc_get_cas(), memc_get_cas_by_key(),
memc_delete(), memc_delete_by_key()
memc_append(), memc_append_by_key()
memc_prepend(), memc_prepend_by_key()
memc_increment(),
memc_decrement()
memc_replace(), memc_replace_by_key(),
memc_behavior_set(), memc_behavior_get(),
memc_behaviors_list(), memc_server_count(),
memc_udf_version(), memc_version()
安装.
关于安装.可以看安装包里的.
/home/garychen/pkgs/memcached_functions_mysql-1.1/utils/
/home/garychen/pkgs/memcached_functions_mysql-1.1/sql
我是参考 将MySQL数据映射到Memcached中 这篇帖子的.
下载:
wget http://launchpad.net/memcached-udfs/trunk/1.1/+download/memcached_functions_mysql-1.1.tar.gz
解压之..
./configure –prefix=/home/garychen/app/libmemcached_functions_mysql/ –with-mysql=/home/garychen/app/mysql/bin/mysql_config –with-libmemcached=/home/garychen/app/libmemcached-0.3/
#或者添加 –libdir=/home/garychen/app/mysql/lib/mysql/plugins
make
make install
更改/etc/man.config 添加/home/garychen/app/libmemcached_functions_mysql/share/man 目录以加载man帮助.
for example : man memc_get
###可能你想.copy memcached UDFs 到Mysql plugins 目录.
cp libmemcached_functions_mysql* /home/garychen/app/mysql/lib/mysql/plugins
[mysqld]
plugin_dir=/home/garychen/app/mysql/lib/mysql/plugins
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”;
mysql> select memc_servers_set(‘127.0.0.1’);
+——————————-+
| memc_servers_set(‘127.0.0.1’) |
+——————————-+
| 0 |
+——————————-+
1 row in set (0.01 sec)
mysql> select memc_set(‘garychen’,’good_job’);
+———————————+
| memc_set(‘garychen’,’good_job’) |
+———————————+
| 1 |
+———————————+
1 row in set (0.00 sec)
mysql> select memc_get(‘garychen’);
+———————-+
| memc_get(‘garychen’) |
+———————-+
| good_job |
+———————-+
1 row in set (0.00 sec)
附带点资料:
memcached 和 Grails,第 1 部分:安装和使用 memcached

 » 如果喜欢可以: 点此订阅本站
分类: 互联网技术 标签: , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.