af83

redishttp - A simple php http proxy for redis

Well, this post explains the previous one.

I wanted to create a simple web proxy for redis.

It simply takes the url path and passes it to Redis, getting the response back either Raw or encoded in Json.

So I could use redis directly from javascript.

The rational behnid this is to get a “free” persistant key val store in javascript. see http://cplus.about.com/b/2010/11/07/openkeyval-an-online-datastore.htm

On the choice of redisent see http://dev.af83.com/redis/which-php-library-use-redis/2010/12/30

Using it is as simple as :


$redishttp= new RedisHTTP();
echo json_encode(RedisHTTP::run());

So simply visiting http://localhost/redis/set/Hello/world

Will Set the key “Hello” to the value “World”

Visiting http://localhost/redis/get/Hello

Will output:


World

BTW, You should probably have a Redis instance running...

Visiting http://localhost/redis/flushdb will destory your redis data in the first database. All of it. Without ever asking for any kind of confirmation.

Visiting http://localhost/redis/flashall will destory all your redis data. All of it. Without ever asking for any kind of confirmation.

All of Redis methods are supported. So you can use for example http://localhost/redis/info to monitor your redis server

you can set the redis host and port with $redishttp= new RedisHTTP(‘localhost, 6379);

Note: there is no state on the server side. So each command you send is a new connection; This is mostly important so you understand: No piping, and select will basically do nothing

Below is a simple ajax form that sends commands to redis and shows the result seperate the commands and the parameters by a forward slash

examples (just type this in the input box below):

  • info
  • set/hello/world
  • get/hello

Fork happily on https://github.com/AF83/redishttp

blog comments powered by Disqus