memcachedをWindows Web Server 2008にインストールする.

スキルチャージプログラムなサーバーにmemcachedをインストールしてみる.


Windows Web Server 2008は,名前のとおりWindowsなので,Windowsバイナリをダウンロードしてくる.

http://jehiah.cz/projects/memcached-win32/


既に上記ページにインストール方法が書いてあるので,ちょっと訳してみる.
Windowsなのでサービスインストールする必要がある.


  1. Unzip the binaries in your desired directory (eg. c:\memcached)
  2. Install the service using the command: 'c:\memcached\memcached.exe -d install' from either the command line
  3. Start the server from the Microsoft Management Console or by running the following command: 'c:\memcached\memcached.exe -d start'
  4. Use the server, by default listening to port 11211


特に難しいことはなさげ.

  1. 目的のディレクトリにZIPファイルを展開するよ → 例えば c:\memcached とかね
  2. 次のコマンドでサービスをインストールするよ → c:\memcached\memcached.exe -d install
  3. サービスを管理コンソールから起動するよ → c:\memcached\memcached.exe -d start
  4. デフォルトポートは11211なのですよ!


この通りにインストールしてみる.


まずはダウンロード.

memcached-1.2.1-win32.zip


ダウンロードしてきたファイルを

c:\Program Files (x86)\memcached-1.2.1-win32

に展開してみた.んで

c:\Program Files (x86)\memcached-1.2.1-win32\memcached.exe -d install

でインストール.さらに

c:\Program Files (x86)\memcached-1.2.1-win32\memcached.exe -d start

でサービス開始なのですよ.


動いていることを確認する.
Rubyで使いたかったので,Rubyで書く書く.
とりあえずmemcacheをRequireしなくちゃいけないらしいので

gem install memcache-client

と実行してみる.
それからいざ,Rubyのコードを書きます.


memcachedに追加する場合.

require "memcache"

cache = MemCache::new 'localhost:11211'

cache["robot"] = "Iroha Liner"
cache["college"] = "Oyama"


読み込む場合

require "memcache"

cache = MemCache::new 'localhost:11211'

puts cache["robot"]
puts cache["college"]


ほんと超簡単.
memcachedとmemcache-clientに感謝!