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...