Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of backslashes in CLI client "unexpected" #755

Closed
sgbeal opened this issue Nov 6, 2012 · 6 comments
Closed

Handling of backslashes in CLI client "unexpected" #755

sgbeal opened this issue Nov 6, 2012 · 6 comments

Comments

@sgbeal
Copy link

sgbeal commented Nov 6, 2012

LOL: i was having a discussion with a colleague about why we should NOT use hard tabs for separators in our redis db and accidentally found a bug: the CLI client seems to mis-handle keys which contain the escape sequence \t (it was trying to prove to my colleague that there is "no way" the CLI client interprets that as a tab):

  redis 127.0.0.1:6379> set "blah\tblah" foo
  OK
  redis 127.0.0.1:6379> set "blahblah" foo
  OK
  redis 127.0.0.1:6379> keys b*
  1) "blah\blah"
  2) "blahblah"
  redis 127.0.0.1:6379> del "blah\blah"
  (integer) 0
  redis 127.0.0.1:6379> del blahblah
  (integer) 1
  redis 127.0.0.1:6379> keys b*
  1) "blah\blah"
  redis 127.0.0.1:6379> del blah\blah
  (integer) 0
  redis 127.0.0.1:6379> del blah\tblah
  (integer) 0
  redis 127.0.0.1:6379> keys *
  1) "blah\blah"
  redis 127.0.0.1:6379> del blah\\blah
  (integer) 0
  redis 127.0.0.1:6379> keys *
  1) "blah\blah"

i am not sure how i can delete this key (not that i need to - this is a dummy instance).

@charsyam
Copy link
Contributor

charsyam commented Nov 7, 2012

how about using del "blah\tblah"

@moreaki
Copy link

moreaki commented Nov 7, 2012

Just tested on redis-server 2.6.2:

redis 127.0.0.1:6379> FLUSHDB
OK
redis 127.0.0.1:6379> KEYS *
(empty list or set)
redis 127.0.0.1:6379> set "blah\tblah" foo
OK
redis 127.0.0.1:6379> set "blah\\blah" foo
OK
redis 127.0.0.1:6379> set "blah\n\blah" foo
OK
redis 127.0.0.1:6379> KEYS *
1) "blah\n\blah"
2) "blah\\blah"
3) "blah\tblah"
redis 127.0.0.1:6379> del "blah\tblah"
(integer) 1
redis 127.0.0.1:6379> del "blah\\blah"
(integer) 1
redis 127.0.0.1:6379> del "blah\n\blah"
(integer) 1
redis 127.0.0.1:6379> KEYS *
(empty list or set)

As noted by @charsyam, you have tested GNU readline rather than the SET command of redis. So wrap your escape characters into quotes "<chars>".

@charsyam
Copy link
Contributor

charsyam commented Nov 7, 2012

my result is also similar with @moreaki

charsyam@ubuntu:~/projects/redis$ src/redis-cli
redis 127.0.0.1:6379> set "blah\tblah" foo
OK
redis 127.0.0.1:6379> set "blahblah" foo
OK
redis 127.0.0.1:6379> keys *

  1. "bar"
  2. "blahblah"
  3. "key"
  4. "blah\tblah"
    redis 127.0.0.1:6379> keys b*
  5. "bar"
  6. "blahblah"
  7. "blah\tblah"
    redis 127.0.0.1:6379> del blah\tblah
    (integer) 0
    redis 127.0.0.1:6379> del "blah\tblah"
    (integer) 1
    redis 127.0.0.1:6379>

@badboy
Copy link
Contributor

badboy commented Nov 7, 2012

@moreaki Just to clarify this: redis-cli does not use readline, but linenoise, antirez' own alternative to readline (with similar behaviour)

@moreaki
Copy link

moreaki commented Nov 7, 2012

@badboy: That's exactly true, thank you for mentioning it. In fact I wish we'd replace existing GNU tools (for example the notoriously big bash) with linenoise to reduce the noise and have significantly smaller binaries for let's say ARM environments. I hope Chet Ramey won't be offended by this ;).

@joezen777
Copy link

For anyone stumbling upon this issue, this article could apply if you're using Git bash for Windows. http://stackoverflow.com/questions/37051203/how-do-i-pass-a-literal-forward-slash-into-node-js-in-git-bash-for-windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants