Commit Graph

176 Commits

Author SHA1 Message Date
Yossi Gottlieb
91de9c975a RESP3 support changes from Redis.
This corresponds to commits d5c54f0b..bea09a7f in the redis repository.
2019-08-04 12:13:04 +03:00
Mark Nunberg
4830786c84 ensure that blocking timeout is set 2019-04-10 08:36:06 -04:00
m
dc6d19b9ec Port network layer to Winsock
With this change, Hiredis builds with MinGW and runs on Windows.
2019-04-01 11:54:37 +02:00
m
e84086cb92 Introduce a redisFD type
The redisFD type should be equal to the system native socket file
desciptor type (for POSIX, this is a plain int).

We also introduce the REDIS_INVALID_FD value, which maps to -1 on POSIX
systems.
2019-04-01 11:52:24 +02:00
m
1788f41f16 Move network I/O calls to net.c
This makes hiredis.c free from system calls related to socket I/O. This
is also makes the treatment of raw socket connections more similar to
the SSL backend.
2019-04-01 11:52:24 +02:00
Mark Nunberg
5eb6958870 Allow option for async connections to not automatically free 2019-02-21 11:49:25 -05:00
Mark Nunberg
ea9f9d2515 fixed wrong memset args 2019-02-20 09:11:10 -05:00
Mark Nunberg
1eb44cf0c4 scrub redisContext before freeing
This helps us detect use-after-free
2019-02-20 09:11:10 -05:00
valentino
847a20122f Fix memory leaks 2019-02-20 09:10:10 -05:00
valentino
58222c26f4 Support SNI 2019-02-20 09:10:10 -05:00
Mark Nunberg
f4f6b6d65c minor fixes: initialize options struct with 0 always
also, clean up redisContextInit -- we're just zeoring the struct
2019-02-20 09:10:10 -05:00
Mark Nunberg
e4a78006e7 Provide option-struct initialization
This reduces the boilerplate of all the redisConnectXXX functions, and
allows us to provide more connection options in the future.
2019-02-20 09:10:10 -05:00
Mark Nunberg
0c14544906 Initial SSL (sync) implementation 2019-02-20 09:10:10 -05:00
Stefan Hacker
169fcc708b Fix redisBufferRead documentation
Referred to redisContextReadReply which I cannot find in this codebase
nor the old redis-tools one. Presumably this meant to say
redisGetReplyFromReader which is how redisBufferRead is used in this
file. Could've also meant the interface function redisReaderGetReply.
2018-10-24 23:56:51 +02:00
Mark Nunberg
49974c9359 Call connect(2) again for non-blocking connect
This retrieves the actual error which occurred, as getsockopt is not
always reliable in this regard.
2018-09-25 20:21:37 -04:00
Justin Brewer
58e6b87f51 Remove redundant NULL checks
free(NULL) is a valid NOP. Most of the hiredis free functions behave the
same way. redisReaderFree is updated to also be NULL-safe.

There is one redundant NULL check at sds.c:1036, but it's left as is
since sds is imported from upstream.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30 21:45:13 -05:00
Justin Brewer
54acc8f087 Remove redundant zero stores
calloc is guaranteed to provide a zero-initialized buffer. There is
no need to set fields to zero explicitly.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30 21:45:13 -05:00
Justin Brewer
d1c1b668c1 Drop __redis_strerror_r
Since _GNU_SOURCE is now guaranteed to be unset, it is no longer
necessary to support the GNU-specific version of strerror_r.

Drop __redis_strerror_r from the header, and call strerror_r directly.
This breaks any external users of this macro, but they shouldn't have
been using it in  the first place.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30 21:45:13 -05:00
cdliuqiang@gmail.com
9219556386 calloc param fixes and NULL check 2018-01-05 16:19:54 +01:00
amallia
3c32344a41 Small fixes 2017-06-15 20:59:37 +01:00
Paulino Huerta
360a0646bb Typo format in redisFormatSdsCommandArgv function
this issue is very significant, because not allow the proper execution of the "function redisCommandArgv". The server returns "invalid bulk length".
Thanks!
2016-05-14 01:53:48 +02:00
charsyam
e2f6ee239c fixing typos 2015-10-28 02:19:24 +09:00
Jan-Erik Rediger
d323b5ef9c Revert "redisBufferRead: Clear REDIS_CONNECTED flag when server closed connection"
This reverts commit 1db17f257b.

