Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

redis-raw

0.0.1 • Public • Published

    __      ___      ___   / ( )  ___            __      ___                 
  //  ) ) //___) ) //   ) / / / ((   ) ) ____  //  ) ) //   ) ) //  / /  / / 
 //      //       //   / / / /   \ \          //      //   / / //  / /  / /  
//      ((____   ((___/ / / / //   ) )       //      ((___( ( ((__( (__/ /   

RedisRaw

A simple redis client

I wrote this because the other available nodejs redis clients where not correct enough for me.

RedisRaw handles all commands, (including P?UNSUBSCRIBE) with callbacks consistant to the nodejs way.

create a new client

redis-raw.Redis takes the same arguments as net.createConnection.
returns a redis client, callback is optional.

  var Redis = require('redis-raw').Redis
    , r = Redis(port, host, callback)

.req(command, callback)

  r.req(['GET', key, value], function (err, reply) {...})

command must be an array of strings.
commands are described in the redis documentation

reply may be a primitive or an array. if err is from redis, err will be a string.

If there is a unexpected disconnection,
all callbacks that have not been answered will get an error.

  • RedisRaw does not stringify objects for you. do your own json

Pub Sub

SUBSCRIBE & PSUBSCRIBE

when redis gets a [SUBSCRIBE]((http://redis.io/commands/subscribe) or PSUBSCRIBE command,
it goes into subscribe mode and non Pub/Sub commands will callback an error.

UNSUBSCRIBE & PUNSUBSCRIBE

calls to [UNSUBSCRIBE]((http://redis.io/commands/unsubscribe) [PUNSUBSCRIBE]((http://redis.io/commands/punsubscribe) will callback (error, [events, subscriptionCount])

where events is the list of events that you have unsubscribed to.

redis has strange behavior with the handling of these commands, and may reply many times.
however, RedisRaw keeps it's own count of subscriptions, and will callback only once, in the normal nodejs way.
(it was my frustration with other redis clients on this matter that decided me to write this package)
i've opened an issue about this here: https://github.com/antirez/redis/issues/123

.onMessage & .onPMessage

capture messages that you are subscribed to by overwriting redis.onMessage and redis.onPMessage see http://redis.io/topics/pubsub

 
var Redis = require('redis-raw').Redis
  , r = Redis(port, host, callback)
 
r.req(['PSUBSCRIBE', '*'], function () {...})
 
r.onMessage = function (event, message) {...}
r.onPMessage = function (event, pattern, message) {...}
 

PSUBSCRIBE supports all standard [glob patterns](http://en.wikipedia.org/wiki/Glob_(programming)).

'error', 'close', .end() and .destroy()

redis raw does not manage the connection for you,
Users should directly access the underlieing net.Socket
and add listeners and end or destroy the connection there.

var Redis = require('redis-raw').Redis
  , r = Redis(port, host, callback)
 
r.socket.on('close',function () {...})
r.socket.destroy()

(also, you can let the server close the connection r.req(['QUIT'], callback))

Keywords

none

install

npm i redis-raw

Downloadsweekly downloads

0

version

0.0.1

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability