yeahoffline / redis-mock

Node.js redis client mock
212 stars 110 forks source link

Added Support for custom commands #200

Open harrytwright opened 2 years ago

harrytwright commented 2 years ago

Overview

A workaround using the premise of #163 to add custom commands. Comes with updated tests, but haven't ran it against the new node-redis

Usage

var redis = require("redis-mock")

redis.addMockCommand('json.set', (client, args, callback) => {
  // your logic here
  client.set(args[0], JSON.stringify(args[2]), callback)
})

// In your app
redis.addCommand('json.set')

var client = redis.createClient()
client.json_set('key', '.', { json: 'value' }, redis.print) // 0 'OK'