If the `REDIS_CONNECTED` flag is cleared,
the async onDisconnect callback function will never be called.
This causes problems as the disconnect is never reported back to the user.

Closes #359
2015-09-14 14:58:05 +02:00
Jerry Jacobs
1db17f257b redisBufferRead: Clear REDIS_CONNECTED flag when server closed connection 2015-08-24 17:03:16 +02:00
Alex Balashov
d132d676e9 Renamed redisContext struct member 'unix' to 'unix_sock' to avoid encountering defined constant 'unix' in GNU C environment (see commit d8145d79ce).
Not all code using hiredis can compile using '-std=c99', and/or not all users are able to easily make that change to the build process of various open-source projects, so it is more pragmatic to choose a different identifier that does not impose this requirement.
2015-04-30 15:01:31 -04:00
Jan-Erik Rediger
af598dbce5 Change copyright date and add copyright holder 2015-04-16 21:29:41 +02:00
Jan-Erik Rediger
d9e0b0f6ab Implement a reconnect method for the client context
Originally implemented by @abedra as part of #306.

In case a write or read times out, we force an error state, because we
can't guarantuee that the next read will get the right data.
Instead we need to reconnect to have a clean-state connection, which is
now easily possible with this method.
2015-04-16 21:00:30 +02:00
Matt Stancliff
195aca3427 Improve digit counting for multibulk creation
This replaces the old intlen() implementation with a slightly
faster way of counting digits.

Implementation taken from the same place where digits10() in
redis/src/util.c came from.

The old 'intlen' allowed negative inputs, but no usage in hiredis
was passing negative numbers, so that ability is removed.  Also,
the new implementation can count higher (uint64_t) instead of
limited to just int as before.

Fixes #295 by replacing implementation
2015-01-22 16:00:38 -05:00
Matt Stancliff
f28872ca70 Cleanup tabs and end of line whitespace 2015-01-05 16:53:23 -05:00
Matt Stancliff
cc20232406 Fix errno error buffers to not clobber errors
The strerror_r API has two flavors depending on system options.

The bad flavor uses a static buffer for returning results, so if
you save the pointer from strerror_r, the string you're referencing
becomes useless if anybody else calls strerror_r again

The good flavor does what you expect: it writes the error to your buffer.

This commit uses strerror_r directly if it's a good version or copies
the static buffer into our private buffer if it's a bad version.

Thanks to gemorin for explaining the problem and drafting a fix.

Fixes #239
2015-01-05 16:53:23 -05:00
tzickel
ba3e74c408 Refactor reading code into read.c
Makes hiredis reading functions easier to include in external projects

[fixed all merge conflicts against current version]

Closes #249
2015-01-05 16:53:22 -05:00
Matt Stancliff
6a00a4643b Fix redisAppendCommand error result
Previously, redisvAppendCommand() would return OOM even with formatting
errors.  Now we use OTHER with an error string telling the user the
error was formatting related, not memory related.

This also fixes a potentially worse bug where were would pass error result
of -1 as an actual length to another function taking an unsigned length,
which would result in crash/overallocation/errors.  Now for that case,
we just return an error immediately and stop processing the command.

Fixes #177
2015-01-05 16:52:08 -05:00
NanXiao
e30c96ebde Add empty pointer check in error cleanup
If realloc fails, the curargv will be NULL.

Closes #253
2015-01-05 16:39:30 -05:00
NanXiao
d1e820d8ee Add error check in redisContextInit
Check whether the obuf or reader is empty: if one of the items is empty,
free the redisContext.
2015-01-05 16:39:30 -05:00
Nan Xiao
b6a860795c Fix redisvFormatCommand format parsing
Flags can occur in any order in format string, so we can't assume any order.

In original code, the redisvFormatCommand can process " %#+d" correctly,
but can't process "%+#d".

