redis-json-client

0.2.9 • Public • Published

RedisJSON-Client

GitHub npm

Redis에서 JSON타입을 직접 사용할 수 있게 만들어주는 RedisJSON의 NodeJS 클라이언트

(https://github.com/RedisJSON/RedisJSON)

Compatibility

RedisJSON / All Command Support

RedisJSON2 / Not Confirmed

Quick Start

Installation

npm install redis-json-client

Basic Usage

const RedisJSONClient = require('redis-json-client')

const opts = {
  ports: 6379,
  hosts: '127.0.0.1',
  db: 0,
  password: 'password'
}

or

const opts = "/tmp/redis.sock"

const client = new RedisJSONClient(opts)

// Redis 연결
client.connect()
  .then(_ => {
    // 데이터 저장 (부모가 존재하지 않으면 생성)
    client.set('key', 'path.a.b', {alpha: 'beta'}, {recursive: true})
      .then(_ => {
        // 데이터 불러오기
        client.get('key', 'path.a.b.alpha')
          .then(json => {
            console.log(json)
          })      
      })  
  })
  .catch(err => {
    console.error(err)
    process.exit()  
  })

Command Examples

JSON.GET

client.get(key, path)
  .then(json)
  .catch(err)

JSON.SET

client.set(key, path, value, { recursive: true })
  .then(result)
  .catch(err)

JSON.DEL

client.del(key, path)
  .then(result)
  .catch(err)

JSON.FORGOT

client.forgot(key, path)
  .then(result)
  .catch(err)

JSON.TYPE

client.type(key, path)
  .then(type)
  .catch(err)

JSON.MGET

client.mget(keys, path)
  .then(json)
  .catch(err)

JSON.NUMINCRBY

client.inc(key, path, value)
  .then(json)
  .catch(err)

JSON.NUMMULTBY

client.mul(key, path, value)
  .then(json)
  .catch(err)

JSON.STRAPPEND

client.strand(key, path, value)
  .then(length)
  .catch(err)

JSON.STRLEN

client.strlen(key, path)
  .then(length)
  .catch(err)

JSON.ARRAPPEND

client.arrand(key, path, values)
  .then(size)
  .catch(err)

JSON.ARRINDEX

client.arridx(key, path, value)
  .then(index)
  .catch(err)

JSON.ARRINSERT

client.arrins(key, path, index, values)
  .then(size)
  .catch(err)

JSON.ARRLEN

client.arrlen(key, path)
  .then(size)
  .catch(err)

JSON.ARRPOP

client.arrpop(key, path, [index])
  .then(json)
  .catch(err)

JSON.ARRTRIM

client.arrtrim(key, path, start, end)
  .then(size)
  .catch(err)

JSON.OBJKEYS

client.objkeys(key, path)
  .then(json)
  .catch(err)

JSON.OBJLEN

client.objlen(key, path)
  .then(size)
  .catch(err)

JSON.DEBUG

client.debug(args)
  .then(json)
  .catch(err)

JSON.RESP

client.resp(args)
  .then(json)
  .catch(err)

License

MIT

Package Sidebar

Install

npm i redis-json-client

Weekly Downloads

7

Version

0.2.9

License

MIT

Unpacked Size

22.4 kB

Total Files

6

Last publish

Collaborators

  • map_side