Use mysql triggers to automatically update memcache implementation code _ PHP Tutorial

Source: Internet
Author: User
Tags perl script
Use the mysql trigger to automatically update the implementation code of memcache. Mysql5.1 supports the features of triggers and user-defined function interfaces (UDFs). if libmemcache and MemcachedFunctionsforMySQL are used together, memcache can be automatically updated. A simple record of the features that mysql 5.1 supports triggers and user-defined function interfaces (UDFs). if libmemcache and Memcached Functions for MySQL are used together, memcache can be automatically updated. Record the installation and testing steps.

Installation steps

  • Install memcached. This step is simple and can be seen everywhere.
  • Install mysql server 5.1RC.
  • Compile libmemcached, decompress it, and install it.
    ./configure; make; make install
  • Compile Memcached Functions for MySQL. find the latest download path at http://download.tangent.org/here,
    ./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
    make
    make install
    There are two ways to make Memcached Functions for MySQL take effect in mysql.

  • Execute SQL/install_functions. SQL in the memcached_functions_mysql source code directory in the mysql shell. This will add memcache function as UDF to mysql
  • Run utils/install. pl in the memcached_functions_mysql source code directory. this is a perl script that works the same way as the previous one.


Test memcache function
The following test script is taken from the source code directory of memcached_functions_mysql. if you are interested, try it.

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 ' ) ;

Http://www.bkjia.com/PHPjc/320793.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320793.htmlTechArticlemysql 5.1 supports trigger and UDF features, if combined with libmemcache and Memcached Functions for MySQL, memcache can be automatically updated. Simple record...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.