Patrick Galbraith ([info]capttofu) wrote,
@ 2007-11-30 10:37:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:memcached, mysql

Memcached MySQL Functions Released!
The first initial Memcached MySQL UDF functions version has been released. You can download them at:

http://download.tangent.org/memcached_functions_mysql-0.1.tar.gz

Developed by Brian Aker and Patrick Galbraith, These are a number of MySQL user defined functions based on libmemcached (http://tangent.org/552/libmemcached.html) mirroring libmemcached client functions.

Included are:

memc_servers_set() - sets list of memcached servers to use

memc_set(hash, value) - sets a value keyed by hash in memcached
memc_get(hash) - retrieves a value from memcached keyed by hash
memc_delete() - deletes a value from memcached keyed by hash
memc_append() - appends to the end of a value in memcached keyed by hash
memc_prepend() - prepends to the beginning of a value in memcached keyed by hash
memc_increment() - increments numerical values stored in memcached (think sequence) keyed by hash
memc_decrement() - decrements numerical values stored in memcached keyed by hash
memc_replace() - replaces values with new values keyed by hash

What do these functions give you? The ability to either write to or read from memcached on read or write queries, within mysql. This means you could do something like this:

CREATE TABLE `jsoncache` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`memcache_key` varchar(32) DEFAULT NULL,
`json` mediumtext,
PRIMARY KEY (`id`)
)

mysql> delimiter | mysql> CREATE TRIGGER `jsoncache_trigger` BEFORE INSERT ON `jsoncache` FOR EACH ROW begin set @id= concat('jsoncache:', NEW.id); set @tt= memc_set(@id, NEW.json); set NEW.memcache_key = @id; end |
Query OK, 0 rows affected (0.05 sec)

mysql>delimiter ;

mysql> insert into jsoncache (json) values ('{{json stuff}}');
Query OK, 1 row affected (0.00 sec)

mysql> select * from jsoncache;

+----+--------------+----------------+
| id | memcache_key | json |
+----+--------------+----------------+
| 1 | jsoncache:1 | {{json stuff}} |
+----+--------------+----------------+
1 row in set (0.00 sec)

mysql> select memc_get('jsoncache:1');

+-------------------------+
| memc_get('jsoncache:1') |
+-------------------------+
| {{json stuff}} |
+-------------------------+
1 row in set (0.00 sec)

Wow! This is great, because now when you insert (write) to MySQL (in my case it would be to a master), you have that data automagically written to memcached!

You can either have a write-through or read-through way of writing data to memcached. I'm sure others will come up with other uses.



(Read 30 comments) - (Post a new comment)

My blog about health and wealth
(Anonymous)
2008-01-20 04:33 pm UTC (link)
Why you should buy viagr lawsuit?
First of all, if you buy us gneric viagra you get quality service and great discounts!
Why would you need pfizer viara?
Viagra in the first place make a uverenost, most of the problems are solved in the privacy of using our products. We will help you learn infinite possibilities in the intimate lives.
Why do you have to use our shop?
You pay only real value of the goods, without deductions resellers percent! Ordering pfier viagra us, you get free delivery and discounts on other products.
On our site you can order levtra. The lowest price. Large discounts. Full anonymity. Free shipping.
More info about viagra onlie you can be found on our website http://buy-viagra-online-pharmacy-in-canada.info/buy-cheap-viagra-online-now/bestellen-online-viagra.php

(Reply to this)


(Read 30 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…