Skip to content

Commit 1bdcb67

Browse files
committed
Merge pull request #943 from NodeRedis/new-stuff
Deprecate null / undefined arguments Deprecate .end() Drop support for redis < 2.6.11 Improve redis url parsing Add retry_unfullfilled_commands option Always refresh server_info after running info Improve arguments parsing Fixes #927 Fixes #442 Fixes #70 Fixes #921
2 parents be7c892 + ccf4c99 commit 1bdcb67

20 files changed

+499
-370
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ coverage
55
*.log
66
*.rdb
77
stunnel.conf
8-
stunnel.pid
8+
stunnel.pid
9+
*.out

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ addons:
1111
node_js:
1212
- "0.10"
1313
- "0.12"
14-
- "4.0"
15-
- "5.0"
14+
- "4"
15+
- "5"
1616
after_success: npm run coveralls

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ This will display:
5050
1: hashtest 2
5151
mjr:~/work/node_redis (master)$
5252

53-
Note that the API is entire asynchronous. To get data back from the server,
54-
you'll need to use a callback. The return value from most of the API is a
55-
backpressure indicator.
53+
Note that the API is entire asynchronous. To get data back from the server, you'll need to use a callback.
5654

5755
### Promises
5856

@@ -115,9 +113,8 @@ For a list of Redis commands, see [Redis Command Reference](http://redis.io/comm
115113

116114
The commands can be specified in uppercase or lowercase for convenience. `client.get()` is the same as `client.GET()`.
117115

118-
Minimal parsing is done on the replies. Commands that return a single line reply return JavaScript Strings,
119-
integer replies return JavaScript Numbers, "bulk" replies return node Buffers, and "multi bulk" replies return a
120-
JavaScript Array of node Buffers. `HGETALL` returns an Object with Buffers keyed by the hash keys.
116+
Minimal parsing is done on the replies. Commands that return a integer return JavaScript Numbers, arrays return JavaScript Array. `HGETALL` returns an Object keyed by the hash keys. All strings will either be returned as string or as buffer depending on your setting.
117+
Please be aware that sending null, undefined and Boolean values will result in the value coerced to a string!
121118

122119
# API
123120

@@ -173,23 +170,20 @@ port and host are probably fine and you don't need to supply any arguments. `cre
173170
* `redis.createClient()`
174171
* `redis.createClient(options)`
175172
* `redis.createClient(unix_socket, options)`
176-
* `redis.createClient('redis://user:pass@host:port', options)`
173+
* `redis.createClient(redis_url, options)`
177174
* `redis.createClient(port, host, options)`
178175

179176
#### `options` is an object with the following possible properties:
180177
* `host`: *127.0.0.1*; The host to connect to
181178
* `port`: *6370*; The port to connect to
182179
* `path`: *null*; The unix socket string to connect to
183-
* `url`: *null*; The redis url to connect to
180+
* `url`: *null*; The redis url to connect to (`[redis:]//[user][:password@][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` For more info check [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis))
184181
* `parser`: *hiredis*; Which Redis protocol reply parser to use. If `hiredis` is not installed it will fallback to `javascript`.
185182
* `return_buffers`: *false*; If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings.
186183
* `detect_buffers`: *false*; If set to `true`, then replies will be sent to callbacks as Buffers. Please be aware that this can't work properly with the pubsub mode. A subscriber has to either always return strings or buffers.
187184
if any of the input arguments to the original command were Buffers.
188185
This option lets you switch between Buffers and Strings on a per-command basis, whereas `return_buffers` applies to
189186
every command on a client.
190-
* `socket_nodelay`: *true*; Disables the [Nagle algorithm](https://en.wikipedia.org/wiki/Nagle%27s_algorithm).
191-
Setting this option to `false` can result in additional throughput at the cost of more latency.
192-
Most applications will want this set to `true`.
193187
* `socket_keepalive` *true*; Whether the keep-alive functionality is enabled on the underlying socket.
194188
* `no_ready_check`: *false*; When a connection is established to the Redis server, the server might still
195189
be loading the database from disk. While loading the server will not respond to any commands. To work around this,
@@ -208,7 +202,9 @@ The value is provided in milliseconds and is counted from the moment on a new cl
208202
Default is to try connecting until the default system socket timeout has been exceeded and to try reconnecting until 1h passed.
209203
* `max_attempts`: *0*; By default client will try reconnecting until connected. Setting `max_attempts`
210204
limits total amount of connection tries. Setting this to 1 will prevent any reconnect tries.
211-
* `auth_pass`: *null*; If set, client will run redis auth command on connect.
205+
* `retry_unfulfilled_commands`: *false*; If set to true, all commands that were unfulfulled while the connection is lost will be retried after the connection has reestablished again. Use this with caution, if you use state altering commands (e.g. *incr*). This is especially useful if you use blocking commands.
206+
* `password`: *null*; If set, client will run redis auth command on connect. Alias `auth_pass`
207+
* `db`: *null*; If set, client will run redis select command on connect. This is [not recommended](https://groups.google.com/forum/#!topic/redis-db/vS5wX8X4Cjg).
212208
* `family`: *IPv4*; You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules how to use the family type.
213209
* `disable_resubscribing`: *false*; If set to `true`, a client won't resubscribe after disconnecting
214210
* `rename_commands`: *null*; pass a object with renamed commands to use those instead of the original functions. See the [redis security topics](http://redis.io/topics/security) for more info.
@@ -245,12 +241,13 @@ NOTE: Your call to `client.auth()` should not be inside the ready handler. If
245241
you are doing this wrong, `client` will emit an error that looks
246242
something like this `Error: Ready check failed: ERR operation not permitted`.
247243

248-
## client.end([flush])
244+
## client.end(flush)
249245

250246
Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
251247
If you want to exit cleanly, call `client.quit()` to send the `QUIT` command after you have handled all replies.
252248

253-
If flush is set to true, all still running commands will be rejected instead of ignored after using `.end`.
249+
You should set flush to true, if you are not absolutly sure you do not care about any other commands.
250+
If you set flush to false all still running commands will silently fail.
254251

255252
This example closes the connection to the Redis server before the replies have been read. You probably don't
256253
want to do this:
@@ -259,12 +256,15 @@ want to do this:
259256
var redis = require("redis"),
260257
client = redis.createClient();
261258

262-
client.set("foo_rand000000000000", "some fantastic value");
263-
client.end(); // No further commands will be processed
264-
client.get("foo_rand000000000000", function (err, reply) {
265-
// This won't be called anymore, since flush has not been set to true!
259+
client.set("foo_rand000000000000", "some fantastic value", function (err, reply) {
260+
// This will either result in an error (flush parameter is set to true)
261+
// or will silently fail and this callback will not be called at all (flush set to false)
266262
console.log(err);
267263
});
264+
client.end(true); // No further commands will be processed
265+
client.get("foo_rand000000000000", function (err, reply) {
266+
console.log(err); // => 'The connection has already been closed.'
267+
});
268268
```
269269

270270
`client.end()` without the flush parameter should not be used in production!

changelog.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
11
Changelog
22
=========
33

4-
## v.2.5.0 - xx Dez, 2015
4+
## v.2.5.0-0 - xx Dez, 2015
55

66
Features
77

8-
- The parsers moved into the [redis-parser](https://github.com/NodeRedis/node-redis-parser) module and will be maintained in there from now on ([@BridgeAR](https://github.com/BridgeAR))
9-
- Improve js parser speed significantly for big SUNION/SINTER/LRANGE/ZRANGE ([@BridgeAR](https://github.com/BridgeAR))
8+
- The parsers moved into the [redis-parser](https://github.com/NodeRedis/node-redis-parser) module and will be maintained in there from now on
9+
- Improve js parser speed significantly for big SUNION/SINTER/LRANGE/ZRANGE
10+
- Improve redis-url parsing to also accept the database-number and options as query parameters as suggested in the [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)
11+
- Added a `retry_unfulfilled_commands` option
12+
- Setting this to 'true' results in retrying all commands that were not fulfilled on a connection loss after the reconnect. Use with caution
13+
- Added a `db` option to select the database while connecting (this is [not recommended](https://groups.google.com/forum/#!topic/redis-db/vS5wX8X4Cjg))
14+
- Added a `password` option as alias for auth_pass
15+
- The client.server_info is from now on updated while using the info command
16+
17+
Bugfixes
18+
19+
- Fixed explicit undefined as a command callback in a multi context
20+
- Fixed hmset failing to detect the first key as buffer or date if the key is of that type
21+
- Fixed do not run toString on an array argument and throw a "invalid data" error instead
22+
- This is not considered as breaking change, as this is likely a error in your code and if you want to have such a behavior you should handle this beforehand
23+
- The same applies to Map / Set and individual Object types
24+
- Fixed redis url not accepting the protocol being omitted or protocols other than the redis protocol for convienence
25+
- Fixed parsing the db keyspace even if the first database does not begin with a zero
26+
- Fixed handling of errors occuring while receiving pub sub messages
27+
28+
Deprecations
29+
30+
- Using any command with a argument being set to null or undefined is deprecated
31+
- From v.3.0.0 on using a command with such an argument will return an error instead
32+
- If you want to keep the old behavior please use a precheck in your code that converts the arguments to a string.
33+
- Using SET or SETEX with a undefined or null value will from now on also result in converting the value to "null" / "undefined" to have a consistent behavior. This is not considered as breaking change, as it returned an error earlier.
34+
- Using .end(flush) without the flush parameter deprecated and the flush parameter should explicitly be used
35+
- From v.3.0.0 on using .end without flush will result in an error
36+
- Using .end without flush means that any command that did not yet return is going to silently fail. Therefor this is considered harmfull and you should explicitly silence such errors if you are sure you want this
37+
- Depending on the return value of a command to detect the backpressure is deprecated
38+
- From version 3.0.0 on node_redis might not return true / false as a return value anymore. Please rely on client.should_buffer instead
39+
- The socket_nodelay option is deprecated and will be removed in v.3.0.0
40+
- If you want to buffer commands you should use [.batch or .multi](./README.md) instead. This is necessary to reduce the amount of different options and this is very likely reducing your throughput if set to false.
41+
- If you are sure you want to activate the NAGLE algorithm you can still activate it by using client.stream.setNoDelay(false)
42+
- Redis < v. 2.6.11 is not supported anymore and will not work in all cases. Please update to a newer redis version
1043

1144
## v.2.4.2 - 27 Nov, 2015
1245

0 commit comments

Comments
 (0)