Automatic update of MEMCACHE implementation code with MySQL triggers _php tutorial

Source: Internet
Author: User
Tags perl script
MySQL 5.1 supports triggers and the features of the Custom Function interface (UDF), which, if mated with Libmemcache and memcached Functions for MySQL, enables automatic memcache updates. Simply record the installation test steps.

Installation steps

    • Install memcached, this step is very simple, everywhere
    • Install MySQL server 5.1RC, installation method is also very popular, no nonsense
    • Compile libmemcached, install after decompression
      ./configure; make; make install
    • Compile memcached Functions for MySQL, find a latest version of the download in http://download.tangent.org/is,
      ./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
      make
      make install
      Then there are two ways to make memcached Functions for MySQL in MySQL.

    • Execute the Sql/install_functions.sql in the Memcached_functions_mysql source directory in the MySQL shell, which will add Memcache function as a UDF to MySQL
    • Run the Memcached_functions_mysql source directory under the utils/install.pl, this is a Perl script, the role of a


Test Memcache function
The following test scripts are excerpted from the source directory of Memcached_functions_mysql and are interested to try

Drop Table if exists URLs ;
Create Table URLs (
ID int ( 3 ) not NULL ,
URL varchar ( - ) 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/320793.html techarticle MySQL 5.1 supports triggers and the features of the Custom Function interface (UDF), which, if mated with Libmemcache and memcached Functions for MySQL, enables automatic memcache updates. 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.