Thursday, June 30, 2011

Install Redis on Debian to use in PHP as a cacher


We need fresh version of Redis, so we have to add dotdeb-sources, if they are not there yet:
nano /etc/apt/sources.list

add lines:
deb stable all
deb-src stable all

get PGP-key:
cd /tmp
cat dotdeb.gpg | apt-key add - 

and update:
apt-get update

And now let's install Redis:
apt-get install redis-server


Now we need to edit redis.conf:
nano /etc/redis/redis.conf 

First of all, we have to change default level of logging to warning, otherwise log will be filled up by useless lines very fast - new line each 5 seconds:
loglevel warning

Now, if you are going to use Redis as cacher, not as database, it will be good to set limit of allowed memory:
# 64M
maxmemory 67108864

of course, it's optional.

And now let's set size of allowed swap-file:
vm-pages 4194304
size of page is 32, so 4194304 * 32 =  134217728 = 128 Mb
I think it should be enough. I don't like idea of swapping at all, and size of swap on my server is 256Mb :) Also, I know that VPS OpenVZ usually are deployed with 0 swap.

Using as a cacher

To use Redis in PHP you need client.
You can use PHP Memory Cacher with built-in client for Redis.

It will be easy:
$cacher = new \Jamm\Memory\RedisObject(); 

1 comment:

  1. Article writing is also a excitement, if you know then you
    can write otherwise it is complex to write.

    Also visit my weblog - Advantages of making use of BRP therapy regarding gynecomastia