hiddenid01 / redis

Automatically exported from code.google.com/p/redis
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

redis-cli: no need to maintain history when input is not a terminal #465

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
>>What version of Redis you are using, in what kind of Operating System?

Redis 2.2, Linux

>>What is the problem you are experiencing?

Not really a problem. Redis-cli stores its history file in
$HOME, and maintains it at each command execution. When a lot
of commands are piped in (for instance from a shell command
line), it is misleading for the user (the user history is
instantly overriden).

Furthermore, in many corporate environments, the home directory is
stored on a NAS or NFS server. Since this file is written at each
command, it makes redis-cli really slow when a lot of commands
are executed (like 50 times slower) from a pipe or a file.

>> Please provide any additional information below.

Suggested fix:

@@ -696,7 +700,7 @@
     config.mb_delim = sdsnew("\n");
     cliInitHelp();

-    if (getenv("HOME") != NULL) {
+    if ( isatty(fileno(stdin)) && getenv("HOME") != NULL) {
         config.historyfile = malloc(256);
         snprintf(config.historyfile,256,"%s/.rediscli_history",getenv("HOME"));
         linenoiseHistoryLoad(config.historyfile);

Regards,
Didier.

Original issue reported on code.google.com by didier...@gmail.com on 22 Feb 2011 at 9:40

GoogleCodeExporter commented 8 years ago
this looks like a very good idea indeed, thanks

Original comment by anti...@gmail.com on 22 Feb 2011 at 10:08

GoogleCodeExporter commented 8 years ago
Thanks, added this in combination with skipping keeping history altogether when 
not in an interactive session (should speed up things with a large number of 
commands).

https://github.com/pietern/redis/commit/ca36b4ab31be1a1fea24f422028c07c6eeb21120

Original comment by pcnoordh...@gmail.com on 6 Mar 2011 at 8:17