Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use MySQL triggers to automatically update memcache

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use MySQL triggers to update memcache automatically. I hope you will get something after reading this article. Let's discuss it together.

Mysql 5.1supports the features of trigger and custom function interface (UDF). If you cooperate with libmemcache and Memcached Functions for MySQL, you can automatically update memcache. Briefly record the installation test steps.

Installation steps

To install memcached, this step is simple and can be seen everywhere.

Install mysql server 5.1RC, the installation method is also very popular, cut the crap

Compile libmemcached, decompress it and install it. / configure; make; make install

Compiling Memcached Functions for MySQL, looking for the latest version is. / configure-- with-mysql=/usr/local/mysql/bin/mysql_config-- libdir=/usr/local/mysql/lib/mysql/

Make

Make install

Next, there are two ways to make Memcached Functions for MySQL effective in mysql

Execute sql/install_functions.sql under the memcached_functions_mysql directory in the shell of mysql, which will add memcache function to mysql as UDF

Run utils/install.pl under the memcached_functions_mysql source directory, which is a perl script that works the same as the previous line

Test memcache function

The following test script is extracted from the source directory of memcached_functions_mysql. If you are interested, you can try it.

PLAIN TEXTCODE: 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.);

Insert into urls (url) values (http://www.devdao.net/);

Insert into urls (url) values (http://slashdot.org);

Insert into urls (url) values (http://.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)

After reading this article, I believe you have a certain understanding of "how to use MySQL triggers to update memcache automatically". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report