Install Memcached with Rails

To Install Memcached and use it with rails

Install libevent first :

curl -O http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar xzvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --prefix=/usr/local
make
make verify
sudo make install


install memcached

curl -O http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
$ tar xzvf memcached-1.4.4.tar.gz
$ cd memcached-1.4.4
$ ./configure --prefix=/usr/local
$ make
$ make test
$ sudo make install


Run Memcached by default (with 64mb ram)

memcached

Run Memcached in verbose mode

memcached -vv

Run memcached as a daemon with pidfile on specific ip

memcached -d -P pidfile -l 127.0.0.1

To Stop Memcached

killall memcached


To connect memcached with rails, i using gem called memcached, install it by calling

sudo gem install memcached

to use it with rails, just add rails environment.rb

require "memcached"
CACHE = Memcached.new('127.0.0.1')

Using memcached by calling the CACHE variabel, example :

CACHE.set('name','bobby')
CACHE.get('name')

Thats all, hope that helps

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s