Automatic update of MEMCACHE implementation code _php techniques with MySQL triggers

Source: Internet
Author: User
Tags memcached perl script

MySQL 5.1 supports triggers as well as custom function interface (UDF) features, and can implement memcache Automatic Updates if combined with Libmemcache and memcached functions for MySQL. Simply record the installation test steps.

Installation steps

    • Install memcached, this step is very simple, everywhere
    • Install MySQL server 5.1RC, installation method also very popular, no nonsense.
    • Compile libmemcached, after decompression installation can
      ./configure; make; make install
    • Compile memcached functions for MySQL, in http://download.tangent.org/ find an updated version of the download 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 get memcached functions for MySQL to take effect in MySQL

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


Testing Memcache function
The following test script is excerpted from the Memcached_functions_mysql source directory and is interested to try

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

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.