Commit Graph

146 Commits

Author SHA1 Message Date
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
Allen.Dou
9dff5105fc Make KeepAlive optional
Make Connection KeepAlive being optional instead of default.
2013-04-30 00:11:57 +08:00
Pieter Noordhuis
f05909cd53 Merge pull request #147 from hdoreau/d7e3268f48b457cb52336d264f8860b336faea9f
Prevent hiredis from crashing on memory allocation failure
2013-01-26 11:18:45 -08:00
Henri Doreau
814be4f5bd Made connect functions return NULL on alloc failures.
Updated documentation and examples accordingly.
2013-01-22 10:19:46 +01:00
Nathan McSween
ba6c3c152c constify: constify some variables / functions 2012-11-12 19:48:21 +00:00
Fabien MARTY
bf161d996f Try again later for EINTR errors (see issue #99) 2012-11-06 18:42:05 +01:00
antirez
f7f022e4e0 On stack buffer to read replies set to 16k (was 2k).
It was verified experimentally that this value, on Linux kernels, provides
better performances compared to the 2k value. However larger values
apparently don't produce any noticeable effect on performances.
2012-08-21 15:10:16 +02:00
antirez
51ab89d899 Max depth of multi-bulk reply moved from 2 to 7.
Hiredis can handle multi bulk replies with a fixed (hardcoded) level of
nesting. This should be changed in the future in order to avoid
hardcoded limits. As a quick fix this commit moves the max nesting from 2
to 7, so that there are no problems when processing replies from the SLOWLOG
command, from Redis Sentinel, or generated by Redis Lua Scripts (that are
allowed to generate replies with any level of nesting).
2012-08-21 15:06:06 +02:00
antirez
7f095053c6 Configurable reader max idle buffer size.
Hiredis used to free unused redisReader buffers bigger than 16k. Now
this limit is configurable (see the documentation updated by this commit)
in order to allow working with big payloads without incurring to speed
penalty.
2012-08-21 15:01:47 +02:00
Chip Salzenberg
56ae8aa110 DRY list of integer formats 2011-12-20 10:06:23 -08:00
mrb
52a29a124b increase read depth by one, would allow ruby redis client to read from slowlog 2011-12-02 08:45:13 -05:00
John Zwinck
347528cf48 Fix minor inconsistencies in comment. 2011-11-28 16:37:35 -05:00
Pieter Noordhuis
2da784ce8f Abort on invalid format
There is no way we can guess the width of the argument when we cannot
infer its type from the format specifier.
2011-07-09 15:08:45 +02:00
Pieter Noordhuis
27c96dde77 Use correct type when calling va_arg in formatter 2011-07-09 15:08:45 +02:00
Pieter Noordhuis
375ba48eea Revert "Add function to retrieve formatted reply"
This reverts commit 77540aa316. The change
in buffer strategy is too large to put in a minor release. It is put in
a separate branch in the meantime, so it can be refined and released
together with a minor version bump.
2011-06-19 13:41:25 +02:00
Pieter Noordhuis
5f5b3d9787 Fix for issue #45 2011-06-09 09:25:09 +02:00
Pieter Noordhuis
77540aa316 Add function to retrieve formatted reply
This is done by only truncating the read buffer once a full reply has
been read. The buffer is no longer truncated halfway through reading a
reply. In addition: pass offset/length of protocol and content via the
read tasks.
2011-05-05 17:01:34 +02:00
Pieter Noordhuis
0cb7c27d9c Update license 2011-04-21 22:46:23 +02:00
Pieter Noordhuis
f3f02b6419 Let the async API segfault on OOM for now 2011-04-21 22:40:36 +02:00
Pieter Noordhuis
c9dc93e1de Move chrtos to hiredis.c (not used elsewhere) 2011-04-21 22:39:19 +02:00
Pieter Noordhuis
8419b060f2 Handle OOM when doing blocking requests 2011-04-21 21:34:43 +02:00
Pieter Noordhuis
e932709a66 More safety 2011-04-21 21:18:08 +02:00
Pieter Noordhuis
dd5fc26457 Make command formatters gracefully abort when out of memory 2011-04-21 20:59:41 +02:00
Pieter Noordhuis
d4ebb60d65 More OOM checks in the protocol reader 2011-04-21 18:50:10 +02:00
Pieter Noordhuis
df1d693b03 Include fmacros.h to make sure strerror_p is defined on Linux 2011-04-21 16:24:03 +02:00
Pieter Noordhuis
965d42640f Rename *ReplyReader* to *Reader* 2011-04-21 16:03:32 +02:00
Pieter Noordhuis
0ee7c66818 Use static buffer for error string on context 2011-04-21 15:56:22 +02:00
Pieter Noordhuis
6d207ea98e Create protocol reader when creating context 2011-04-21 15:04:42 +02:00
Pieter Noordhuis
a926232293 Reply object functions can be set by the user after creating the reader 2011-04-21 14:37:29 +02:00
Pieter Noordhuis
5ba49014da Privdata can be set directly on the struct 2011-04-21 14:34:03 +02:00
Pieter Noordhuis
2002218981 Remove useless casts 2011-04-21 14:31:02 +02:00