• ClaytonNorthey92's avatar
    Add reverse history search in redis-cli (linenoise) (#12543) · 8a05f009
    ClaytonNorthey92 authored
    added reverse history search to redis-cli, use it with the following:
    
    * CTRL+R : enable search backward mode, and search next one when
    pressing CTRL+R again until reach index 0.
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (reverse-i-search):                   # press CTRL+R
    (reverse-i-search): keys two          # input `keys`
    (reverse-i-search): keys one          # press CTRL+R again
    (reverse-i-search): keys one          # press CTRL+R again, still `keys one` due to reaching index 0
    (i-search): keys two                  # press CTRL+S, enable search forward
    (i-search): keys two                  # press CTRL+S, still `keys one` due to reaching index 1
    ```
    
    * CTRL+S : enable search forward mode, and search next one when pressing
    CTRL+S again until reach index 0.
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (i-search):                       # press CTRL+S
    (i-search): keys one              # input `keys`
    (i-search): keys two              # press CTRL+S again
    (i-search): keys two              # press CTRL+R again, still `keys two` due to reaching index 0
    (reverse-i-search): keys one      # press CTRL+R, enable search backward
    (reverse-i-search): keys one      # press CTRL+S, still `keys one` due to reaching index 1
    ```
    
    * CTRL+G : disable
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (reverse-i-search):                   # press CTRL+R
    (reverse-i-search): keys two          # input `keys`
    127.0.0.1:6379>                       # press CTRL+G
    ```
    
    * CTRL+C : disable
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (reverse-i-search):                   # press CTRL+R
    (reverse-i-search): keys two          # input `keys`
    127.0.0.1:6379>                       # press CTRL+G
    ```
    
    * TAB : use the current search result and exit search mode
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (reverse-i-search):                # press CTRL+R
    (reverse-i-search): keys two       # input `keys`
    127.0.0.1:6379> keys two           # press TAB
    ```
    
    * ENTER : use the current search result and execute the command
    ```
    127.0.0.1:6379> keys one
    127.0.0.1:6379> keys two
    (reverse-i-search):                 # press CTRL+R
    (reverse-i-search): keys two        # input `keys`
    127.0.0.1:6379> keys two            # press ENTER
    (empty array)
    127.0.0.1:6379>
    ```
    
    * any arrow key will disable reverse search
    
    your result will have the search match bolded, you can press enter to
    execute the full result
    
    note: I have _only added this for multi-line mode_, as it seems to be
    forced that way when `repl` is called
    
    Closes: https://github.com/redis/redis/issues/8277
    
    
    
    ---------
    Co-authored-by: default avatarClayton Northey <clayton@knowbl.com>
    Co-authored-by: default avatarViktor Söderqvist <viktor.soderqvist@est.tech>
    Co-authored-by: default avatardebing.sun <debing.sun@redis.com>
    Co-authored-by: default avatarBjorn Svensson <bjorn.a.svensson@est.tech>
    Co-authored-by: default avatarViktor Söderqvist <viktor@zuiderkwast.se>
    8a05f009
redis-cli.c 375 KB