npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

respjs

v4.2.0

Published

An implementation of REdis Serialization Protocol (RESP).

Downloads

47,485

Readme

RESP.js

An implementation of REdis Serialization Protocol (RESP).

NPM version Build Status Downloads

Rust version: https://github.com/iorust/resp

Golang version: https://github.com/teambition/respgo

Implementations:

Install

Install with npm

npm install respjs

Usage

simple redis client (with test): https://github.com/zensh/resp.js/blob/master/example/redis_client.js

Run:

npm run example

API

const Resp = require('respjs')

Class Resp

new Resp([options])

Resp is a EventEmitter similar to Writable stream. It accept pipelining socket chunks, parse them, produce redis response data. Readable stream can be piped to resp.

  • options {Object}
  • bufBulk {Boolean} return buffers for bulk reply, default to false
const resp = new Resp({
  bufBulk: true
})

resp.write(chunk)

Feed chunk and parse it. resp will emit data event while a integrated data decoded.

resp.end([chunk])

Call this method when no more chunk will be written to bufsp, then finish event emit.

Event: 'error'

  • error {Error}

Emitted when an error occurs.

Event: 'data'

  • data {Mixed}

Emitted when redis response data produced.

Event: 'drain'

Emitted when chunk have been parsed or need more chunks for parsing.

Event: 'finish'

The finish event is fired after .end() is called and all chunks have been processed.

Class Method: Resp.decode(buffer, bufBulk)

Decode RESP's buffer to RESP value.

Resp.decode(Resp.encodeNull()) // null
Resp.decode(Resp.encodeString('123')) // '123'
Resp.decode(Resp.encodeInteger(123)) // 123
Resp.decode(Resp.encodeBulk(123)) // '123'

Class Method: Resp.encodeRequest([value, ...])

Encode a array of value to one RESP buffer. It is usefull to encode a request.

let buf = Resp.encodeRequest(['set', 'key', 123])
// <Buffer 2a 33 0d 0a 24 33 0d 0a 73 65 74 0d 0a 24 33 0d 0a 6b 65 79 0d 0a 24 33 0d 0a 31 32 33 0d 0a>
let str = buf.toString() // *3\r\n$3\r\nset\r\n$3\r\nkey\r\n$3\r\n123\r\n

Resp.encodeRequest(['set', 'key', new Buffer('123')]) // support buffer!

Class Method: Resp.encodeNull()

Encode RESP's Null value to RESP buffer.

let buf = Resp.encodeNull() // <Buffer 24 2d 31 0d 0a>
let str = buf.toString() // $-1\r\n

Class Method: Resp.encodeNullArray()

Encode RESP's Null Array value to RESP buffer.

let buf = Resp.encodeNull() // <Buffer 2a 2d 31 0d 0a>
let str = buf.toString() // *-1\r\n

Class Method: Resp.encodeString(str)

Encode string to RESP buffer.

let buf = Resp.encodeString('OK') // <Buffer 2b 4f 4b 0d 0a>
let str = buf.toString() // +OK\r\n

Class Method: Resp.encodeError(error)

Encode error object to RESP buffer.

let buf = Resp.encodeError(new Error('error')) // <Buffer 2d 45 72 72 6f 72 20 65 72 72 6f 72 0d 0a>
let str = buf.toString() // -Error error\r\n

Class Method: Resp.encodeInteger(num)

Encode integer to RESP buffer.

let buf = Resp.encodeInteger(123) // <Buffer 3a 31 32 33 0d 0a>
let str = buf.toString() // :123\r\n

Class Method: Resp.encodeBulk(str)

Encode RESP's bulk string to RESP buffer.

let buf = Resp.encodeBulk('message') // <Buffer 24 37 0d 0a 6d 65 73 73 61 67 65 0d 0a>
let str = buf.toString() // $7\r\nmessage\r\n

Class Method: Resp.encodeBufBulk(buf)

Encode RESP's bulk buffer to RESP buffer.

let buf = Resp.encodeBufBulk(new Buffer('buf')) // <Buffer 24 33 0d 0a 62 75 66 0d 0a>
let str = buf.toString() // $3\r\nbuf\r\n

Class Method: Resp.encodeArray([RESP_buffer, ...])

Encode a array of RESP' value buffer to one RESP buffer.

let buf = Resp.encodeArray([Resp.encodeNull(), Resp.encodeString('OK')])
// <Buffer 2a 32 0d 0a 24 2d 31 0d 0a 2b 4f 4b 0d 0a>
let str = buf.toString() // *2\r\n$-1\r\n+OK\r\n

License

MIT © zensh