Skip to content

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 <[email protected]>
I'm a dick, the end

Signed-off-by: harrytwright <[email protected]>
Signed-off-by: harrytwright <[email protected]>
Bring the code back inline with the original

Signed-off-by: harrytwright <[email protected]>
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.

1 participant