Comparing version 4.15.1 to 4.16.0
@@ -435,4 +435,5 @@ "use strict"; | ||
if (to !== "master") { | ||
const isCommandReadOnly = commands.exists(command.name) && | ||
commands.hasFlag(command.name, "readonly"); | ||
const isCommandReadOnly = command.isReadOnly || | ||
(commands.exists(command.name) && | ||
commands.hasFlag(command.name, "readonly")); | ||
if (!isCommandReadOnly) { | ||
@@ -439,0 +440,0 @@ to = "master"; |
@@ -56,2 +56,5 @@ "use strict"; | ||
} | ||
if (options.readOnly) { | ||
this.isReadOnly = true; | ||
} | ||
} | ||
@@ -58,0 +61,0 @@ static getFlagMap() { |
@@ -68,6 +68,7 @@ "use strict"; | ||
* @param {number} [definition.numberOfKeys=null] - the number of keys. | ||
* @param {boolean} [definition.readOnly=false] - force this script to be readonly so it executes on slaves as well. | ||
* If omit, you have to pass the number of keys as the first argument every time you invoke the command | ||
*/ | ||
Commander.prototype.defineCommand = function (name, definition) { | ||
var script = new script_1.default(definition.lua, definition.numberOfKeys, this.options.keyPrefix); | ||
var script = new script_1.default(definition.lua, definition.numberOfKeys, this.options.keyPrefix, definition.readOnly); | ||
this.scriptsSet[name] = script; | ||
@@ -74,0 +75,0 @@ this[name] = generateScriptingFunction(script, "utf8"); |
@@ -8,6 +8,7 @@ "use strict"; | ||
class Script { | ||
constructor(lua, numberOfKeys = null, keyPrefix = "") { | ||
constructor(lua, numberOfKeys = null, keyPrefix = "", readOnly = false) { | ||
this.lua = lua; | ||
this.numberOfKeys = numberOfKeys; | ||
this.keyPrefix = keyPrefix; | ||
this.readOnly = readOnly; | ||
this.sha = crypto_1.createHash("sha1") | ||
@@ -24,2 +25,5 @@ .update(lua) | ||
} | ||
if (this.readOnly) { | ||
options.readOnly = true; | ||
} | ||
const evalsha = new command_1.default("evalsha", [this.sha].concat(args), options); | ||
@@ -26,0 +30,0 @@ evalsha.isCustomCommand = true; |
@@ -0,1 +1,8 @@ | ||
# [4.16.0](https://github.com/luin/ioredis/compare/v4.15.1...v4.16.0) (2020-02-19) | ||
### Features | ||
* ability force custom scripts to be readOnly and execute on slaves ([#1057](https://github.com/luin/ioredis/issues/1057)) ([a24c3ab](https://github.com/luin/ioredis/commit/a24c3abcf4013e74e25424d2f6b91a2ae0de12b5)) | ||
## [4.15.1](https://github.com/luin/ioredis/compare/v4.15.0...v4.15.1) (2019-12-25) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "ioredis", | ||
"version": "4.15.1", | ||
"version": "4.16.0", | ||
"description": "A robust, performance-focused and full-featured Redis client for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "built/index.js", |
@@ -79,19 +79,28 @@ [![ioredis](https://cdn.jsdelivr.net/gh/luin/ioredis@b5e8c74/logo.svg)](https://github.com/luin/ioredis) | ||
```javascript | ||
var Redis = require("ioredis"); | ||
var redis = new Redis(); | ||
const Redis = require("ioredis"); | ||
const redis = new Redis(); // uses defaults unless given configuration object | ||
redis.set("foo", "bar"); | ||
// ioredis supports all Redis commands: | ||
redis.set("foo", "bar"); // returns promise which resolves to string, "OK" | ||
// the format is: redis[SOME_REDIS_COMMAND_IN_LOWERCASE](ARGUMENTS_ARE_JOINED_INTO_COMMAND_STRING) | ||
// the js: ` redis.set("mykey", "Hello") ` is equivalent to the cli: ` redis> SET mykey "Hello" ` | ||
// ioredis supports the node.js callback style | ||
redis.get("foo", function(err, result) { | ||
console.log(result); | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log(result); // Promise resolves to "bar" | ||
} | ||
}); | ||
redis.del("foo"); | ||
// Or using a promise if the last argument isn't a function | ||
// Or ioredis returns a promise if the last argument isn't a function | ||
redis.get("foo").then(function(result) { | ||
console.log(result); | ||
console.log(result); // Prints "bar" | ||
}); | ||
// Arguments to commands are flattened, so the following are the same: | ||
redis.sadd("set", 1, 3, 5, 7); | ||
redis.sadd("set", [1, 3, 5, 7]); | ||
// Most responses are strings, or arrays of strings | ||
redis.zadd("sortedSet", 1, "one", 2, "dos", 4, "quatro", 3, "three") | ||
redis.zrange("sortedSet", 0, 2, "WITHSCORES").then(res => console.log(res)); // Promise resolves to ["one", "1", "dos", "2", "three", "3"] as if the command was ` redis> ZRANGE sortedSet 0 2 WITHSCORES ` | ||
@@ -836,17 +845,17 @@ // All arguments are passed directly to the redis server: | ||
```javascript | ||
function (times) { | ||
var delay = Math.min(100 + times * 2, 2000); | ||
return delay; | ||
} | ||
``` | ||
```javascript | ||
function (times) { | ||
var delay = Math.min(100 + times * 2, 2000); | ||
return delay; | ||
} | ||
``` | ||
It's possible to modify the `startupNodes` property in order to switch to another set of nodes here: | ||
It's possible to modify the `startupNodes` property in order to switch to another set of nodes here: | ||
```javascript | ||
function (times) { | ||
this.startupNodes = [{ port: 6790, host: '127.0.0.1' }]; | ||
return Math.min(100 + times * 2, 2000); | ||
} | ||
``` | ||
```javascript | ||
function (times) { | ||
this.startupNodes = [{ port: 6790, host: '127.0.0.1' }]; | ||
return Math.min(100 + times * 2, 2000); | ||
} | ||
``` | ||
@@ -853,0 +862,0 @@ - `dnsLookup`: Alternative DNS lookup function (`dns.lookup()` is used by default). It may be useful to override this in special cases, such as when AWS ElastiCache used with TLS enabled. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
243701
4224
1182