Redis Common Commands

Source: Internet
Author: User

There are two types of REDIS commands:

1) Key-value related commands

2) service-related commands


I. Key-Value RELATED commands

Keys: Returns all keys that satisfy the given pattern

127.0.0.1:6379> keys * 1) "Mail" 2) "Key2" 3) "MyList" 4) "name" 5) "mylist02" 6) "user" 7) "age" 8) "Key3" 9) "user:00 1 "Key4") "user001" "Zeng" "Key5") "Key1" "Job"
127.0.0.1:6379> keys my*1) "MyList" 2) "mylist02"


2, exists: Verify that a key exists, there is return 1, otherwise return 0

127.0.0.1:6379> exists mylist (integer) 1127.0.0.1:6379> exists my (integer) 0


3, Del: Delete a key, delete successfully returned 1

127.0.0.1:6379> del name (integer) 1 ' 127.0.0.1:6379> exists name (integer) 0


4, expire: Set the expiration time of a key

127.0.0.1:6379> expire Age (integer) 1127.0.0.1:6379> ttl age (Integer) 7127.0.0.1:6379> ttl age (integer) 5127.0.0.1:6379> ttl age (Integer) 4127.0.0.1:6379> ttl age (Integer) 3127.0.0.1:6379> ttl age (integer) 2127.0.0.1:6379> ttl age (Integer) 1127.0.0.1:6379> ttl age (Integer) 1127.0.0.1:6379> ttl age (integer)- 2127.0.0.1:6379> TTL age (Nil)


5. Move: Transfer the key from the current database to a different database

127.0.0.1:6379> Select 0//select Choose Database ok127.0.0.1:6379> set age 10ok127.0.0.1:6379> get Age "10" 127.0.0.1:6379 > Move Age 1 (integer) 1127.0.0.1:6379> get Age (Nil) 127.0.0.1:6379> select 1ok127.0.0.1:6379[1]> Get Age "10"


6, Persist: Remove the expiration time of the given key, cancel the successful return 1

127.0.0.1:6379[1]> expire Age (integer) 1127.0.0.1:6379[1]> ttl age (integer) 196127.0.0.1:6379[1]> persist Age (Integer) 1127.0.0.1:6379[1]> ttl age (integer)-1


7. Rename: 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) "US er001 "Zeng") "Key5" ("Key1") "Job" 127.0.0.1:6379> 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") "Zeng" "Key5" 13 ) "Job"


8. Type: Returns a value that is none if key does not exist

127.0.0.1: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: Detects if the connection is alive

127.0.0.1:6379> Ping

PONG


2, Echo: Output The specified information at the command line

127.0.0.1:6379> echo "Hello,world"

"Hello,world"


3. Select: Choose Database


4, quit, exit: Exit command line


5. Dbsize: Returns the number of keys in the current database

127.0.0.1:6379> keys *) "name" 2) "Age" 127.0.0.1:6379> dbsize (integer) 2


6. Info: Get the information and statistics of the server

127.0.0.1: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 x86_64arch_bits : 64multiplexing_api:epollgcc_version:4.4.7process_id:5032run_id:cde348e6605d2f14df3ab48ae63280bcf637397etcp_ port:6379uptime_in_seconds:668uptime_in_days:0hz:10lru_clock:14012658executable:/usr/local/redis/bin/ Redis-serverconfig_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: real-time dump of received requests


8. FLUSHDB: Delete all keys in the currently selected database

127.0.0.1:6379> dbsize (integer) 2127.0.0.1:6379> flushdb ok127.0.0.1:6379> dbsize (integer) 0127.0.0.1:6379 > Keys * (empty list or set)


9. Flushall: Remove all keys from all databases

127.0.0.1:6379> Select 0ok127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set name zengOK127.0.0.1 :6379> dbsize (integer) 1127.0.0.1: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)







This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1854097

Redis Common Commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.