You're viewing old version number 31. - Current version
Nginx and Redis - September 2014
- http://www.nodex.co.uk/article/13-04-12/high-performance-caching-with-nginx-redis-and-php
- http://wiki.nginx.org/HttpRedis#Download
- https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/
- http://search.cpan.org/~dams/Redis-1.975/lib/Redis.pm
- http://redis.io/topics/data-types-intro
http://www.saltwebsites.com/2012/install-redis-245-service-centos-6
http://eamann.com/tech/ludicrous-speed-wordpress-caching-with-redis
http://10up.com/blog/2012/eric-mann-joins-10up/
apt-get install redis-server
took only a few seconds to install
Online tutorial at http://try.redis.io
To access the command prompt client, type:
redis-cli
service redis-server stop
service redis-server start
/etc/init.d/redis-server restart
redis-server -t && service redis-server reload
set cleveland "browns"
get cleveland
delete cleveland
set counter 0
incr counter
get counter
setnx something "whatever" (sets a key only if it does not already exist)
A list is a series of ordered values. Some of the important commands for interacting with lists are RPUSH, LPUSH, LLEN, LRANGE, LPOP, and RPOP. You can immediately begin working with a key as a list, as long as it doesn't already exist as a different type.
Simple strings, sets and sorted sets already get a lot done but there is one more data type Redis can handle: Hashes.Hashes are maps between string fields and string values, so they are the perfect data type to represent objects (eg: A User with a number of fields like name, surname, age, and so forth):
HSET user:1000 name "John Smith"
HSET user:1000 email "john.smith@example.com"
HSET user:1000 password "s3cret"To get back the saved data use HGETALL:
HGETALL user:1000
You can also set multiple fields at once:
HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"
If you only need a single field value that is possible as well:
HGET user:1001 name => "Mary Jones"
Numerical values in hash fields are handled exactly the same as in simple strings and there are operations to increment this value in an atomic way.
HSET user:1000 visits 10
HINCRBY user:1000 visits 1 => 11
HINCRBY user:1000 visits 10 => 21
HDEL user:1000 visits
HINCRBY user:1000 visits 1 => 1Check the full list of Hash commands for more information.
Testing
# redis-cli
redis 127.0.0.1:6379> hset user:1 username "jr"
redis 127.0.0.1:6379> hset user:1 email "x@x.com"
redis 127.0.0.1:6379> hset user:1 desc "i like food"
redis 127.0.0.1:6379> exit
Create Perl script:
#!/usr/bin/perl -wT
use Redis;
## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379 per /etc/redis.conf
my $redis = Redis->new;
my $username = $redis->hget('user:1', 'username');
print "hello world $username\n";
http://redis.io/topics/data-types-intro
http://redis.io/topics/twitter-clone
demo: http://retwis.redis.io
source: https://code.google.com/p/redis/downloads/list
Perl
http://search.cpan.org/dist/Redis/
http://search.cpan.org/~dams/Redis-1.975/lib/Redis.pm
Sep 25, 2014 update: - executed perl -MCPAN -e 'install Redis'
and installed DAMS/Redis-1.975
http://search.cpan.org/~dpavlin/Redis-0.0801/lib/Redis.pm
https://github.com/PerlRedis/perl-redis
http://stackoverflow.com/questions/17224585/using-redis-pm-pipeline-in-perl
PhP
For MySQL
sudo apt-get install php5-mysql
For PhP
sudo apt-get install php5-fpm
Didn't do anything because apparently, it was already installed, but I don't remember when I did that, unless something else installed it. I assume the 'F' part is for FastCGI, and when I installed FastCGI, I guess it already installed this package.
Follow the instructions given at the above Digital Ocean web page for the PhP section.
#blogging - #redis - #cache - #scalability
From JR's : articles
456 words - 4095 chars
- 2 min read
created on
updated on
- #
source
- versions
Related articles
Nginx and Redis - Fall 2014 - Oct 17, 2014