Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for custom commands #200

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

harrytwright
Copy link

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'

When using a redis plugin like ReJSON this wouldn't work as the mock was just built around the basic functionality of redis itself, so by adding an 'addMockCommand' and allowing the user to add their own functionality built around the basic redis code will help any tests

TODO:
  - [ ] More testing
  - [ ] Clean up the code
  - [ ] Submit PR
When seeing if the concept would work I built the '.addCommand' inside the Client and not globally, which would cause issues with comparability, something I should have remembered since I spent a lot of time last year going through NodeRedis' source. This has now lead me on a rabbit hole dive with some ideas with slightly nicer functionality of adding commands, and how ArgumentParser could be leveraged to assert the args when they come in too, so a user can trust that we will test everything as best we can

TODO:
  - [ ] More testing
  - [x] Clean up the code
  - [ ] Submit PR
Signed-off-by: harrytwright <haroldtomwright@gmail.com>
I'm a dick, the end

Signed-off-by: harrytwright <haroldtomwright@gmail.com>
Signed-off-by: harrytwright <haroldtomwright@gmail.com>
Bring the code back inline with the original

Signed-off-by: harrytwright <haroldtomwright@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant