Redis common commands
There are two types of Redis commands:
1) key value related commands
2) Service-related commands
1. Key value related commands
Keys: returns all key that satisfy a given pattern
127.0.0.1 key2 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.1 > keys my*1) "mylist" 2) "mylist02"
2. Exists: confirm whether a key exists. If it exists, it returns 1, otherwise it returns 0.
127.0.0.1 exists mylist 6379 > exists my (integer) 0
3. Del: delete a key. If deleted, 1 will be returned.
127.0.0.1 del name 6379 > exists name (integer) 0
4. Expire: set the expiration time of a key
127.0.0.1ttl age (integer) 7127.0.0.1 > ttl age (integer) 5127.0.0.1 > ttl age (integer) 4127.0.0.1 > ttl age (integer) 3127.0.1 > ttl age (integer) 2127.0.1 > ttl age (integer) 1127.0.1 > ttl age (integer) 1127.0.1 : 6379 > ttl age (integer)-2127.0.0.1 ttl age (nil)
5. Move: transfer the key in the current database to another database
127.0.0.1OK127.0.0.1:6379 6379 > select 0 / / select selection database OK127.0.0.1:6379 > set age 10OK127.0.0.1:6379 > get age "10" 127.0.0.1 OK127.0.0.1:6379 6379 > move age 1 (integer) 1127.0.0.1 OK127.0.0.1:6379 6379 > get age (nil) 127.0.0.1 OK127.0.0.1:6379 6379 > select 1OK127.0.0.1:6379 [1] > get age "10"
6. Persist: remove the expiration time of a given key. A successful cancellation returns 1.
127.0.0.1 expire age 6379 [1] > ttl age (integer) 196127.0.0.1 ttl age [1] > persist age (integer) 1127.0.0.1 persist age [1] > ttl age (integer)-1
7. Rename: rename key
127.0.0.1 key2 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 1) rename mail emailOK127.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: the type of return value, or none if key does not exist
127.0.1 type zengstring127.0.0.1:6379 6379 > type mylistlist127.0.0.1:6379 > type name none127.0.0.1:6379 > type zengstring127.0.0.1:6379 > type usehash
Second, server-related commands
1. Ping: check whether the connection is alive
127.0.0.1 purl 6379 > ping
PONG
2. Echo: output specified information on the command line
127.0.1 6379 > echo "hello,world"
"hello,world"
3. Select: select a database
4. Quit, exit: exit the command line
5. Dbsize: returns the number of key in the current database
127.0.0.1 keys * 1) "name" 2) "age" 127.0.1 age > dbsize (integer) 2
6. Info: get server information and statistics
127.0.0.1Viru 6379 > info# Serverredis_version:3.2.1redis_git_sha1:00000000redis_git_dirty:0redis_build_id:83009af8b7a28da3redis_mode:standaloneos:Linux 2.6.32-573.el6.x86_64 x86archetspurl 64protoapidised epollgcctransiversion4.4.7processicidl 5032runroomidride cde348e6605d2f14df3ab48ae63280bcf637397etcpportable portRose 6379uptimeroomsecondspurl 668uptimekeeping inhabits days0hzren 10lruleavclockride 14012658executablejar File:/usr/local/redis/etc/redis.conf# Clientsconnected_clients:1client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0# Memoryused_memory:822504used_memory_human:803.23Kused_memory_rss:7794688used_memory_rss_human:7.43Mused_memory_peak:822504used_memory_peak_human:803.23Ktotal_system_memory:1028882432total_system_memory_human:981.22Mused_memory_lua:37888used_memory_lua_human:37.00Kmaxmemory:0maxmemory _ human:0Bmaxmemory_policy:noevictionmem_fragmentation_ratio:9.48mem_allocator:jemalloc-4.0.3# Persistenceloading:0rdb_changes_since_last_save:2rdb_bgsave_in_progress:0rdb_last_save_time:1473629782rdb_last_bgsave_status:okrdb_last_bgsave_time_sec:-1rdb_current_bgsave_time_sec:-1aof_enabled:0aof_rewrite_in_progress:0aof_rewrite_scheduled:0aof_last_rewrite_time_sec:-1aof_current_rewrite_ Time_sec:-1aof_last_bgrewrite_status:okaof_last_write_status:ok# Statstotal_connections_received:2total_commands_processed:11instantaneous_ops_per_sec:0total_net_input_bytes:251total_net_output_bytes:11772155instantaneous_input_kbps:0.00instantaneous_output_kbps:0.00rejected_connections:0sync_full:0sync_partial_ok:0sync_partial_err:0expired_keys:0evicted_keys:0keyspace_hits:0keyspace_misses:0pubsub_channels:0pubsub_patterns:0latest _ fork_usec:0migrate_cached_sockets:0# Replicationrole:masterconnected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0# CPUused_cpu_sys:0.66used_cpu_user:0.27used_cpu_sys_children:0.00used_cpu_user_children:0.00# Clustercluster_enabled:0# Keyspacedb0:keys=2 Expires=0,avg_ttl=0
7. Config get: dump the received requests in real time
8. Flushdb: delete all key in the currently selected database
127.0.0.1 flushdb OK127.0.0.1:6379 > dbsize (integer) 2127.0.0.1 > flushdb OK127.0.0.1:6379 > dbsize (integer) 0127.0.0.1 > keys * (empty list or set)
9. Flushall: delete all key in all databases
127.0.0.1 select 0OK127.0.0.1:6379 > keys * (empty list or set) 127.0.0.1 empty list or set 6379 > set name zengOK127.0.0.1:6379 > dbsize (integer) 1127.0.0.1 dbsize 6379 > select 1OK127.0.0.1:6379 [1] > flushallOK127.0.0.1:6379 [1] > select 0OK127.0.0.1:6379 > keys * (empty list or set)