首页 > 数据库 >【ubuntu】使用redis-cli操作redis查询

【ubuntu】使用redis-cli操作redis查询

时间:2024-12-05 17:33:38浏览次数:8  
标签:latency cli -- redis keys mode ubuntu

一、场景

命令行操作redis, 万一没有界面化软件可用

   

二、文档

https://redis.io/docs/latest/develop/tools/cli/

 

 

三、安装

sudo apt-get update
sudo apt-get install redis-tools

 

 

四、命令介绍

$ redis-cli --help
redis-cli 7.0.15

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
  -h <hostname>      Server hostname (default: 127.0.0.1).
  -p <port>          Server port (default: 6379).
  -s <socket>        Server socket (overrides hostname and port).
  -a <password>      Password to use when connecting to the server.
                     You can also use the REDISCLI_AUTH environment
                     variable to pass this password more safely
                     (if both are used, this argument takes precedence).
  --user <username>  Used to send ACL style 'AUTH username pass'. Needs -a.
  --pass <password>  Alias of -a for consistency with the new --user option.
  --askpass          Force user to input password with mask from STDIN.
                     If this argument is used, '-a' and REDISCLI_AUTH
                     environment variable will be ignored.
  -u <uri>           Server URI.
  -r <repeat>        Execute specified command N times.
  -i <interval>      When -r is used, waits <interval> seconds per command.
                     It is possible to specify sub-second times like -i 0.1.
                     This interval is also used in --scan and --stat per cycle.
                     and in --bigkeys, --memkeys, and --hotkeys per 100 cycles.
  -n <db>            Database number.
  -2                 Start session in RESP2 protocol mode.
  -3                 Start session in RESP3 protocol mode.
  -x                 Read last argument from STDIN (see example below).
  -X                 Read <tag> argument from STDIN (see example below).
  -d <delimiter>     Delimiter between response bulks for raw formatting (default: \n).
  -D <delimiter>     Delimiter between responses for raw formatting (default: \n).
  -c                 Enable cluster mode (follow -ASK and -MOVED redirections).
  -e                 Return exit error code when command execution fails.
  --tls              Establish a secure TLS connection.
  --sni <host>       Server name indication for TLS.
  --cacert <file>    CA Certificate file to verify with.
  --cacertdir <dir>  Directory where trusted CA certificates are stored.
                     If neither cacert nor cacertdir are specified, the default
                     system-wide trusted root certs configuration will apply.
  --insecure         Allow insecure TLS connection by skipping cert validation.
  --cert <file>      Client certificate to authenticate with.
  --key <file>       Private key file to authenticate with.
  --tls-ciphers <list> Sets the list of preferred ciphers (TLSv1.2 and below)
                     in order of preference from highest to lowest separated by colon (":").
                     See the ciphers(1ssl) manpage for more information about the syntax of this string.
  --tls-ciphersuites <list> Sets the list of preferred ciphersuites (TLSv1.3)
                     in order of preference from highest to lowest separated by colon (":").
                     See the ciphers(1ssl) manpage for more information about the syntax of this string,
                     and specifically for TLSv1.3 ciphersuites.
  --raw              Use raw formatting for replies (default when STDOUT is
                     not a tty).
  --no-raw           Force formatted output even when STDOUT is not a tty.
  --quoted-input     Force input to be handled as quoted strings.
  --csv              Output in CSV format.
  --json             Output in JSON format (default RESP3, use -2 if you want to use with RESP2).
  --quoted-json      Same as --json, but produce ASCII-safe quoted strings, not Unicode.
  --show-pushes <yn> Whether to print RESP3 PUSH messages.  Enabled by default when
                     STDOUT is a tty but can be overridden with --show-pushes no.
  --stat             Print rolling stats about server: mem, clients, ...
  --latency          Enter a special mode continuously sampling latency.
                     If you use this mode in an interactive session it runs
                     forever displaying real-time stats. Otherwise if --raw or
                     --csv is specified, or if you redirect the output to a non
                     TTY, it samples the latency for 1 second (you can use
                     -i to change the interval), then produces a single output
                     and exits.
  --latency-history  Like --latency but tracking latency changes over time.
                     Default time interval is 15 sec. Change it using -i.
  --latency-dist     Shows latency as a spectrum, requires xterm 256 colors.
                     Default time interval is 1 sec. Change it using -i.
  --lru-test <keys>  Simulate a cache workload with an 80-20 distribution.
  --replica          Simulate a replica showing commands received from the master.
  --rdb <filename>   Transfer an RDB dump from remote server to local file.
                     Use filename of "-" to write to stdout.
 --functions-rdb <filename> Like --rdb but only get the functions (not the keys)
                     when getting the RDB dump file.
  --pipe             Transfer raw Redis protocol from stdin to server.
  --pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
                     no reply is received within <n> seconds.
                     Default timeout: 30. Use 0 to wait forever.
  --bigkeys          Sample Redis keys looking for keys with many elements (complexity).
  --memkeys          Sample Redis keys looking for keys consuming a lot of memory.
  --memkeys-samples <n> Sample Redis keys looking for keys consuming a lot of memory.
                     And define number of key elements to sample
  --hotkeys          Sample Redis keys looking for hot keys.
                     only works when maxmemory-policy is *lfu.
  --scan             List all keys using the SCAN command.
  --pattern <pat>    Keys pattern when using the --scan, --bigkeys or --hotkeys
                     options (default: *).
  --quoted-pattern <pat> Same as --pattern, but the specified string can be
                         quoted, in order to pass an otherwise non binary-safe string.
  --intrinsic-latency <sec> Run a test to measure intrinsic system latency.
                     The test will run for the specified amount of seconds.
  --eval <file>      Send an EVAL command using the Lua script at <file>.
  --ldb              Used with --eval enable the Redis Lua debugger.
  --ldb-sync-mode    Like --ldb but uses the synchronous Lua debugger, in
                     this mode the server is blocked and script changes are
                     not rolled back from the server memory.
  --cluster <command> [args...] [opts...]
                     Cluster Manager command and arguments (see below).
  --verbose          Verbose mode.
  --no-auth-warning  Don't show warning message when using password on command
                     line interface.
  --help             Output this help and exit.
  --version          Output version and exit.

