William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Tag Archives: Redis

CouchDB vs. Redis

CouchDB vs. Redis

I installed CouchDB, ZeroMQ in my MacBook Air, with the usages of XCode 5, brew.
The following are some helpful articles:

Is CouchDB The Anti-Redis?

CouchDB 的长处正是Redis的短处:存储大量的不易变但会被经常查询的数据。Redis的长处正是CouchDB的短处:存储小量的常变数据。

IndexedDB -> CouchDB
localStorage -> Redis
Web Workers -> node promises/delay

PHP and Redis Server

PHP and Redis Server

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Redis server can be used as a session handler, which is especially useful if you are using a multi-server architecture behind a load balancer.
Redis also has a publish/subscribe system, which is great for creating an online chat or a live booking system.
I used Redis server with NodeJS before; however and definitely, Redis Server is also available for PHP. Here is a helpful article:


The following are the steps to install Redis-server, and make it work in PHP.

//1. install redis-server
wget http://redis.googlecode.com/files/redis-2.2.4.tar.gz
tar -zxf redis-2.2.4.tar.gz
cd redis-2.2.4
sudo make install

//2. run it, sumple way, you can also use: 
//sudo update-rc.d redis-server defaults to make it run when start.
$ /usr/local/bin/redis-server &

Now Redis server is done. After that, we make it work with PHP.
For PHP, Redis client library is Predis, we can get the sources from github:

$ git clone git://github.com/nrk/predis.git

After install Redis server and Predis interface, we now use PHP to connect and operate the session server. A testing example like this:

require "predis/autoload.php";

// since we connect to default setting localhost
// and 6379 port there is no need for extra
// configuration. If not then you can specify the
// scheme, host and port to connect as an array
// to the constructor.
try {
    $redis = new Predis\Client();
    $redis = new Predis\Client(array(
        "scheme" => "tcp",
        "host" => "",
        "port" => 6379));
    echo "Successfully connected to Redis";
catch (Exception $e) {
    echo "Couldn't connected to Redis";
    echo $e->getMessage();

Pretty simple, and should return ‘Successfully connected to Redis’. A more test for Redis key-value store is like this:

$redis->set("any_key", "Hi Redis for php by using predis!");
$value = $redis->get("any_key");