Skip to content

Commit

Permalink
Use string key if getRangeBuffer is available (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
heri16 authored Jun 7, 2018
1 parent 4b0b615 commit 144ea68
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/redis-rstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function RedisRStream(client, key, options) {
if (!(this instanceof RedisRStream)) return new RedisRStream(client, key, options);
Readable.call(this, options);
this._redisClient = client;
this._redisKey = new Buffer(key); // using Buffer key so redis returns buffers
this._redisKey = !!client.getrangeBuffer ? key : new Buffer(key); // using Buffer key so redis returns buffers
this._redisChunkSize = (options && options.chunkSize) ? options.chunkSize : 64 * 1024; // default 64KB
this._redisMaxPendingReads = (options && options.maxPendingReads) ? options.maxPendingReads : 2;
this._redisOffset = (options && options.startOffset) ? options.startOffset : 0;
Expand All @@ -23,7 +23,6 @@ function RedisRStream(client, key, options) {
this._redisLength = 0;
this._redisEnded = false;
this._redisPendingReads = 0;
this._redisHasSuffixBufferAPI = !!client.getrangeBuffer
}

util.inherits(RedisRStream, Readable);
Expand Down Expand Up @@ -70,7 +69,7 @@ RedisRStream.prototype._read = function _read(size) {
return;
}
};
if (this._redisHasSuffixBufferAPI) {
if (self._redisClient.getrangeBuffer) {
self._redisClient.getrangeBuffer(self._redisKey, startOffset, endOffset, getrangeCallback)
} else {
self._redisClient.getrange(self._redisKey, startOffset, endOffset, getrangeCallback)
Expand Down

0 comments on commit 144ea68

Please sign in to comment.