Justin Poliey

 
Filed under

redisent

 

A Redis Interface for Modest Developers

I wasn't really satisfied with the current PHP interface to Redis, so I wrote my own. If you don't know what Redis is, it's a distributed key-value store. It's different from memcached in that it's persistent, meaning that keys aren't lost when the server is shut down, and it supports abstract data types like lists and sets.

My implementation is called Redisent, and it's available on Github. I tried to make Redisent as small, simple, and intuitive as possible. To do so, I made all of the methods directly map to Redis protocol commands. Here's some simple example usage:

require 'redisent.php';
$redis = new Redisent('localhost');
$redis->set('awesome', 'absolutely');
echo sprintf('Is Redisent awesome? %s.\n', $redis->get('awesome'));

This bit of code sets a key, and then retrieves it.

Redisent also supports clustering of servers, and uses consistent hashing to distribute keys across servers in a way that will allow you to add and remove servers from the cluster without having most keys be remapped to different servers. To use clustering, use the RedisentCluster class:

require 'redisent_cluster.php';
$cluster = new RedisentCluster(array(
array('host' => '127.0.0.1', 'port' => 6379),
array('host' => '127.0.0.1', 'port' => 6380)
));

Now keys will be hashed and distributed to different servers, and the method names you use are exactly the same as the regular Redisent class. Not all Redis commands operate on keys though, some are server-specific. If you want to execute a command on a specific server, you can give a server an alias and then use the to($alias) method to execute the command on the server with the given alias.

require 'redisent_cluster.php';
$cluster = new RedisentCluster(array(
'alpha' => array('host' => '127.0.0.1', 'port' => 6379),
array('host' => '127.0.0.1', 'port' => 6380)
));
echo $cluster->to('alpha')->info();

Now the Redis server running on 127.0.0.1:6379 has the alias alpha, and you can route commands to it by using the to method. To see an example application using Redisent, the blog application distibuted with Tessera uses Redis as a datastore, and uses Redisent to interface with it.

Loading mentions Retweet
Filed under  //   php   redis   redisent   tessera  

Comments [1]

Tessera, a Fold-out Framework

The past couple of days I have been polishing a PHP framework that I had originally written for Rewindle, before it outgrew it and we switched to Cake. It's called Tessera, and it's everything I like about software: unintrusive, obvious, and lean. It's inspired by other so-called microframeworks like Web.py and Juno, and it's written in PHP.

An entire Tessera application is contained in a single class that is superclassed from the Tessera class. It's provided a list of routes, and those routes are mapped to methods inside of the application class. Routing supports named parameters, and the framework itself supports views and layouts to help your DRY up your code. Here's a little taste:

I wrote up as much documentation as I could before the first release, it's all on the wiki on the project page. Included in the source distribution is a bunch of test applications, and an example blog application using Redis as the datastore, and using Redisent to interface with it.

At any rate, I made this because I couldn't find a PHP framework that fit my definition of minimal (that wasn't PHP itself). Some of them are pretty small, yes, but not the bare essentials. Not all applications need an ORM, or a different templating engine. That doesn't mean that they won't, either, so Tessera provides one bit of functionality and then gets out of your way. Plus, if you really did need a bit of extra functionality, it's not hard to add a require statement to your application.

Loading mentions Retweet
Filed under  //   php   redis   redisent   tessera  

Comments [0]