Cluster Manager Commands:
  Use --cluster help to list all available cluster manager commands.

Examples:
  cat /etc/passwd | redis-cli -x set mypasswd
  redis-cli -D "" --raw dump key > key.dump && redis-cli -X dump_tag restore key2 0 dump_tag replace < key.dump
  redis-cli -r 100 lpush mylist x
  redis-cli -r 100 -i 1 info | grep used_memory_human:
  redis-cli --quoted-input set '"null-\x00-separated"' value
  redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
  redis-cli --scan --pattern '*:12345*'

  (Note: when using --eval the comma separates KEYS[] from ARGV[] items)

When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands
and settings.

 

五、常用操作

1、连接redis,并连接到指定的db

redis-cli -h 192.168.3.74 -p 6379 -n 5

 认证参数根据实际redis设置使用

 

2、查看所有的key

 

3、根据正则表达查询,如包含部分字符

 

4、查询某个key的值

 

其他操作可以根据需要自行了解

 

 

参考链接:

https://blog.csdn.net/sinat_20471177/article/details/132043998

标签:latency,cli,--,redis,keys,mode,ubuntu
From: https://www.cnblogs.com/fireblackman/p/18589034

相关文章

  • 【ubuntu】yarn安装和配置
    一、官网https://yarn.bootcss.com/ 二、安装npminstall--globalyarn检查yarn--version 三、配置环境变量#yarnexportYARN_GLOBAL=/home/tester/.yarn/yarn_globalexportYARN_BIN=/home/tester/.yarn/binexportPATH=$PATH:$YARN_BIN生效配置 四......
  • 【ubuntu】使用二进制安装包安装node和npm并配置
    一、官网https://nodejs.org/zh-cn 二、安装方法1、下载安装包 2、解压安装包到指定目录tarxfnode-v14.21.0-linux-x64.tar.xz-C~/tools/&&cd~/tools 3、配置环境变量#nodeexportNODE_HOME=$HOME/tools/node-v14.21.0-linux-x64exportPATH=$NODE_HO......
  • Ubuntu 24.04.1 LTS 安装docker
    在Ubuntu24.04.1LTS上安装Docker的步骤如下:1.更新系统包sudoaptupdatesudoaptupgrade-y2.安装必要的软件包sudoaptinstall-yapt-transport-httpsca-certificatescurlsoftware-properties-common3.添加Docker官方的GPG密钥curl-fsSLhttps:/......
  • 电脑开机或打开程序提示缺少cliconfg.rll文件问题
    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题,如果是新手第一时间会认为是软件或游戏出错了,其实并不是这样,其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库,这时你可以下载这个cliconfg.rll文件(挑选合适的版本文件)把它......
  • NoSQL数据库实习头歌实验知识点整理(三)-Redis部分
    文章目录1初识Redis1.1Redis简介1.1.1Redis与其他数据库的对比1.1.2Redis的特性1.2快速安装Redis与Python1.3Redis数据结构简介1.3.1Redis中的字符串1.3.2Redis中的列表1.3.3Redis中的集合1.3.4Redis中的哈希1.3.5Redis中的有序集合1.4使用Python与R......
  • 头歌解答 Redis基本命令
    第1关:字符串、列表与集合编程要求根据提示,在右侧Begin-End区域补充代码,完成任务分配的后端处理逻辑:在task_empty()方法中:从Redis中获取列表task_list的长度,判断是否为0若为0,则返回True若不为0,则返回False在get_task()方法中:从列表task_lis......
  • 【ubuntu】手动更新ubuntu23.10 到24.04 LTS版本
    一、背景   个人有些软件在23.10上安装有问题,所以更新下  二、更新方法有事找官网    https://ubuntu.com/server/docs/how-to-upgrade-your-release 三、更新步骤总体步骤如下:开始之前非常重要的一步,备份资料,以防万一更新失败,资料丢失,备份是个好习惯#......
  • Bclinux离线安装PostgreSQL10.23+PostGIS2.5编译安装配置
    一、安装PostgreSQL1、安装PostgreSQL解压PostgreSQL软件包tar-zxvfpostgresql.tar.gz配置并安装PostgreSQL[postgres@localhostsetup]$tar-zxvfpostgresql-10.23.tar.gz进入解压后的目录,按照PostgreSQL的官方文档进行配置和安装。这通常涉及到创建数据目录、配置postgresq......
  • Redis探秘Sentinel(哨兵模式)
    概述Redis的高可用机制有持久化、复制、哨兵和集群。其主要的作用和解决的问题分别是:持久化:持久化是最简单的高可用方法(有时甚至不被归为高可用的手段),主要作用是数据备份,即将数据存储在硬盘,保证数据不会因进程退出而丢失。复制:复制是高可用Redis的基础,哨兵和集群都是在复制......
  • JVM优化,Redis,MySQL相关面试题
    一、平常对SQL优化的了解1.索引优化创建索引:为常用的查询字段创建索引,可以显著提高查询速度。例如,为订单金额的字段创建索引,可以加速按订单金额的排序操作。优化索引:定期维护索引,避免索引碎片化,保持索引性能。使用覆盖索引:通过创建覆盖索引,可以避免回表操作,进一步提高查......