My experience in programming to not forget and maybe share something useful with others :)
Showing posts with label redis. Show all posts
Showing posts with label redis. Show all posts
Monday, November 14, 2011
How to restart Redis
To start or restart Redis from console:
/etc/init.d/redis-server {start|stop|restart|force-reload}
Also, on production you can do it more safely: http://redis.io/topics/admin
Saturday, July 2, 2011
My PHP-client for Redis
My PHP-client for Redis:
https://github.com/jamm/Memory/blob/master/RedisServer.php
And you can find this link here: http://redis.io/clients/#PHP
https://github.com/jamm/Memory/blob/master/RedisServer.php
And you can find this link here: http://redis.io/clients/#PHP
Thursday, June 30, 2011
Install Redis on Debian to use in PHP as a cacher
Installing
We need fresh version of Redis, so we have to add dotdeb-sources, if they are not there yet:
edit:
nano /etc/apt/sources.list
add lines:
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
get PGP-key:
cd /tmp
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -
and update:
apt-get update
And now let's install Redis:
apt-get install redis-server
Configuring
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();
We need fresh version of Redis, so we have to add dotdeb-sources, if they are not there yet:
edit:
nano /etc/apt/sources.list
add lines:
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
get PGP-key:
cd /tmp
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -
and update:
apt-get update
And now let's install Redis:
apt-get install redis-server
Configuring
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();
Monday, June 27, 2011
Redis in PHP Memory Cacher
New storage in PHP Memory Cacher: Redis
It's fast and stable.
Why Redis?
Because it's as fast as APC, data is accessible from php-cli and from mod_php (same as with using memcache), and all data are backed up on disk.
Last thing is very important - currently I store user's sessions in Redis and I don't afraid anymore to reboot my server.
Actually, backing up data on disk turns Redis from usual key-value storage to the BEST storage for data.
Why we love APC, Memcache as a key-value storages? Because they work fast. Especially APC.
What is their weak side? It's volatile storages because all data is stored in RAM only and RAM can be flushed easily. It's significant minus.
And Redis gives us pretty fast key-value storage (much faster than memcache) without that minus!
Even more: Redis has built-in abilities to work with lists, hashes, sets, even Pub/Sub channels. And it's not only "get/set" features, it's very useful and powerful features. So Redis can be used not only as a very fast key-value storage (even for canonical data), but as a database. We can work with data in different ways.
It's impresses me so much, my imagination is full of thoughts, how I can optimize data handling by using Redis - I'm going to write some kind of wrapper or ORM (don't know yet) in PHP to use Redis as database in my code. I use it already as a key-value cacher, but I want to move some data-algorithms from MySQL to Redis. I like MySQL (and SQL at all), but I know I can improve performance with Redis.
And already now you can check, how fast Redis works in my PHP Memory Cacher class :)
It's fast and stable.
Why Redis?
Because it's as fast as APC, data is accessible from php-cli and from mod_php (same as with using memcache), and all data are backed up on disk.
Last thing is very important - currently I store user's sessions in Redis and I don't afraid anymore to reboot my server.
Actually, backing up data on disk turns Redis from usual key-value storage to the BEST storage for data.
Why we love APC, Memcache as a key-value storages? Because they work fast. Especially APC.
What is their weak side? It's volatile storages because all data is stored in RAM only and RAM can be flushed easily. It's significant minus.
And Redis gives us pretty fast key-value storage (much faster than memcache) without that minus!
Even more: Redis has built-in abilities to work with lists, hashes, sets, even Pub/Sub channels. And it's not only "get/set" features, it's very useful and powerful features. So Redis can be used not only as a very fast key-value storage (even for canonical data), but as a database. We can work with data in different ways.
It's impresses me so much, my imagination is full of thoughts, how I can optimize data handling by using Redis - I'm going to write some kind of wrapper or ORM (don't know yet) in PHP to use Redis as database in my code. I use it already as a key-value cacher, but I want to move some data-algorithms from MySQL to Redis. I like MySQL (and SQL at all), but I know I can improve performance with Redis.
And already now you can check, how fast Redis works in my PHP Memory Cacher class :)
Subscribe to:
Posts (Atom)