Closes #257
2015-01-05 16:39:30 -05:00
Matt Stancliff
9a753b4251 Add API to free hiredis (sds) formattings
External callers may not know about sdsfree, so let's
give them an easy way to know how to free their sds result.
2015-01-05 16:39:30 -05:00
Mareq
1b392eb796 Add API to free hiredis (char *) formattings
[Cleaned up:
  - name of function: freeRedis... -> redisFree...
  - return value of function (free doesn't return anything)
  - parameter type for function.
    - we don't need to free a char**, the char** is just
    for returning from the assignment functoin.]

Closes #250
2015-01-05 16:39:30 -05:00
mike
7c4d2557c4 Add support for SO_REUSEADDR
[This introduces some new API functions.]

* Adds new flag to the connection context indicating SO_REUSEADDR
  should be set.
* Adds max number of retries constant for when connect() hits
  EADDRNOTAVAIL.
* Adds new function, redisAsyncConnectBindWithReuse(), letting
  clients enable this functionality.

[Removed trailing whitespace in new header lines.]

Closes #264
2015-01-05 16:39:30 -05:00
jinguoli
a1bc89b236 Improve calloc() correctness
[It doesn't _actually_ matter, but technically
the order argument is: (number of items, size of items)]

Closes #279
2015-01-05 16:39:30 -05:00
michael-grunder
40f7035ba4 Improve redisAppendCommandArgv performance
OK, perhaps the second time is a charm.  I forgot that I had
hiredis forked from a long time ago, so the initial pull
request was hosed.  :)

* Pulled in sdscatfmt() from Redis, and modified it to accept a
  size_t (%T) style format specifier.

* Pulled in sdsll2str() and sdsull2str() from Redis (needed by
  sdscatfmt).

* Added a new method, redisFormatSdsCommandArgv() which takes
  and sds* as the target, rather than char* (and uses sdscatfmt
  instead of sprintf for the construction).

I get roughly the following improvement:

Old: 1.044806
New: 0.481620

The benchmark code itself can be found here:
https://gist.github.com/michael-grunder/c92ef31bb632b3d0ad81

Closes #260
2015-01-05 11:21:38 -05:00
Daniel Melani
05b85ebe7f Less surprising behaviour.
Make redisFree() and freeReplyObject() less surprising by behaving just
like free(). That is, don't crash when passing in NULL.
2014-05-29 16:05:27 +02:00
Pieter Noordhuis
a9c21e4d48 Fix const correctness 2014-04-09 22:30:04 -07:00
antirez
334525359a Upgrade sds to latest version
SDS is now broken out of Redis into its own project, so include
the latest version from the SDS repo.

This is a backport of the Redis commit doing the same to the bundled hiredis:
320fa02b9b
2014-04-09 17:02:42 -04:00
Axel Etcheverry
66192a0052 Add new redisAppendFormatedCommand with tests
Closes #202
2014-04-09 17:02:42 -04:00
Eddy Jansson
ae30d58ff9 Add redisConnectFd() and redisFreeKeepFd()
These allows for easier integration of hiredis with external
code that wants to manage its fds, say for instance in a pool.

Closes #223
2014-04-09 17:02:42 -04:00
Matt Stancliff
37d25a392c Add ability to bind source address on connect
Some environments require binding to specific source addresses instead
of letting the system determine which IP a connection should originate
from.

Closes #233
2014-04-08 19:37:54 -04:00
Noah Williamsson
fbf1bb648e Mark the timeout parameter as const in various functions
The struct timeval argument in redisConnectWithTimeout(),
redisConnectUnixWithTimeout(), redisSetTimeout(),
redisContextSetTimeout(), redisContextConnectTcp()
and redisContextConnectUnix() is never modified and can
therefore be marked as const.

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
2013-07-10 23:34:49 -07:00
Pieter Noordhuis
c532edc27f Fix const-related compiler errors 2013-07-10 23:31:30 -07:00
Pieter Noordhuis
049346aa33 Merge pull request #132 from nwmcsween/constify
constify: constify some variables / functions
2013-07-10 23:13:36 -07:00
Wolfgang Richter
37a840dc2c Emphasize size_t length for %b formatting
Closes #121.
2013-07-10 23:05:39 -07:00