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

Fix SET to work with NX flag does as expected #202

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ redis-mock

![Build status](https://github.com/yeahoffline/redis-mock/workflows/Build/badge.svg?branch=master)
![node-current](https://img.shields.io/node/v/redis-mock)
![mock-completeness](https://img.shields.io/badge/Methods%20mocked-46%25%20(222%2F482)-red)
![mock-completeness](https://img.shields.io/badge/Methods%20mocked-46%25%20(224%2F482)-red)
[![GitHub issues](https://img.shields.io/github/issues/yeahoffline/redis-mock)](https://github.com/yeahoffline/redis-mock/issues)

The goal of the `redis-mock` project is to create a feature-complete mock of [node_redis](https://github.com/NodeRedis/node_redis), which may be used interchangeably when writing unit tests for code that depends on `redis`.
Expand Down
7 changes: 5 additions & 2 deletions lib/server/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ exports.set = function (key, value, callback, args = {}) {
const keyExists = key in this.storage;
const expirationTime = getExpirationTime();

let response = 'OK';
if ((keyExists && args.xx) || (!keyExists && args.nx) || (!args.xx && !args.nx)) {
// it it's okay to set the value
this.storage[key] = createItem(value);
} else if (args.xx || args.nx) {
response = null;
}

if (expirationTime) {
this.expire(key, expirationTime, (err, result) => {
helpers.callCallback(callback, err, "OK");
helpers.callCallback(callback, err, response);
});
} else {
helpers.callCallback(callback, null, "OK");
helpers.callCallback(callback, null, response);
}
};

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redis-mock",
"version": "0.56.3",
"version": "0.56.4",
"description": "Redis client mock object for unit testing",
"author": "Kristian Faeldt <[email protected]>",
"main": "./lib/index",
Expand Down