MySQL に memcached プロトコルサポートを追加してみる
ソース: http://coderepos.org/share/browser/platform/mysql/mycached/
例によって UDF (笑) として書いてみてるところ *1。
大体2倍速。対応してるのは gets? コマンドのみ、かつ、INT 系のプライマリキーのルックアップのみ。
こんな感じで動いてる。
$ echo 'select mycached_start(0,12345)' | mysql -u root && telnet localhost 12345 mycached_start(0,12345) 0 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. gets test.t1.1 VALUE test.t1.1 0 72 {"id":1,"message":"hello world! hello world! hello world! hello world!"} END ^] telnet> quit Connection closed. $
mysql で SELECT した場合と同じ結果が見えてる。
mysql> select * from t1 where id=1; +----+-----------------------------------------------------+ | id | message | +----+-----------------------------------------------------+ | 1 | hello world! hello world! hello world! hello world! | +----+-----------------------------------------------------+ 1 row in set (0.00 sec)
あとやらなきゃなんないのは、libevent ベースの実装に直すこと。
なんでそんなことやってるかとか考察とかはあとで考える。
*1:UDF だとリンク時間が節約できるのがいいw