redis命令行管理
本文主要介绍使用redis命令行来查看和管理redis数据库。redis命令行的全集链接:http://redis.io/commands
使用redis-cli登录redis数据库:
[baichuan@zjdw-odmz-0009 ~]$ ./redis-2.8.19/bin/redis-cli -h
redis-cli 2.8.19
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.
-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.
-n <db> Database number.
-x Read last argument from STDIN.
-d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n).
-c Enable cluster mode (follow -ASK and -MOVED redirections).
--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.
--csv Output in CSV format.
--stat Print rolling stats about server: mem, clients, ...
--latency Enter a special mode continuously sampling latency.
--latency-history Like --latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
--slave Simulate a slave showing commands received from the master.
--rdb <filename> Transfer an RDB dump from remote server to local 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 big keys.
--scan List all keys using the SCAN command.
--pattern <pat> Useful with --scan to specify a SCAN pattern.
--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>.
--help Output this help and exit.
--version Output version and exit.
Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
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.
[baichuan@zjdw-odmz-0009 ~]$ ./redis-2.8.19/bin/redis-cli -h 115.239.138.137 -p 45981
115.239.138.137:45981>
登录上去后,需要使用AUTH命令来进行授权:
115.239.138.137:45981[14]> help AUTH AUTH password summary: Authenticate to the server since: 1.0.0 group: connection 115.239.138.137:45981[14]> 115.239.138.137:45981> AUTH xxx (redis数据库的密码) OK
然后就可以使用其他命令来操作redis数据库了。
1、SELECT命令
Select the DB with having the specified zero-based numeric index. New connections always use DB 0.
SELECT命令从当前连接切换到指定的数据库,这个数据库ID是在redis配置文件中配置好的从0开始的数字索引。新连接总是使用数据库0。
115.239.138.137:45981[14]> help SELECT SELECT index summary: Change the selected database for the current connection since: 1.0.0 group: connection 115.239.138.137:45981[14]> SELECT 6 OK 115.239.138.137:45981[6]>
2、PING命令
Returns PONG
if no argument is provided, otherwise return a copy of the argument as a bulk. This command is often used to test if a connection is still alive, or to measure latency.
PING命令如果没有提供参数,则返回PONG,否则返回参数的一个复制作为回应。这个命令通常被用测试连接是否还是活着的,或者测试延迟。
115.239.138.137:45981[6]> help ping PING - summary: Ping the server since: 1.0.0 group: connection 115.239.138.137:45981[6]> ping PONG 115.239.138.137:45981[6]> ping 16 "16" 115.239.138.137:45981[6]>
3、QUIT命令
Ask the server to close the connection. The connection is closed as soon as all pending replies have been written to the client.
QUIT命令用于告诉服务器关闭这个连接。这个连接在所有挂起的回复都已经写到客户端后马上关闭。
115.239.138.137:45981[6]> help QUIT QUIT - summary: Close the connection since: 1.0.0 group: connection 115.239.138.137:45981[6]> QUIT [baichuan@zjdw-odmz-0009 ~]$
4、SET命令
Set key
to hold the string value
. If key
already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
设置key来保持字符串value。如果key已经保持了一个值,它会被覆盖,无论它的类型是什么。任何以前和这个key关联的时间都在SET操作成功后被丢弃。
Options
Starting with Redis 2.6.12 SET supports a set of options that modify its behavior:
-
EX
seconds -- Set the specified expire time, in seconds. -
PX
milliseconds -- Set the specified expire time, in milliseconds. -
NX
-- Only set the key if it does not already exist. -
XX
-- Only set the key if it already exist.
Note: Since the SET command options can replace SETNX, SETEX, PSETEX, it is possible that in future versions of Redis these three commands will be deprecated and finally removed.
Return value
Simple string reply: OK
if SET was executed correctly. Null reply: a Null Bulk Reply is returned if the SET operation was not performed because the user specified the NX
or XX
option but the condition was not met.
115.239.138.137:45981[6]> help SET SET key value [EX seconds] [PX milliseconds] [NX|XX] summary: Set the string value of a key since: 1.0.0 group: string 115.239.138.137:45981[6]> 127.0.0.1:6379[1]> SET hello "welcome to the redis" OK 127.0.0.1:6379[1]> GET hello "welcome to the redis" 127.0.0.1:6379[1]> SET hello "already exist" NX (nil) 127.0.0.1:6379[1]> GET hello "welcome to the redis" 127.0.0.1:6379[1]> SET hello "already exist" XX OK 127.0.0.1:6379[1]> GET hello "already exist" 127.0.0.1:6379[1]> 127.0.0.1:6379[1]> KEYS * 1) "hello" 127.0.0.1:6379[1]> DEL hello (integer) 1 127.0.0.1:6379[1]> GET hello (nil) 127.0.0.1:6379[1]> KEYS * (empty list or set) 127.0.0.1:6379[1]>
5、GET命令
Get the value of key
. If the key does not exist the special value nil
is returned. An error is returned if the value stored at key
is not a string, because GET only handles string values.
获取key的对应的值。如果key不存在,则特殊值nil被返回。如果key所存储的值不是一个string,则返回错误,因为GET只能处理string值。
Return value
Bulk string reply: the value of key
, or nil
when key
does not exist.
115.239.138.137:45981[6]> help GET GET key summary: Get the value of a key since: 1.0.0 group: string 115.239.138.137:45981[6]> get hello (nil)
6、KEYS命令
Returns all keys matching pattern
.
返回所有的复合pattern模式的key。
While the time complexity for this operation is O(N), the constant times are fairly low. For example, Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds.
尽管这个操作的时间复杂度是O(N),但是它的常量时间非常小。例如,在一个普通的笔记本上运行的Redis,只需要40毫秒就可以扫面一个100万个key的数据库。
Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.
注意:把KEYS当成一个命令,它在生成环境中使用时需要极其小心。当它在一个大型数据库上执行时会破坏性能。这个命令是为调试和特殊操作设计的,例如改变key空间的布局。不要在你的普通应用程序代码中使用KEYS。如果你在寻找一种方式来查找你的key空间的一个子集的keys,考虑使用SCAN或sets。
Supported glob-style patterns:
-
h?llo
matcheshello
,hallo
andhxllo
-
h*llo
matcheshllo
andheeeello
-
h[ae]llo
matcheshello
andhallo,
but nothillo
-
h[^e]llo
matcheshallo
,hbllo
, ... but nothello
-
h[a-b]llo
matcheshallo
andhbllo
Use \
to escape special characters if you want to match them verbatim.
Return value
Array reply: list of keys matching pattern
.
115.239.138.137:45981[6]> help KEYS KEYS pattern summary: Find all keys matching the given pattern since: 1.0.0 group: generic 115.239.138.137:45981[6]> OK 115.239.138.137:45981[6]> MSET one 1 two 2 three 3 four 4 OK 115.239.138.137:45981[6]> KEYS *o* 1) "four" 2) "two" 3) "one" 115.239.138.137:45981[6]> KEYS t?? 1) "two" 115.239.138.137:45981[6]> KEYS * 1) "four" 2) "two" 3) "three" 4) "one" 115.239.138.137:45981[6]>
相关推荐
基于MySQL、Redis和MongoDB数据库开发命令行新闻管理系统,通俗易懂,适合python初学者学习了解
Redis 管理工具 Redis...不过它公自带一个最小化的命令行式的数据库管理工具,有时侯使用起来并不方便。不过Github上面已经有了很多图形化的管理工具,而且都针对REDIS做了一些优化,如自动折叠带schema的key等。
redis桌面管理工具 Redis是一个超精简的基于内存的键值对数据库(key-value),一般对并发有一定要求的应用都用其储存session,乃至整个数据库。不过它公自带一个最小化的命令行式的数据库管理工具,有时侯使用起来并...
============================ Redis桌面可视化管理工具,方便进行查看管理; 内置命令行功能; ============================
本文详细介绍了Redis数据库的切换操作,包括使用Redis命令行客户端和使用Redis客户端库两种方法。通过掌握这些操作方法,读者可以更加灵活地操作Redis中的多个数据库,满足实际应用中的不同需求。同时,也提醒读者在...
redis客户端的连接工具,mac版本,版本号0.9.3,通过该软件可以再mac上查询redis数据库中的相关数据,比起命令行方便很对
redisdesktop 是一个对redis 可视化的管理工具,方便查看redis数据以及可视化添加、编辑、删除redis数据;同样内部支持命令行执行;开发过程中提供效率。
RedisInsight是一个可视化管理工具,用于管理和监控Redis实例。它提供了实时监控、命令行模式、内存分析、实时数据可视化和慢查询等功能。RedisInsight支持多种Redis实例,包括单节点、集群和哨兵模式。它还提供了...
macOS的redis可视化管理工具 redis-manager,解压即用 redis可视化管理工具,让命令行见鬼去吧. 懒人必备神器.
在命令行窗口跳转到D:\Redis-x64-3.2.100目录下执行 redis-server.exe --service-start 方法二: 打开管理工具 服务,找到Redis服务。 通过右键选择启动或者直接点击左边的启动来启动服务。 redis库的默认...
在命令行窗口跳转到D:\Redis-x64-3.2.100目录下执行 redis-server.exe --service-start 方法二: 打开管理工具 服务,找到Redis服务。 通过右键选择启动或者直接点击左边的启动来启动服务。
windows 图形化界面redis管理工具-不需要再用命令行去查看redis中的key-value 数据资源了 非常好用 很方便~ 很赞~~
命令执行: 用户可以通过GUI界面执行Redis命令,而不必直接在命令行中输入。 可视化工具: 提供图表和图形,以帮助用户更好地理解和分析Redis数据库的性能和数据。 redis可视化工具 RedisInsight是Redis Labs提供的...
shortcut-redis-cli.sh:通用redis-cli终端运维管理快捷连接脚本
redis可视化工具 RedisInsight是Redis Labs提供的一个用于管理和监控Redis数据库的图形用户界面(GUI)工具。它为用户提供了直观的界面,以便更轻松地执行各种Redis数据库操作,包括查看键值、执行命令、监控性能等...
redis可视化工具 RedisInsight是Redis Labs提供的一个用于管理和监控Redis数据库的图形用户界面(GUI)工具。它为用户提供了直观的界面,以便更轻松地执行各种Redis数据库操作,包括查看键值、执行命令、监控性能等...
BBBUG聊天室API端,基于Thinkphp6实现API部分,命令行运行后台歌曲下载与同步任务,Redis做歌曲队列缓存。特色功能(创建房间、切换房间,房间权限与房间类型管理。点歌/切歌/听歌与歌曲播放进度同步。聊天、送歌等...
命令行界面 ./apollo --helpApollo is a Redis Cluster manager that aims to lighten the operational burdenon cluster operators. The cluster manager watches the Redis cluster for possibleiss
ruster - 一个简单的 Redis 集群管理工具 从命令行控制您的。 用法 ruster依赖 ,轻量级 Redis 客户端。 它目前允许创建集群、添加和删除节点以及在集群中的所有节点中执行命令。 创建集群 $ ruster create ip:port...
redis可视化工具 RedisInsight是Redis Labs提供的一个用于管理和监控Redis数据库的图形用户界面(GUI)工具。它为用户提供了直观的界面,以便更轻松地执行各种Redis数据库操作,包括查看键值、执行命令、监控性能等...