Home

Awesome

clue/redis-server Build Status

A Redis server implementation in pure PHP. Not for the faint-hearted.

Note: This project is in early alpha stage! Feel free to report any issues you encounter.

Introduction

Motivation

Redis is a fast in-memory key-value database. This project aims to provide a simple alternative to the official Redis server implementation if installing it is not an option.

Why would I use this project if I already have the official Redis server installed? Simply put, you wouldn't. Ever.

Project goals

Supported commands

Eventually, this project aims to replicate all commands of the official Redis server implementation and their exact behavior.

So far, the following list of commands shows what's already implemented:

For details, refer to the excellent official documentation of Redis commands.

All available commands are expected to behave just like their counterparts in Redis v2.6+, unless otherwise noted. If you find a command to misbehave, don't hesitate to file a bug.

Obviously, this list is incomplete in that it does not include every command supported by Redis. If you find a command is missing, please submit a PR :)

Benchmarking performance

As usual, just about every benchmark is biased - you've been warned.

You can use the redis-benchmark script that is included when installing the official Redis server.

$ redis-benchmark -p 1337 -q

Some benchmarking results:

# official redis-server
$ redis-server --port 1338
$ redis-benchmark -t set,get -p 1338 -q
SET: 121951.22 requests per second
GET: 151515.16 requests per second

# clue/redis-server PHP 5.5
$ php bin/redis-server.php
$ redis-benchmark -t set,get -p 1337 -q
SET: 18761.73 requests per second
GET: 22172.95 requests per second

# clue/redis-server HHVM
$ hhvm -vEval.Jit=true bin/redis-server.php
$ redis-benchmark -t set,get -p 1337 -q
SET: 49019.61 requests per second
GET: 57142.86 requests per second

So depending on your configuration, expect the original implementation to be 2x to 5x as fast. Some thoughts that have a significant effect on the performance:

Quickstart example

Once installed, you can start the Redis server by running the provided bin file:

$ php bin/redis-server.php

Alternatively, you can also use this project as a lib in order to build your own server like this:

$factory = new Factory($loop);
$factory->createServer('localhost:1337')->then(function (Server $server) use ($loop) {
    $server->on('connection', function(Client $client) {
        echo $client->getRemoteAddr() .' connected' . PHP_EOL;    
    });
});

$loop->run();

Install

The recommended way to install this library cloning this repo and installing its dependencies through composer. New to composer?

$ sudo apt-get install php5-cli git curl
$ git clone https://github.com/clue/php-redis-server.git
$ cd php-redis-server/
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install

Docker

This project is also available as a docker image. Using the clue/php-redis-server image is as easy as running this:

$ docker run -d clue/php-redis-server

License

MIT