redis命令使用

1:redis数据类型的基本操作:

查看或取出所有的key值
keys *
  
查看含SHOP的key值
keys SHOP_*
  
查看所有包括kevin字样的key值
keys kevin* 
  
查key中已保存的value值
lrange key 0 -1
 
查看redis下,当前的key值是否存在。如查看kevin这个key值是否存在
exists key kevin
 
删除当前的key值,如删除kevin这个key值
del kevin
 
设置过期时间,比如设置kevin这个key值20秒过期
expire kevin 20
 
清空当前数据库
flushdb
 
批量删除key的集合
redis-cli -h 192.168.138.128 -p 6379 keys "web*"| xargs redis-cli -h 192.168.148.128 -p 6379 del

2: value默认为1并递增,DECR为递减

INCR:如果key不存在就创建并设置value默认为1并递增,DECR为递减

192.168.138.128:6379> INCR num 
(integer) 1
192.168.138.128:6379> INCR num 
(integer) 2
192.168.138.128:6379> INCR num 
(integer) 3
192.168.138.128:6379> DECR num
(integer) 2
192.168.138.128:6379> DECR num
(integer) 1
192.168.138.128:6379> DECR num
(integer) 0
192.168.138.128:6379> DECR num
(integer) -1
2.1.7:INCRBY递增和DECRBY递减:

192.168.138.128:6379> DECRBY num 10
(integer) -12
192.168.138.128:6379> DECRBY num 10
(integer) -22
192.168.138.128:6379> INCRBY num 5
(integer) -17
192.168.138.128:6379> INCRBY num 5
(integer) -12
2.1.8:设置浮点数INCRBYFLOAT :

192.168.138.128:6379> INCRBYFLOAT  num 3.1415926
"3.1415926"
192.168.138.128:6379> INCRBYFLOAT  num1 -0.45
"-0.45"
192.168.138.128:6379> get num
"3.1415926"
192.168.138.128:6379> get num1
"-0.45"

3: info 命令,查看redis服务器的运行状态:

192.168.138.128:6379> INFO
# Server
redis_version:3.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:98b9789a90b21add
redis_mode:standalone
os:Linux 3.10.0-327.36.3.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:3530
run_id:1503196e35cacd678a0c45217d0be27941fc9e72
tcp_port:6379
uptime_in_seconds:11092
uptime_in_days:0
hz:10
lru_clock:7681604
executable:/usr/local/bin/redis-server
config_file:/etc/redis/6379.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:821544
used_memory_human:802.29K
used_memory_rss:7917568
used_memory_rss_human:7.55M
used_memory_peak:822624
used_memory_peak_human:803.34K
total_system_memory:3958697984
total_system_memory_human:3.69G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:512000000
maxmemory_human:488.28M
maxmemory_policy:noeviction
mem_fragmentation_ratio:9.64
mem_allocator:jemalloc-4.0.3

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1484074928
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
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:6
total_commands_processed:209
instantaneous_ops_per_sec:0
total_net_input_bytes:7526
total_net_output_bytes:35618099
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:105
keyspace_misses:4
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:1034
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:18.19
used_cpu_user:0.69
used_cpu_sys_children:0.05
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=1,expires=0,avg_ttl=0

4: config命令,用于查看当前配置、在不重启服务器的情况下修改配置:

192.168.138.128:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "512000000"
192.168.138.128:6379> CONFIG SET maxmemory 612000000
OK
192.168.138.128:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "612000000"

5: select切换数据库,dbsize查看当前库的key数量:

192.168.138.128:6379> KEYS *
1) "num"
192.168.138.128:6379> SELECT 0 #select用于在各库在之间进行切换
OK
192.168.138.128:6379> DBSIZE
(integer) 1
192.168.138.128:6379> set nam zhangsan
OK
192.168.138.128:6379> DBSIZE 
(integer) 2 #当前有两个key
192.168.138.128:6379> KEYS *
1) "num"
2) "nam"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值