4 min

Nginx and Redis - Fall 2014

  1. http://www.nodex.co.uk/article/13-04-12/high-performance-caching-with-nginx-redis-and-php
  2. http://wiki.nginx.org/HttpRedis#Download
  3. https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/
  4. http://search.cpan.org/~dams/Redis-1.975/lib/Redis.pm
  5. http://redis.io/topics/data-types-intro
  6. http://serverfault.com/questions/227480/installing-optional-nginx-modules-with-apt-get

http://www.infoq.com/presentations/Real-Time-Delivery-Twitter


http://www.saltwebsites.com/2012/install-redis-245-service-centos-6

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04

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

http://redis.io/download

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 => 1

Check 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://redis.io/clients

http://stackoverflow.com/questions/17224585/using-redis-pm-pipeline-in-perl

PhP

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04

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.

Oct 6 2014

The Redis version that I'm using on my Digital Ocean Ubuntu account is version 2.2.12.

It's October 2014.

http://redis.io/download - 2.8.17 is the current stable version.

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis - updated in June 2014

I did: apt-get install tcl8.5

I enjoyed programming in TCL in the late 1990s. I used it for web programming and sys-admin utilities.

In late October and early November 2000, I attended a two-week programming bootcamp at ArsDigita, located in Cambridge, MA where we learned to build web apps, using the ArsDigita Community System, AOL Server (httpd), Oracle, and TCL. Good time. Something like this, except condensed: http://philip.greenspun.com/teaching/boot-camp

It's interesting that the Redis developer uses TCL for testing.

Security

https://github.com/NodeBB/NodeBB

It is important to ensure that your NodeBB and database servers are secured. Bear these points in mind:
  • While some distributions set up Redis with a more restrictive configuration, Redis by default listens to all interfaces, which is especially dangerous when a server is open to the public. Some suggestions:
    • Set bind_address to 127.0.0.1 so as to restrict access to the local machine only
    • Use requirepass to secure Redis behind a password (preferably a long one)
    • Familiarise yourself with Redis Security

Grebe-related Redis commands

Within the Redis client app for hash name or key called grebe.soupmode.com

Caching a page:

  • hset grebe.soupmode.com 123 "html text"
    • stores the html text for post id 123
  • hlen grebe.soupmode.com
    • shows a total number of pages cached for grebe.soupmode.com
  • hkeys grebe.soupmode.com
    • lists all the post id numbers that have html cached in redis
  • hdel grebe.soupmode.com 123
    • removes the cache page for post id 123
  • del grebe.soupmode.com
    • removes the entire cache of pages for grebe.soupmode.com

#blogging - #redis - #cache - #scalability

From JR's : articles
731 words - 6194 chars - 4 min read
created on
updated on - #
source - versions - backlinks



A     A     A     A     A

© 2013-2017 JotHut - Online notebook

current date: Apr 29, 2024 - 6:28 a.m. EDT