マイredis常用コマンドセット(更新継続)
Redis共通コマンドセット
2、redis-benchmark関連
3.redis-server
4.redis-cli
5.サーバの情報と統計を取得する
6.redis TTLキー値削除メカニズム
7.redisコマンドの例
redis-cli-h--stat redis監視コマンド付き
1、Redis
1)
quit: (connection)
auth:
help cmd: cmd , :help quit
2)
save:
bgsave:
lastsave: Unix
shutdown: , ( , )
3)
info:
monitor:
slaveof:
config: Redis
config resetstat: info
config get:
config set: Redis (configuration) , CONFIG GET *
config rewrite:Redis redis.conf
psubscribe: psubscribe news.* tweet.*
publish: message channel publish msg "good morning"
pubsub channels: PUBSUB CHANNELS news.i*
pubsub numsub: PUBSUB NUMSUB news.it news.internet news.sport news.music
pubsub numpat:
punsubscribe: 。
subscribe: 。 subscribe msg chat_room
unsubscribe: 。
4) value
exists(key): key
del(key): key
type(key):
keys(pattern): pattern key
randomkey: key
keyrename(oldname, newname): key
dbsize: key
expire: key (s)
ttl: key
select(index):
move(key, dbindex): key dbindex
flushdb: key
flushall: key
5)String
set(key, value): key string value
get(key): key string value
getset(key, value): key string value
mget(key1, key2,…, key N): string value
setnx(key, value): string, key, value
setex(key, time, value): string, time
mset(key N, value N): string
msetnx(key N, value N): key i string
incr(key): key string 1
incrby(key, integer): key string integer
decr(key): key string 1
decrby(key, integer): key string integer
append(key, value): key string value
substr(key, start, end): key string value
6)List
rpush(key, value): key list value
lpush(key, value): key list value
llen(key): key list
lrange(key, start, end): key list start end
ltrim(key, start, end): key list
lindex(key, index): key list index
lset(key, index, value): key list index
lrem(key, count, value): count key list value
lpop(key): key list
rpop(key): key list
blpop(key1, key2,… key N, timeout):lpop block 。
brpop(key1, key2,… key N, timeout):rpop block 。
rpoplpush(srckey, dstkey): srckey list , dstkey list
7)Set
sadd(key, member): key set member
srem(key, member) : key set member
spop(key) : key set
smove(srckey, dstkey, member) :
scard(key) : key set
sismember(key, member) :member key set
sinter(key1, key2,…key N) :
sinterstore(dstkey, (keys)) : dstkey
sunion(key1, (keys)) :
sunionstore(dstkey, (keys)) : dstkey
sdiff(key1, (keys)) :
sdiffstore(dstkey, (keys)) : dstkey
smembers(key) : key set
srandmember(key) : key set
8)Hash
hset(key, field, value): key hash field
hget(key, field): key hash field value
hmget(key, (fields)): key hash field i value
hmset(key, (fields)): key hash field
hincrby(key, field, integer): key hash field value integer
hexists(key, field): key hash field
hdel(key, field): key hash field
hlen(key): key hash
hkeys(key): key hash
hvals(key): key hash value
hgetall(key): key hash (field) value
2、redis-benchmark関連
redis-benchmark-h localhost -p 6379 -c 100 -n 100000
100 ,100000 , host localhost 6379 redis
./redis-benchmark -n 100000 –c 50
====== –c 50 ======
100000 requests completed in 1.93 seconds (100000 1.93 )
50 parallel clients ( 50 )
3 bytes payload ( 3 )
keep alive: 1 ( 1 )
58.50% <= 0 milliseconds
99.17% <= 1 milliseconds
99.58% <= 2 milliseconds
99.85% <= 3 milliseconds
99.90% <= 6 milliseconds
100.00% <= 9 milliseconds
( 62 )
114293.71 requests per second( 114293.71 )
redis-benchmark
-h IP , 127.0.0.1
-p , 6379
-s ( )
-c
-n
-d / ( 3 )
-k 1: ( )0:
-r SET/GET/INCR , 10 rand:000000000000 - rand:000000000009
-P 1( ), , ( )
-q , 。
--csv CSV
-l ,ctrl+c
-t , :-t ping,set,get
-I 。 50 。
:
$ redis-benchmark
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
$ redis-benchmark -t set -n 1000000 -r 100000000
$ redis-benchmark -t ping,set,get -n 100000 –csv
$ redis-benchmark -r 10000 -n 10000 lpush mylist ele:rand:000000000000
3.redis-server
Redis daemon
redis-server [/path/to/redis.conf]
redis-server /biran/conf/redis.conf
redis-server - (read config from stdin)
redis-server --test-memory 256 256MB
redis-server –version
redis-server /etc/sentinel.conf --sentinel sentinel
4.redis-cli
Redis 。 , telnet
redis-cli 。
redis-cli
-h IP , 127.0.0.1
-p , 6379
-s ( )
-a Master
-r N
-i N , –i 0.1 info( 0.1 )
-n N ID , –n 3( 3 )
-x
-d ( :
)
--raw
--latency
--latency-history
--latency-dist
--latency、--latency-history、--latency-dist。 , 。
--slave
--stat redis 。info , , requests( )
--pipe
--bigkeys key ,--bigkeys -i 0.1
--eval lua
--raw --no-raw #--no-raw 。--raw 。
--help
--version
:
$ redis-cli
$ redis-cli -r 3 info info
$ cat testStr.txt | redis-cli -x set testStr testStr.txt testStr
$ redis-cli -r 100 lpush mylist x
$ redis-cli -r 100 -i 1 info | grep used_memory_human
5.サーバの情報と統計を取得する
redis-cli info 。 localhost, 6379。
redis-cli -p 6379 info | grep '\' used_memory
used_memory_rss maxmemory used_memory_peak maxmemory , maxmemory
6.redis TTLキー値削除メカニズム
1. hz, 。 , key 25% 。 :
1) 100 key
2) key
3) key 25 1
2. , , 。 ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC(25), 25% cpu 。
:timelimit = 1000000*ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC/server.hz/100
7.redisコマンドの例
query
redis-cli MONITOR | head -n 5000 | ./redis-faina.py
cli monitor, 。
oom
redis-cli debug oom
redis-cli debug segfault
hang
redis-cli -p 6379 DEBUG sleep 30
SLOWLOG GET 10
ID、 、 10 , 128 。 , 10 , , 。
slowlog get
slowlog len
slowlog reset
:
config set slow-log-slower-than 20000
config set slow-max-len 1000
config rewrite
redis-cli-h--stat redis監視コマンド付き
[root@localhost Desktop]# redis-cli -h 192.168.1.216 --stat
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
27 1.24M 7 0 1198768 (+0) 2206
27 1.24M 7 0 1198769 (+1) 2206
27 1.24M 7 0 1198770 (+1) 2206
27 1.24M 7 0 1198771 (+1) 2206
27 1.24M 7 0 1198772 (+1) 2206
27 1.24M 7 0 1198773 (+1) 2206
27 1.24M 7 0 1198774 (+1) 2206
27 1.24M 7 0 1198775 (+1) 2206
27 1.24M 7 0 1198776 (+1) 2206
27 1.24M 7 0 1198777 (+1) 2206
27 1.24M 7 0 1198778 (+1) 2206
27 1.24M 7 0 1198779 (+1) 2206
27 1.24M 7 0 1198780 (+1) 2206
27 1.27M 7 0 1198782 (+2) 2206
27 1.24M 7 0 1198783 (+1) 2206
27 1.24M 7 0 1198784 (+1) 2206
27 1.24M 7 0 1198785 (+1) 2206
redis-cli -h --slave
redis , redis 。 redis , 。
redis-cli -h -r 5 -i 1 ping 5 ( ms, 10ms 0.01) , -r 。