Redis命令有两种类型:
1)键值相关命令
2)服务相关命令
一、键值相关命令
keys:返回满足给定pattern的所有key
127.0.0.1:6379> keys * 1) "mail" 2) "key2" 3) "mylist" 4) "name" 5) "mylist02" 6) "user" 7) "age" 8) "key3" 9) "user:001" 10) "key4" 11) "user001" 12) "zeng" 13) "key5" 14) "key1" 15) "job"
127.0.0.1:6379> keys my* 1) "mylist" 2) "mylist02"
2、exists:确认一个key是否存在,存在返回1,否则返回0
127.0.0.1:6379> exists mylist (integer) 1 127.0.0.1:6379> exists my (integer) 0
3、del:删除一个key,删除成功返回1
127.0.0.1:6379> del name (integer) 1' 127.0.0.1:6379> exists name (integer) 0
4、expire:设置一个key的过期时间
127.0.0.1:6379> expire age 10 (integer) 1 127.0.0.1:6379> ttl age (integer) 7 127.0.0.1:6379> ttl age (integer) 5 127.0.0.1:6379> ttl age (integer) 4 127.0.0.1:6379> ttl age (integer) 3 127.0.0.1:6379> ttl age (integer) 2 127.0.0.1:6379> ttl age (integer) 1 127.0.0.1:6379> ttl age (integer) 1 127.0.0.1:6379> ttl age (integer) -2 127.0.0.1:6379> ttl age (nil)
5、move:将当前数据库中的key转移到其他数据库中
127.0.0.1:6379> select 0 //select 选择数据库 OK 127.0.0.1:6379> set age 10 OK 127.0.0.1:6379> get age "10" 127.0.0.1:6379> move age 1 (integer) 1 127.0.0.1:6379> get age (nil) 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> get age "10"
6、persist:移除给定key的过期时间,取消成功返回1
127.0.0.1:6379[1]> expire age 200 (integer) 1 127.0.0.1:6379[1]> ttl age (integer) 196 127.0.0.1:6379[1]> persist age (integer) 1 127.0.0.1:6379[1]> ttl age (integer) -1
7、rename:重命名key
127.0.0.1:6379> keys * 1) "mail" 2) "key2" 3) "mylist" 4) "mylist02" 5) "user" 6) "key3" 7) "user:001" 8) "key4" 9) "user001" 10) "zeng" 11) "key5" 12) "key1" 13) "job" 127.0.0.1:6379> rename mail email OK 127.0.0.1:6379> keys * 1) "key2" 2) "mylist" 3) "mylist02" 4) "user" 5) "key3" 6) "email" 7) "user:001" 8) "key4" 9) "user001" 10) "zeng" 11) "key5" 12) "key1" 13) "job"
8、type:返回值的类型,如果key不存在则返回none
127.0.0.1:6379> type mylist list 127.0.0.1:6379> type name none 127.0.0.1:6379> type zeng string 127.0.0.1:6379> type use hash
二、服务器相关命令
1、ping:检测连接是否存活
127.0.0.1:6379> ping
PONG
2、echo:在命令行输出指定信息
127.0.0.1:6379> echo "hello,world"
"hello,world"
3、select:选择数据库
4、quit、exit:退出命令行
5、dbsize:返回当前数据库中key的数目
127.0.0.1:6379> keys * 1) "name" 2) "age" 127.0.0.1:6379> dbsize (integer) 2
6、info:获取服务器的信息和统计
127.0.0.1:6379> info # Server redis_version:3.2.1 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:83009af8b7a28da3 redis_mode:standalone os:Linux 2.6.32-573.el6.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll gcc_version:4.4.7 process_id:5032 run_id:cde348e6605d2f14df3ab48ae63280bcf637397e tcp_port:6379 uptime_in_seconds:668 uptime_in_days:0 hz:10 lru_clock:14012658 executable:/usr/local/redis/bin/redis-server config_file:/usr/local/redis/etc/redis.conf # Clients connected_clients:1 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0 # Memory used_memory:822504 used_memory_human:803.23K used_memory_rss:7794688 used_memory_rss_human:7.43M used_memory_peak:822504 used_memory_peak_human:803.23K total_system_memory:1028882432 total_system_memory_human:981.22M used_memory_lua:37888 used_memory_lua_human:37.00K maxmemory:0 maxmemory_human:0B maxmemory_policy:noeviction mem_fragmentation_ratio:9.48 mem_allocator:jemalloc-4.0.3 # Persistence loading:0 rdb_changes_since_last_save:2 rdb_bgsave_in_progress:0 rdb_last_save_time:1473629782 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:-1 rdb_current_bgsave_time_sec:-1 aof_enabled:0 aof_rewrite_in_progress:0 aof_rewrite_scheduled:0 aof_last_rewrite_time_sec:-1 aof_current_rewrite_time_sec:-1 aof_last_bgrewrite_status:ok aof_last_write_status:ok # Stats total_connections_received:2 total_commands_processed:11 instantaneous_ops_per_sec:0 total_net_input_bytes:251 total_net_output_bytes:11772155 instantaneous_input_kbps:0.00 instantaneous_output_kbps:0.00 rejected_connections:0 sync_full:0 sync_partial_ok:0 sync_partial_err:0 expired_keys:0 evicted_keys:0 keyspace_hits:0 keyspace_misses:0 pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 migrate_cached_sockets:0 # Replication role:master connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0 # CPU used_cpu_sys:0.66 used_cpu_user:0.27 used_cpu_sys_children:0.00 used_cpu_user_children:0.00 # Cluster cluster_enabled:0 # Keyspace db0:keys=2,expires=0,avg_ttl=0
7、config get:实时转储收到的请求
8、flushdb:删除当前选择数据库中的所有key
127.0.0.1:6379> dbsize (integer) 2 127.0.0.1:6379> flushdb OK 127.0.0.1:6379> dbsize (integer) 0 127.0.0.1:6379> keys * (empty list or set)
9、flushall:删除所有数据库中的所有key
127.0.0.1:6379> select 0 OK 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set name zeng OK 127.0.0.1:6379> dbsize (integer) 1 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> flushall OK 127.0.0.1:6379[1]> select 0 OK 127.0.0.1:6379> keys * (empty list or set)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。