Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
66192a00
Commit
66192a00
authored
Nov 14, 2013
by
Axel Etcheverry
Committed by
Matt Stancliff
Apr 09, 2014
Browse files
Add new redisAppendFormatedCommand with tests
Closes #202
parent
f20f5ad1
Changes
3
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
66192a00
...
...
@@ -1257,6 +1257,15 @@ int __redisAppendCommand(redisContext *c, char *cmd, size_t len) {
return
REDIS_OK
;
}
int
redisAppendFormattedCommand
(
redisContext
*
c
,
char
*
format
,
size_t
len
)
{
if
(
__redisAppendCommand
(
c
,
format
,
len
)
!=
REDIS_OK
)
{
return
REDIS_ERR
;
}
return
REDIS_OK
;
}
int
redisvAppendCommand
(
redisContext
*
c
,
const
char
*
format
,
va_list
ap
)
{
char
*
cmd
;
int
len
;
...
...
hiredis.h
View file @
66192a00
...
...
@@ -194,6 +194,10 @@ int redisBufferWrite(redisContext *c, int *done);
int
redisGetReply
(
redisContext
*
c
,
void
**
reply
);
int
redisGetReplyFromReader
(
redisContext
*
c
,
void
**
reply
);
/* Write a formatted command to the output buffer. Use these functions in blocking mode
* to get a pipeline of commands. */
int
redisAppendFormattedCommand
(
redisContext
*
c
,
char
*
format
,
size_t
len
);
/* Write a command to the output buffer. Use these functions in blocking mode
* to get a pipeline of commands. */
int
redisvAppendCommand
(
redisContext
*
c
,
const
char
*
format
,
va_list
ap
);
...
...
test.c
View file @
66192a00
...
...
@@ -217,6 +217,28 @@ static void test_format_commands(void) {
free
(
cmd
);
}
static
void
test_append_formatted_commands
(
struct
config
config
)
{
redisContext
*
c
;
redisReply
*
reply
;
char
*
cmd
;
int
len
;
c
=
connect
(
config
);
test
(
"Append format command: "
);
len
=
redisFormatCommand
(
&
cmd
,
"SET foo bar"
);
test_cond
(
redisAppendFormattedCommand
(
c
,
cmd
,
len
)
==
REDIS_OK
);
assert
(
redisGetReply
(
c
,
(
void
*
)
&
reply
)
==
REDIS_OK
);
free
(
cmd
);
freeReplyObject
(
reply
);
disconnect
(
c
,
0
);
}
static
void
test_reply_reader
(
void
)
{
redisReader
*
reader
;
void
*
reply
;
...
...
@@ -686,6 +708,7 @@ int main(int argc, char **argv) {
test_blocking_connection
(
cfg
);
test_blocking_io_errors
(
cfg
);
test_invalid_timeout_errors
(
cfg
);
test_append_formatted_commands
(
cfg
);
if
(
throughput
)
test_throughput
(
cfg
);
printf
(
"
\n
Testing against Unix socket connection (%s):
\n
"
,
cfg
.
unix
.
path
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment