Skip to content

Commit

Permalink
CPP client added thanks to Brian Hammond
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed May 9, 2009
1 parent 93ea375 commit 57172ff
Show file tree
Hide file tree
Showing 22 changed files with 2,736 additions and 47 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BEFORE REDIS 1.0.0-rc1

- Contrib dir with RHL for Centos and other contributions like init scripts
- Update the FAQ with max number of keys in a DB and the overcommit thing
- Add number of keys for every DB in INFO
- maxmemory support in config file.
Expand Down
11 changes: 8 additions & 3 deletions benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static struct config {
int donerequests;
int keysize;
int datasize;
int randomkeys;
aeEventLoop *el;
char *hostip;
int hostport;
Expand Down Expand Up @@ -341,6 +342,8 @@ void parseOptions(int argc, char **argv) {
i++;
if (config.datasize < 1) config.datasize=1;
if (config.datasize > 1024*1024) config.datasize = 1024*1024;
} else if (!strcmp(argv[i],"-r")) {
config.randomkeys = 1;
} else if (!strcmp(argv[i],"-q")) {
config.quiet = 1;
} else if (!strcmp(argv[i],"-l")) {
Expand All @@ -354,6 +357,7 @@ void parseOptions(int argc, char **argv) {
printf(" -n <requests> Total number of requests (default 10000)\n");
printf(" -d <size> Data size of SET/GET value in bytes (default 2)\n");
printf(" -k <boolean> 1=keep alive 0=reconnect (default 1)\n");
printf(" -r Use random keys for SET/GET/INCR\n");
printf(" -q Quiet. Just show query/sec values\n");
printf(" -l Loop. Run the tests forever\n");
exit(1);
Expand All @@ -374,6 +378,7 @@ int main(int argc, char **argv) {
config.keepalive = 1;
config.donerequests = 0;
config.datasize = 3;
config.randomkeys = 0;
config.quiet = 0;
config.loop = 0;
config.latency = NULL;
Expand Down Expand Up @@ -402,7 +407,7 @@ int main(int argc, char **argv) {
prepareForBenchmark();
c = createClient();
if (!c) exit(1);
c->obuf = sdscatprintf(c->obuf,"SET foo %d\r\n",config.datasize);
c->obuf = sdscatprintf(c->obuf,"SET foo_rand000000000000 %d\r\n",config.datasize);
{
char *data = zmalloc(config.datasize+2);
memset(data,'x',config.datasize);
Expand All @@ -418,7 +423,7 @@ int main(int argc, char **argv) {
prepareForBenchmark();
c = createClient();
if (!c) exit(1);
c->obuf = sdscat(c->obuf,"GET foo\r\n");
c->obuf = sdscat(c->obuf,"GET foo_rand000000000000\r\n");
c->replytype = REPLY_BULK;
c->readlen = -1;
createMissingClients(c);
Expand All @@ -428,7 +433,7 @@ int main(int argc, char **argv) {
prepareForBenchmark();
c = createClient();
if (!c) exit(1);
c->obuf = sdscat(c->obuf,"INCR counter\r\n");
c->obuf = sdscat(c->obuf,"INCR counter_rand000000000000\r\n");
c->replytype = REPLY_INT;
createMissingClients(c);
aeMain(config.el);
Expand Down
44 changes: 44 additions & 0 deletions client-libraries/cpp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Redis C++ Client Library Makefile

#CFLAGS?= -pedantic -O2 -Wall -W -DNDEBUG
CFLAGS?= -pedantic -O0 -W -DDEBUG -g
CC = g++

CLIENTOBJS = anet.o redisclient.o
LIBNAME = libredisclient.a

TESTAPP = test_client
TESTAPPOBJS = test_client.o
TESTAPPLIBS = $(LIBNAME) -lstdc++

all: $(LIBNAME) $(TESTAPP)

$(LIBNAME): $(CLIENTOBJS)
ar rcs $(LIBNAME) $(CLIENTOBJS)

.c.o:
$(CC) -c $(CFLAGS) $<

.cpp.o:
$(CC) -c $(CFLAGS) $<

$(TESTAPP): $(LIBNAME) $(TESTAPPOBJS)
$(CC) -o $(TESTAPP) $(TESTAPPOBJS) $(TESTAPPLIBS)

test: $(TESTAPP)
@./test_client

check: test

clean:
rm -rf $(LIBNAME) *.o $(TESTAPP)

dep:
$(CC) -MM *.c *.cpp

log:
git log '--pretty=format:%ad %s' --date=short > Changelog

anet.o: anet.c fmacros.h anet.h
redisclient.o: redisclient.cpp redisclient.h anet.h

16 changes: 16 additions & 0 deletions client-libraries/cpp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
redis-cpp-client
================

* A C++ client for the Redis_ key-value database (which is hosted at github_).
* This client has no external dependencies other than g++ (no Boost for instance).
* It uses anet from antirez_ (redis' author), which is bundled.
* This client is licensed under the same license as redis.
* Tested on Linux and Mac OS X.

* This is a work in progress. I will update this README when the client is "done".
If I had to put a version number on it right now, I'd call it version 0.85

.. _Redis: http://code.google.com/p/redis/
.. _github: http://github.com/antirez/redis/tree/master
.. _antirez: https://github.com/antirez

9 changes: 9 additions & 0 deletions client-libraries/cpp/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+ finish command implementations
= finish unit tests
Only a few left, to test the SORT command's edge cases (e.g. BY pattern)
+ determine if we should not use bool return values and instead throw redis_error. (latter).
+ maybe more fine-grained exceptions (not just redis_error but operation_not_permitted_error, etc.)
- benchmarking
- consistent hashing?
- make all string literals constants so they can be easily changed (minor)
- add conveniences that store a std::set in its entirety (same for std::list, std::vector)
Loading

0 comments on commit 57172ff

Please sign in to comment.