Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

redis-cli incorrect prompt string on socket connect #306

Closed
jamarshall opened this Issue · 5 comments

4 participants

@jamarshall

I have a redis 2.4.6 installation under Linux. It is configured to listen on port 6111 and domain socket /tmp/redis.sock .

When I do
redis-cli -s /tmp/redis.sock
I get the following prompt:
redis 127.0.0.1:6379>

My server is NOT listening on port 6379. So this prompt is incorrect.

Can you change it to show the socket name when -s is used? The correct prompt would be:
redis /tmp/redis.sock>

Thank you!

@tchajed

Here's a patch that fixes this issue:

From d792cc5350e9b31d1c3bc54ed2e8fe0d1199bf36 Mon Sep 17 00:00:00 2001
From: Tej Chajed <tchajed@gmail.com>
Date: Tue, 24 Jan 2012 22:01:24 -0600
Subject: [PATCH] fixed prompt in redis-cli when connecting to a socket

---
 src/redis-cli.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/redis-cli.c b/src/redis-cli.c
index 3f60a13..2e02f78 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -91,12 +91,18 @@ static long long mstime(void) {
 }

 static void cliRefreshPrompt(void) {
-    if (config.dbnum == 0)
-        snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d> ",
-            config.hostip, config.hostport);
-    else
-        snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d[%d]> ",
-            config.hostip, config.hostport, config.dbnum);
+   sds prompt = sdsnew("redis ");
+   if (config.hostsocket != NULL) {
+       prompt = sdscat(prompt, config.hostsocket);
+   } else {
+        prompt = sdscatprintf(prompt, "%s:%d", config.hostip, config.hostport);
+        if (config.dbnum > 0) {
+            prompt = sdscatprintf(prompt, "[%d]", config.dbnum);
+        }
+    }
+    prompt = sdscat(prompt, "> ");
+    strcpy(config.prompt, prompt);
+    //snprintf(config.prompt, sizeof(config.prompt), "redis ");
 }

 /*------------------------------------------------------------------------------
-- 
1.7.8.4
@pietern

This is being addressed in #314. Leaving this issue open until fixed and merged.

@antirez
Owner

The patch still needs some care, trivial to fix but I think the original author wants to care about it himself. Maybe at this point it makes sense to submit a new pull request with a single commit given that the issue is trivial and three commits are confusing in this context ;)

@antirez antirez referenced this issue from a commit
@antirez Fix for issue #306, thanks to tchajed (on github) for the pull reques…
…t. The original patch was reworked a bit.
a5bd084
@antirez antirez referenced this issue from a commit
@antirez Fix for issue #306, thanks to tchajed (on github) for the pull reques…
…t. The original patch was reworked a bit.
b805430
@antirez
Owner

Issue fixed with a different patch, original patcher credited in comments. Thank you, closing.

@antirez antirez closed this
@jamarshall

Thanks for fixing the issue! I look forward to seeing it in a production release.

--Jonathan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.