您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。