用mysql触发器自动更新memcache的实现代码
程序员文章站
2022-06-20 14:30:51
mysql 5.1支持触发器以及自定义函数接口(udf)的特性,如果配合libmemcache以及memcached functions for mysql,就能够实现的自...
mysql 5.1支持触发器以及自定义函数接口(udf)的特性,如果配合libmemcache以及memcached functions for mysql,就能够实现的自动更新。简单记录一下安装测试步骤。
安装步骤
- 安装,这个步骤很简单,随处可见
- 安装mysql server 5.1rc,安装办法也很大众,不废话了
- 编译,解压后安装即可
./configure; make; make install
- 编译memcached functions for mysql,在找一个最新的版本下载就是,
./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
make
make install
- 接下来有两个办法让memcached functions for mysql在mysql中生效
- 在mysql的shell中执行memcached_functions_mysql源码目录下的sql/install_functions.sql,这会把memcache function作为udf加入mysql
- 运行memcached_functions_mysql源码目录下的utils/install.pl,这是一个perl脚本,作用同上一条
测试memcache function
以下测试脚本摘自memcached_functions_mysql的源码目录,有兴趣可以试试
drop table if exists urls;
create table urls (
id int(3) not null,
url varchar(64) not null default '',
primary key (id)
);
select memc_servers_set('localhost:11211');
select memc_set('urls:sequence', 0);
delimiter
drop trigger if exists url_mem_insert;
create trigger url_mem_insert
before insert on urls
for each row begin
set new.id= memc_increment('urls:sequence');
set @mm= memc_set(concat('urls:',new.id), new.url);
end
delimiter ;
insert into urls (url) values ('http://google.com');
insert into urls (url) values ('http://www.ooso.net/index.php');
insert into urls (url) values ('http://www.ooso.net/');
insert into urls (url) values ('http://slashdot.org');
insert into urls (url) values ('http://mysql.com');
select * from urls;
select memc_get('urls:1');
select memc_get('urls:2');
select memc_get('urls:3');
select memc_get('urls:4');
select memc_get('urls:5');
create table urls (
id int(3) not null,
url varchar(64) not null default '',
primary key (id)
);
select memc_servers_set('localhost:11211');
select memc_set('urls:sequence', 0);
delimiter
drop trigger if exists url_mem_insert;
create trigger url_mem_insert
before insert on urls
for each row begin
set new.id= memc_increment('urls:sequence');
set @mm= memc_set(concat('urls:',new.id), new.url);
end
delimiter ;
insert into urls (url) values ('http://google.com');
insert into urls (url) values ('http://www.ooso.net/index.php');
insert into urls (url) values ('http://www.ooso.net/');
insert into urls (url) values ('http://slashdot.org');
insert into urls (url) values ('http://mysql.com');
select * from urls;
select memc_get('urls:1');
select memc_get('urls:2');
select memc_get('urls:3');
select memc_get('urls:4');
select memc_get('urls:5');
下一篇: python实现图片彩色转化为素描
推荐阅读
-
用mysql触发器自动更新memcache的实现代码
-
用PHP写的基于Memcache的Queue实现代码
-
用node和express连接mysql实现登录注册的实现代码
-
MySql用case...when..THEN..endcase实现获取星期名存储过程的代码实例
-
mysql表字段的默认值为函数的返回值 用mysql触发器实现
-
用mysql触发器自动更新memcache的实现代码
-
用PHP写的基于Memcache的Queue实现代码
-
用PHP写的基于Memcache的Queue实现代码_PHP教程
-
用PHP写的基于Memcache的Queue实现代码_php技巧
-
用PHP写的基于Memcache的Queue实现代码