Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
README
-----------------------------
This code was forked from the official redis-tools repository on March 28,2012.
The source for this can be found at: https://github.com/antirez/redis-tools

Building
-----------------------------
To compile, simply:
make clean
make

Running
----------------------------
The only reason this was forked was to add a -s parameter to both redis-stat and redis-load.

The -s parameter allows you to specify a unix socket in place of a TCP socket to execute, exactly like redis-cli

e.g.
./redis-stat -s /tmp/redisunix.sock

as long as you have the following in your redis.conf file

unixsocket /tmp/redisunix.sock


Good luck!


14 changes: 11 additions & 3 deletions redis-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static struct config {
int longtail;
int longtail_order;
char *hostip;
char *unixSocket;
int hostport;
int keepalive;
long long start;
Expand Down Expand Up @@ -150,8 +151,11 @@ static void clientDisconnected(const redisAsyncContext *context, int status) {

static client createClient(void) {
client c = zmalloc(sizeof(struct _client));

c->context = redisAsyncConnect(config.hostip,config.hostport);
if (config.unixSocket){
c->context = redisAsyncConnectUnix(config.unixSocket);
}else{
c->context = redisAsyncConnect(config.hostip,config.hostport);
}
c->context->data = c;
redisAsyncSetDisconnectCallback(c->context,clientDisconnected);
if (c->context->err) {
Expand Down Expand Up @@ -348,6 +352,7 @@ static void usage(char *wrong) {
"Usage: redis-load ... options ...\n\n"
" host <hostname> Server hostname (default 127.0.0.1)\n"
" port <hostname> Server port (default 6379)\n"
" -s <unixSocket> Unix socket to connect using\n"
" clients <clients> Number of parallel connections (default 50)\n"
" requests <requests> Total number of requests (default 10k)\n"
" mindatasize <size> Min data size of string values in bytes (default 1)\n"
Expand Down Expand Up @@ -437,6 +442,9 @@ static void parseOptions(int argc, char **argv) {
} else if (!strcmp(argv[i],"port") && !lastarg) {
config.hostport = atoi(argv[i+1]);
i++;
} else if (!strcmp(argv[i],"-s") && !lastarg) {
config.unixSocket = argv[i+1];
i++;
} else if (!strcmp(argv[i],"datasize") && !lastarg) {
config.datasize_max = config.datasize_min = atoi(argv[i+1]);
i++;
Expand Down Expand Up @@ -565,7 +573,7 @@ int main(int argc, char **argv) {

config.hostip = "127.0.0.1";
config.hostport = 6379;

config.unixSocket = 0;
parseOptions(argc,argv);
config.databuf = zmalloc(config.datasize_max);

Expand Down
24 changes: 19 additions & 5 deletions redis-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define STAT_LATENCY 4

static struct config {
char *unixSocket;
char *hostip;
int hostport;
redisContext *context;
Expand Down Expand Up @@ -85,7 +86,11 @@ static redisReply *reconnectingCommand(const char *cmd) {
fflush(stdout);

redisFree(c);
c = redisConnect(config.hostip,config.hostport);
if (config.unixSocket){
c = config.context = redisConnectUnix(config.unixSocket);
}else{
c = redisConnect(config.hostip,config.hostport);
}
usleep(config.delay*1000);
}

Expand Down Expand Up @@ -532,6 +537,7 @@ static void usage(char *wrong) {
"Options:\n"
" host <hostname> Server hostname (default 127.0.0.1)\n"
" port <hostname> Server port (default 6379)\n"
" -s <unix socket> Unix socket to connect using\n"
" delay <milliseconds> Delay between requests (default: 1000 ms, 1 second).\n"
" samplesize <keys> Number of keys to sample for 'vmpage' stat.\n"
" logscale User power-of-two logarithmic scale in graphs.\n"
Expand All @@ -545,10 +551,13 @@ static int parseOptions(int argc, char **argv) {
for (i = 1; i < argc; i++) {
int lastarg = (i == (argc-1));

if (!strcmp(argv[i],"host") && !lastarg) {
if (!strcmp(argv[i],"-s" ) && !lastarg) {
config.unixSocket = argv[i+1];
i++;
} else if (!strcmp(argv[i],"host" ) && !lastarg) {
config.hostip = argv[i+1];
i++;
} else if (!strcmp(argv[i],"port") && !lastarg) {
} else if (!strcmp(argv[i],"port" ) && !lastarg) {
config.hostport = atoi(argv[i+1]);
i++;
} else if (!strcmp(argv[i],"delay") && !lastarg) {
Expand All @@ -572,6 +581,7 @@ static int parseOptions(int argc, char **argv) {
} else if (!strcmp(argv[i],"help")) {
usage(NULL);
} else {
printf("Missing something? %s", argv[i]);
usage(argv[i]);
}
}
Expand All @@ -587,10 +597,14 @@ int main(int argc, char **argv) {
config.delay = 1000;
config.samplesize = 10000;
config.logscale = 0;

config.unixSocket = 0;//"/tmp/redis.sock";
parseOptions(argc,argv);

c = config.context = redisConnect(config.hostip,config.hostport);
if (config.unixSocket){
c = config.context = redisConnectUnix(config.unixSocket);
}else{
c = redisConnect(config.hostip,config.hostport);
}
if (c->err) {
fprintf(stderr, "Error connecting to Redis: %s\n", c->errstr);
exit(1);
Expand Down