Redis常用命令-创新互联
Redis命令有两种类型:
成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、网站建设、新城网络推广、成都微信小程序、新城网络营销、新城企业策划、新城品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;成都创新互联公司为所有大学生创业者提供新城建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com1)键值相关命令
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) 03、del:删除一个key,删除成功返回1
127.0.0.1:6379> del name (integer) 1' 127.0.0.1:6379> exists name (integer) 04、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) -17、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) 26、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=07、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)另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前文章:Redis常用命令-创新互联
文章来源:http://pwwzsj.com/article/deieoj.html