Skip to content

Commit

Permalink
Fix missing scripts error
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed Aug 13, 2018
1 parent e261a09 commit f394ca3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions bottleneck.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
this.client = redis.createClient(this.clientOptions);
this.subClient = redis.createClient(this.clientOptions);
this.pubsubs = {};
this.shas = {};
this.loaded = false;
this.ready = new this.Promise((resolve, reject) => {
var count, done, errorListener;
Expand Down Expand Up @@ -1184,7 +1185,6 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
this.initSettings = initSettings;
this.originalId = this.instance.id;
parser.load(options, options, this);
this.shas = {};
this.isReady = false;
this.connection = (ref = this._groupConnection) != null ? ref : new RedisConnection(this.clientOptions, this.Promise, this.instance.Events);
this.ready = this.connection.ready.then(clients => {
Expand Down Expand Up @@ -1236,7 +1236,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
if (err != null) {
return reject(err);
}
this.shas[name] = replies[0];
this.connection.shas[name] = replies[0];
return resolve(replies[0]);
});
});
Expand All @@ -1250,7 +1250,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
keys = Scripts.keys(name, this.originalId);
return new this.Promise((resolve, reject) => {
var arr;
arr = [this.shas[name], keys.length].concat(keys, args, function (err, replies) {
arr = [this.connection.shas[name], keys.length].concat(keys, args, function (err, replies) {
if (err != null) {
return reject(err);
}
Expand Down
2 changes: 1 addition & 1 deletion bottleneck.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/RedisConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
this.client = redis.createClient(this.clientOptions);
this.subClient = redis.createClient(this.clientOptions);
this.pubsubs = {};
this.shas = {};
this.loaded = false;
this.ready = new this.Promise((resolve, reject) => {
var count, done, errorListener;
Expand Down
5 changes: 2 additions & 3 deletions lib/RedisStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
this.initSettings = initSettings;
this.originalId = this.instance.id;
parser.load(options, options, this);
this.shas = {};
this.isReady = false;
this.connection = (ref = this._groupConnection) != null ? ref : new RedisConnection(this.clientOptions, this.Promise, this.instance.Events);
this.ready = this.connection.ready.then(clients => {
Expand Down Expand Up @@ -75,7 +74,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
if (err != null) {
return reject(err);
}
this.shas[name] = replies[0];
this.connection.shas[name] = replies[0];
return resolve(replies[0]);
});
});
Expand All @@ -89,7 +88,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
keys = Scripts.keys(name, this.originalId);
return new this.Promise((resolve, reject) => {
var arr;
arr = [this.shas[name], keys.length].concat(keys, args, function (err, replies) {
arr = [this.connection.shas[name], keys.length].concat(keys, args, function (err, replies) {
if (err != null) {
return reject(err);
}
Expand Down
1 change: 1 addition & 0 deletions src/RedisConnection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class RedisConnection
@client = redis.createClient @clientOptions
@subClient = redis.createClient @clientOptions
@pubsubs = {}
@shas = {}
@loaded = false

@ready = new @Promise (resolve, reject) =>
Expand Down
6 changes: 2 additions & 4 deletions src/RedisStorage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ BottleneckError = require "./BottleneckError"
RedisConnection = require "./RedisConnection"
Scripts = require "./Scripts"


class RedisStorage
constructor: (@instance, @initSettings, options) ->
@originalId = @instance.id
parser.load options, options, @
@shas = {}
@isReady = false

@connection = @_groupConnection ? new RedisConnection @clientOptions, @Promise, @instance.Events
Expand Down Expand Up @@ -38,15 +36,15 @@ class RedisStorage

@clients.client.multi([["script", "load", payload]]).exec (err, replies) =>
if err? then return reject err
@shas[name] = replies[0]
@connection.shas[name] = replies[0]
return resolve replies[0]

runScript: (name, args) ->
if !@isReady then @Promise.reject new BottleneckError "This limiter is not done connecting to Redis yet. Wait for the '.ready()' promise to resolve before submitting requests."
else
keys = Scripts.keys name, @originalId
new @Promise (resolve, reject) =>
arr = [@shas[name], keys.length].concat keys, args, (err, replies) ->
arr = [@connection.shas[name], keys.length].concat keys, args, (err, replies) ->
if err? then return reject err
return resolve replies
@instance.Events.trigger "debug", ["Calling Redis script: #{name}.lua", args]
Expand Down

0 comments on commit f394ca3

Please sign in to comment.