Skip to content

Commit 04e68ac

Browse files
committedMar 14, 2022
fix: remove dropBufferSupport option
1 parent 32eb381 commit 04e68ac

File tree

8 files changed

+79
-198
lines changed

8 files changed

+79
-198
lines changed
 

‎README.md

+69-27
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ ioredis is a robust, full-featured Redis client that is
1919
used in the world's biggest online commerce company [Alibaba](http://www.alibaba.com/) and many other awesome companies.
2020

2121
0. Full-featured. It supports [Cluster](http://redis.io/topics/cluster-tutorial), [Sentinel](http://redis.io/topics/sentinel), [Streams](https://redis.io/topics/streams-intro), [Pipelining](http://redis.io/topics/pipelining), and of course [Lua scripting](http://redis.io/commands/eval), [Redis Functions](https://redis.io/topics/functions-intro), [Pub/Sub](http://redis.io/topics/pubsub) (with the support of binary messages).
22-
0. High performance 🚀.
23-
0. Delightful API 😄. It works with Node callbacks and Native promises.
24-
0. Transformation of command arguments and replies.
25-
0. Transparent key prefixing.
26-
0. Abstraction for Lua scripting, allowing you to [define custom commands](https://github.com/luin/ioredis#lua-scripting).
27-
0. Supports [binary data](https://github.com/luin/ioredis#handle-binary-data).
28-
0. Supports [TLS](https://github.com/luin/ioredis#tls-options) 🔒.
29-
0. Supports offline queue and ready checking.
30-
0. Supports ES6 types, such as `Map` and `Set`.
31-
0. Supports GEO commands 📍.
32-
0. Supports Redis ACL.
33-
0. Sophisticated error handling strategy.
34-
0. Supports NAT mapping.
35-
0. Supports autopipelining
22+
1. High performance 🚀.
23+
2. Delightful API 😄. It works with Node callbacks and Native promises.
24+
3. Transformation of command arguments and replies.
25+
4. Transparent key prefixing.
26+
5. Abstraction for Lua scripting, allowing you to [define custom commands](https://github.com/luin/ioredis#lua-scripting).
27+
6. Supports [binary data](https://github.com/luin/ioredis#handle-binary-data).
28+
7. Supports [TLS](https://github.com/luin/ioredis#tls-options) 🔒.
29+
8. Supports offline queue and ready checking.
30+
9. Supports ES6 types, such as `Map` and `Set`.
31+
10. Supports GEO commands 📍.
32+
11. Supports Redis ACL.
33+
12. Sophisticated error handling strategy.
34+
13. Supports NAT mapping.
35+
14. Supports autopipelining
3636

3737
# Versions
3838

@@ -105,35 +105,77 @@ $ npm install ioredis
105105

106106
```javascript
107107
const Redis = require("ioredis");
108-
const redis = new Redis(); // uses defaults unless given configuration object
109108

110-
// ioredis supports all Redis commands:
111-
redis.set("foo", "bar"); // returns promise which resolves to string, "OK"
109+
// First, you need to create a Redis instance.
110+
// We are going to cover how to specify host, port, and other connection
111+
// options soon.
112+
const redis = new Redis();
112113

113-
// the format is: redis[SOME_REDIS_COMMAND_IN_LOWERCASE](ARGUMENTS_ARE_JOINED_INTO_COMMAND_STRING)
114-
// the js: ` redis.set("mykey", "Hello") ` is equivalent to the cli: ` redis> SET mykey "Hello" `
114+
// Invoke the SET command. This is equivalent to the cli `redis> SET name Bob`:
115+
redis.set("name", "Bob"); // Returns a Promise
115116

116-
// ioredis supports the node.js callback style
117-
redis.get("foo", function (err, result) {
117+
// ioredis provides two kind of APIs, Node.js callback and Promise.
118+
// 1. You can pass a callback as the last parameter. It will be called when
119+
// we get a response from the Redis server:
120+
redis.get("name", (err, value) => {
118121
if (err) {
119122
console.error(err);
120123
} else {
121-
console.log(result); // Promise resolves to "bar"
124+
console.log(value); // "Bob"
125+
}
126+
});
127+
128+
// 2. Additionally, every command method returns a Promise
129+
// representing the server response:
130+
redis.get("name").then(
131+
(value) => {
132+
console.log(value);
133+
},
134+
(err) => {
135+
console.error(err);
122136
}
137+
);
138+
139+
//
140+
141+
// Every
142+
143+
async function main() {
144+
await redis.set("mykey", "Hello, World!");
145+
const value = await redis.get("mykey"); // value === "Hello, World!"
146+
}
147+
148+
main();
149+
```
150+
151+
// ioredis supports all Redis commands:
152+
redis.set("foo", "bar"); // returns promise which resolves to string, "OK"
153+
154+
// the format is: redis[REDIS_COMMAND_NAME_IN_LOWERCASE](ARGUMENTS_ARE_JOINED_INTO_COMMAND_STRING)
155+
// the js: `redis.set("mykey", "Hello")` is equivalent to the cli: ` redis> SET mykey "Hello"`
156+
157+
// ioredis supports the Node.js callback style
158+
redis.get("foo", (err, result) => {
159+
if (err) {
160+
console.error(err);
161+
} else {
162+
console.log(result); // Promise resolves to "bar"
163+
}
123164
});
124165

125166
// Or ioredis returns a promise if the last argument isn't a function
126-
redis.get("foo").then(function (result) {
127-
console.log(result); // Prints "bar"
167+
redis.get("foo").then((result) => {
168+
console.log(result); // Prints "bar"
128169
});
129170

130171
// Most responses are strings, or arrays of strings
131172
redis.zadd("sortedSet", 1, "one", 2, "dos", 4, "quatro", 3, "three");
132-
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 `
173+
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`
133174

134175
// All arguments are passed directly to the redis server:
135176
redis.set("key", 100, "EX", 10);
136-
```
177+
178+
````
137179
138180
See the `examples/` folder for more examples.
139181
@@ -155,7 +197,7 @@ new Redis({
155197
password: "auth",
156198
db: 0,
157199
});
158-
```
200+
````
159201

160202
You can also specify connection options as a [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis) or [`rediss://` URL](https://www.iana.org/assignments/uri-schemes/prov/rediss) when using [TLS encryption](#tls-options):
161203

‎lib/DataHandler.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ interface DataHandledable extends EventEmitter {
2929

3030
interface ParserOptions {
3131
stringNumbers: boolean;
32-
dropBufferSupport: boolean;
3332
}
3433

3534
export default class DataHandler {
3635
constructor(private redis: DataHandledable, parserOptions: ParserOptions) {
3736
const parser = new RedisParser({
3837
stringNumbers: parserOptions.stringNumbers,
39-
returnBuffers: !parserOptions.dropBufferSupport,
38+
returnBuffers: true,
4039
returnError: (err: Error) => {
4140
this.returnError(err);
4241
},

‎lib/Pipeline.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ Pipeline.prototype.multi = function () {
245245

246246
// @ts-expect-error
247247
const execBuffer = Pipeline.prototype.execBuffer;
248-
const exec = Pipeline.prototype.exec;
249248
// @ts-expect-error
250249
Pipeline.prototype.execBuffer = deprecate(function () {
251250
if (this._transactions > 0) {
@@ -278,10 +277,7 @@ Pipeline.prototype.exec = function (callback: Callback): Promise<Array<any>> {
278277

279278
if (this._transactions > 0) {
280279
this._transactions -= 1;
281-
return (this.options.dropBufferSupport ? exec : execBuffer).apply(
282-
this,
283-
arguments
284-
);
280+
return execBuffer.apply(this, arguments);
285281
}
286282
if (!this.nodeifiedPromise) {
287283
this.nodeifiedPromise = true;

‎lib/connectors/SentinelConnector/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ export default class SentinelConnector extends AbstractConnector {
296296
enableReadyCheck: false,
297297
connectTimeout: this.options.connectTimeout,
298298
commandTimeout: this.options.sentinelCommandTimeout,
299-
dropBufferSupport: true,
300299
...options,
301300
});
302301
// @ts-expect-error

‎lib/redis/RedisOptions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface CommonRedisOptions extends CommanderOptions {
1515
username?: string;
1616
password?: string;
1717
db?: number;
18-
dropBufferSupport?: boolean;
1918
autoResubscribe?: boolean;
2019
autoResendUnfulfilledCommands?: boolean;
2120
reconnectOnError?: ReconnectOnError;
@@ -76,7 +75,6 @@ export const DEFAULT_REDIS_OPTIONS: RedisOptions = {
7675
password: null,
7776
db: 0,
7877
// Others
79-
dropBufferSupport: false,
8078
enableOfflineQueue: true,
8179
enableReadyCheck: true,
8280
autoResubscribe: true,

‎lib/redis/event_handler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export function connectHandler(self) {
7272
*/
7373
new DataHandler(self, {
7474
stringNumbers: self.options.stringNumbers,
75-
dropBufferSupport: self.options.dropBufferSupport,
7675
});
7776

7877
if (self.options.enableReadyCheck) {

‎lib/utils/Commander.ts

+8-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { list } from "@ioredis/commands";
2-
import asCallback from "standard-as-callback";
32
import {
43
executeWithAutoPipelining,
54
shouldUseAutoPipelining,
@@ -14,11 +13,6 @@ export interface CommanderOptions {
1413
showFriendlyErrorStack?: boolean;
1514
}
1615

17-
const DROP_BUFFER_SUPPORT_ERROR =
18-
"*Buffer methods are not available " +
19-
'because "dropBufferSupport" option is enabled.' +
20-
"Refer to https://github.com/luin/ioredis/wiki/Improve-Performance for more details.";
21-
2216
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2317
class Commander<Context extends ClientContext = { type: "default" }> {
2418
options: CommanderOptions = {};
@@ -154,13 +148,6 @@ function generateFunction(
154148
replyEncoding: _encoding,
155149
};
156150

157-
if (this.options.dropBufferSupport && !_encoding) {
158-
return asCallback(
159-
Promise.reject(new Error(DROP_BUFFER_SUPPORT_ERROR)),
160-
callback as Callback | undefined
161-
);
162-
}
163-
164151
// No auto pipeline, use regular command sending
165152
if (!shouldUseAutoPipelining(this, functionName, commandName)) {
166153
return this.sendCommand(
@@ -185,24 +172,18 @@ function generateScriptingFunction(
185172
functionName: string,
186173
commandName: string,
187174
script: Script,
188-
encoding: unknown
175+
encoding: BufferEncoding | null
189176
) {
190-
return function (...args) {
177+
return function (...args: any[]) {
191178
const callback =
192179
typeof args[args.length - 1] === "function" ? args.pop() : undefined;
193180

194-
let options;
195-
if (this.options.dropBufferSupport) {
196-
if (!encoding) {
197-
return asCallback(
198-
Promise.reject(new Error(DROP_BUFFER_SUPPORT_ERROR)),
199-
callback
200-
);
201-
}
202-
options = { replyEncoding: null };
203-
} else {
204-
options = { replyEncoding: encoding };
205-
}
181+
const options: {
182+
replyEncoding: BufferEncoding | null;
183+
errorStack?: Error;
184+
} = {
185+
replyEncoding: encoding,
186+
};
206187

207188
if (this.options.showFriendlyErrorStack) {
208189
options.errorStack = new Error();

‎test/functional/drop_buffer_support.ts

-133
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.