Redisの一般的なメンテナンスコマンドを記録します

17168 ワード

一、コマンドセット
  • auth passwd認証登録
  • TIMEタイムスタンプとマイクロ秒数を表示
  • DBSIZE現在のライブラリのkey数を表示
  • BGREWRITEAOFバックグラウンドプロセス書き換えAOF
  • BGSAVEバックグラウンド保存rdbスナップショット
  • SAVE保存rdbスナップショット
  • LASTSAVE前回保存時間
  • SLAVEOFをslaveサーバ
  • に設定
  • FLUSHALLすべてのdb
  • をクリア
  • FLUSHDB現在のdb
  • をクリア
  • SHUTDOWN[""|save|nosave]接続を切断し、サーバをシャットダウン
  • SLOWLOG表示スロークエリ
  • INFO表示サーバ情報
  • CONFIGGET取得構成情報
  • CONFIGSET設定構成情報
  • MONITORオープンコンソール
  • SYNCマスタスレーブ同期
  • CLIENT LISTクライアントリスト
  • CLIENT KILLクライアントをシャットダウン
  • CLIENT SETNAMEクライアント名
  • CLIENT GETNAMEクライアント名取得
  • 二、いくつかの比較的よく使われるコマンド
    1.infoコマンド(Redisサーバの各種情報と統計値を表示可能)
    # Server
    redis_version:2.6.9
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_mode:standalone
    os:Linux 3.4.9-gentoo x86_64
    arch_bits:64
    multiplexing_api:epoll          # redis       
    gcc_version:4.6.3
    process_id:18926
    run_id:df8ad7574f3ee5136e8be94aaa6602a0079704cc #   redis server    
    tcp_port:6379
    uptime_in_seconds:120           # redis server     (  s)
    uptime_in_days:0                # redis server     (  d)
    lru_clock:321118                # Clock incrementing every minute, for LRU management TODO          
    
    # Clients
    connected_clients:3             #        
    client_longest_output_list:0    #                   TODO
    client_biggest_input_buf:0      #             buffer TODO
    blocked_clients:0               #         
    
    # Memory
    used_memory:573456              #     ,  B
    used_memory_human:560.02K       # human read      
    used_memory_rss:1798144         #    redis     (     )
    used_memory_peak:551744         #          
    used_memory_peak_human:538.81K  # human read        
    used_memory_lua:31744           # lua       
    mem_fragmentation_ratio:3.14    # used_memory_rss/used_memory  ,     ,used_memory_rss   used_memory,        , mem_fragmentation_ratio   ,            
    mem_allocator:jemalloc-3.3.1    #      
    
    # Persistence
    ##########################
    # rdb aof redis        
    #
    # rdb         save           
    #                     db
    #        crash,      
    #          
    #
    # aof                     
    #        
    #   appendfsync always appendfsync eversec
    #           ,      ,        
    #         ,    crash,      1s   
    ##########################
    loading:0                       #
    rdb_changes_since_last_save:0   #    dump rdb   
    rdb_bgsave_in_progress:0        #   rdb save     
    rdb_last_save_time:1366359865   #   save    
    rdb_last_bgsave_status:ok       #    save    
    rdb_last_bgsave_time_sec:-1     #   rdb save       (  s)
    rdb_current_bgsave_time_sec:-1  #   rdb save      ,        
    ----------------------------
    aof_enabled:0                   #     aof,     
    aof_rewrite_in_progress:0       #   aof rewrite        
    aof_rewrite_scheduled:0         #        rdb save       
    aof_last_rewrite_time_sec:-1    #   rewrite       (  s)
    aof_current_rewrite_time_sec:-1 #   rewrite      ,         
    aof_last_bgrewrite_status:ok    #   rewrite     
    -----------------------------
    #   aof      info  
    aof_current_size:0              # aof    
    aof_base_size:0                 # aof     rewrite   
    aof_pending_rewrite:0           #     aof_rewrite_scheduled
    aof_buffer_length:0             # aof buffer   
    aof_rewrite_buffer_length:0     # aof rewrite buffer   
    aof_pending_bio_fsync:0         #   IO     fsync     
    aof_delayed_fsync:0             #    fsync    TODO
    -----------------------------
    
    # Stats
    total_connections_received:7    #           
    total_commands_processed:7      #            
    instantaneous_ops_per_sec:0     #          
    rejected_connections:0          #             ,           
    expired_keys:0                  #        key   
    evicted_keys:0                  #         ,           
    keyspace_hits:0                 #  main dictionary(todo)      key  
    keyspace_misses:0               #   ,    key   
    pubsub_channels:0               #   /     
    pubsub_patterns:0               #   /     
    latest_fork_usec:0              #    fork       (  ms)
    ##########################
    # pubsub          ,         
    #         ,         ,         
    #       SUBSCRIBE            
    #       PSUBSCRIBE                   
    ##########################
    
    # Replication
    role:master                     #   
    connected_slaves:1              #       
    slave0:127.0.0.1,7777,online
    -----------------------------
    role:slave
    master_host:127.0.0.1
    master_port:6379
    master_link_status:up
    master_last_io_seconds_ago:4
    master_sync_in_progress:0       #    redis      redis
    slave_priority:100
    slave_read_only:1
    connected_slaves:0
    
    # CPU
    used_cpu_sys:0.00           # redis server sys cpu   
    used_cpu_user:0.12          # redis server user cpu   
    used_cpu_sys_children:0.00  #      sys cpu   
    used_cpu_user_children:0.00 #      user cpu   
    
    # Keyspace
    db0:keys=2,expires=0
    db1:keys=1,expires=0
    

    2.config(redis構成属性値を表示可能)
    構文:[config get xxx]たとえば:
    //  timeout  
    127.0.0.1:6379> config get timeout
    1) "timeout"
    2) "600"
    127.0.0.1:6379> 
    

    同様にconfig set[プロパティ][プロパティ値]もあり、指定したプロパティ値にパラメータを設定します.
    3.client list(確立した接続をリアルタイムで表示)
    127.0.0.1:6379> client list
    id=13636 addr=10.1.60.25:57398 fd=106 name= age=28543 idle=6274 flags=N db=1 sub=0 psub=3 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=psubscribe
    id=14071 addr=10.1.60.25:36923 fd=150 name= age=6342 idle=6 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=ping
    id=14116 addr=127.0.0.1:37037 fd=6 name= age=28 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
    127.0.0.1:6379> 
    

    クライアントリストの対応するフィールドの意味を列挙します.
           :
    addr :          
    fd :             
    age :           
    idle : 【         】
    flags :     flag
    db :              ID
    sub :         
    psub :         
    multi :             
    qbuf :         (     , 0            )
    qbuf-free :             (     , 0         )
    obl :         (     , 0            )
    oll :            (             ,                       )
    omem :                  
    events :        
    cmd :          
        flag          :
    O :      MONITOR         (slave)
    S :          (normal)     
    M :        (master)
    x :          
    b :            
    i :         VM I/O   (   )
    d :      (watched)      , EXEC      
    c :            ,    
    u :        (unblocked)
    A :          
    N :       flag
              :
    r :       (    loop  )    (readable)
    w :       (    loop  )    (writeable)
    

    idleで対応する値が高い場合は、redisのtimeoutプロパティ設定に問題があることを示します.config get timeoutと組み合わせてタイムアウト時間を確認し、timeoutが0の場合、この機能が無効になっていることを示すと、redis接続数が解放されないという問題が発生する可能性があります.
    4.client kill(接続を殺す)
    CLIENT KILL 127.0.0.1:43501
    

    5.slowlog(redisスロークエリの表示)
    Slow logの動作は2つの構成パラメータ(configuration parameter)によって指定され、redisを書き換えることができる.confファイルは、CONFIGGETコマンドとCONFIGSETコマンドで動的に変更されます.最初のオプションはslowlog-log-slower-thanです.実行時間がマイクロ秒(microsecond、1秒=1000000マイクロ秒)より大きいクエリーを記録するかどうかを決定します.たとえば、次のコマンドを実行すると、slow logはすべてのクエリー時間が100マイクロ秒以上のクエリーを記録します.CONFIG SET slow-log-slower-than 100です.次のコマンドは、すべてのクエリー時間が1000マイクロ秒以上のクエリーを記録します.CONFIG SET slow-log-slow-slower-than 1000のもう一つのオプションはslow-max-lenです.slow logが最大何個のログを保存できるかを決定します.slow log自体はFIFOキューであり、キューサイズがslowlog-max-lenを超えると、最も古いログが削除され、最新のログがslow logに追加されます.次のコマンドは、slow logに最大1000個のログを保存します.CONFIG SET slowlog-max-len 1000は、CONFIGGETコマンドを使用して、2つのオプションの現在の値を問い合わせることができます.
    redis> CONFIG GET slowlog-log-slower-than
    1) "slowlog-log-slower-than"
    2) "1000"
    
    redis> CONFIG GET slowlog-max-len
    1) "slowlog-max-len"
    2) "1000"
    

    slow logを表示slow logを表示するには、すべてのslow logを印刷するSLOWLOG GETまたはSLOWLOG GET numberコマンドを使用します.最大長はslow-max-lenオプションの値に依存しますが、SLOWLOG GET numberは指定された数のログのみを印刷します.最新のログが最初に印刷されます.
    テストのためにslowlog-log-slower-thanを10マイクロ秒に設定しました
    redis> SLOWLOG GET
    1) 1) (integer) 12                      #    (unique)      
       2) (integer) 1324097834              #            ,  UNIX        
       3) (integer) 16                      #       ,      
       4) 1) "CONFIG"                       #      ,        
          2) "GET"                          #          CONFIG GET slowlog-log-slower-than
          3) "slowlog-log-slower-than"
    
    2) 1) (integer) 11
       2) (integer) 1324097825
       3) (integer) 42
       4) 1) "CONFIG"
          2) "GET"
          3) "*"
    
    3) 1) (integer) 10
       2) (integer) 1324097820
       3) (integer) 11
       4) 1) "CONFIG"
          2) "GET"
          3) "slowlog-log-slower-than"
    

    ログの唯一のidは、Redisサーバが再起動するたびにリセットされます.これにより、ログの重複処理を回避できます(たとえば、新しい遅いクエリーが発見されるたびにメールで通知したい場合があります).現在のログの数を表示コマンドSLOWLOG LENを使用して、現在のログの数を表示します.この値とslower-max-lenの違いに注意してください.1つは現在のログの数であり、1つは記録が許可されている最大ログの数です.
    redis> SLOWLOG LEN
    (integer) 14
    

    クリアログコマンドSLOWLOG RESETを使用してslow logをクリアします.
    redis> SLOWLOG LEN
    (integer) 14
    redis> SLOWLOG RESET
    OK
    redis> SLOWLOG LEN
    (integer) 0
    

    6.Redis-benchmarkはRedis性能をテストする
    Usage: redis-benchmark [-h ] [-p ] [-c ] [-n  [-k ]
    
     -h       Server hostname (default 127.0.0.1)
     -p           Server port (default 6379)
     -s         Server socket (overrides host and port)
     -c        Number of parallel connections (default 50)
     -n       Total number of requests (default 10000)
     -d           Data size of SET/GET value in bytes (default 2)
     -k        1=keep alive 0=reconnect (default 1)
     -r    Use random keys for SET/GET/INCR, random values for SADD
      Using this option the benchmark will get/set keys
      in the form mykey_rand:000000012456 instead of constant
      keys, the  argument determines the max
      number of values for the random number. For instance
      if set to 10 only rand:000000000000 - rand:000000000009
      range will be allowed.
     -P         Pipeline  requests. Default 1 (no pipeline).
     -q                 Quiet. Just show query/sec values
     --csv              Output in CSV format
     -l                 Loop. Run the tests forever
     -t          Only run the comma-separated list of tests. The test
                        names are the same as the ones produced as output.
     -I                 Idle mode. Just open N idle connections and wait.
    

    テストコマンド事例:1、redis-benchmark-h 192.168.1.201-p 6379-c 100-n 100000 100個同時接続、100000個要求、hostがlocalhostポート6379のredisサーバ性能2、redis-benchmark-h 192.168.1.201-p 6379-q-d 100テストアクセスサイズ100バイトのパケットの性能3、redis-benchmark-t set、lpush-n 100000-q特定の動作のパフォーマンスのみをテストする4、redis-benchmark-n 100000-q script load「redis.call('set','foo','bar')」特定の数値アクセスのパフォーマンスのみをテストする
    テスト結果の分析:
    requests completed in 0.30 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.11% <= 1 milliseconds
    86.00% <= 2 milliseconds
    90.12% <= 3 milliseconds
    96.68% <= 4 milliseconds
    99.27% <= 5 milliseconds
    99.54% <= 6 milliseconds
    99.69% <= 7 milliseconds
    99.78% <= 8 milliseconds
    99.89% <= 9 milliseconds
    100.00% <= 9 milliseconds
    33222.59 requests per second
    
    ====== PING_BULK ======
    requests completed in 0.27 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.93% <= 1 milliseconds
    97.66% <= 2 milliseconds
    100.00% <= 2 milliseconds
    37174.72 requests per second
    
    ====== SET ======
    requests completed in 0.32 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.22% <= 1 milliseconds
    91.68% <= 2 milliseconds
    97.78% <= 3 milliseconds
    98.80% <= 4 milliseconds
    99.38% <= 5 milliseconds
    99.61% <= 6 milliseconds
    99.72% <= 7 milliseconds
    99.83% <= 8 milliseconds
    99.94% <= 9 milliseconds
    100.00% <= 9 milliseconds
    30959.75 requests per second
    
    ====== GET ======
    requests completed in 0.28 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.55% <= 1 milliseconds
    98.86% <= 2 milliseconds
    100.00% <= 2 milliseconds
    35971.22 requests per second
    
    ====== INCR ======
    requests completed in 0.14 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    95.61% <= 1 milliseconds
    100.00% <= 1 milliseconds
    69444.45 requests per second
    
    ====== LPUSH ======
    requests completed in 0.21 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    18.33% <= 1 milliseconds
    100.00% <= 1 milliseconds
    48309.18 requests per second
    
    ====== LPOP ======
    requests completed in 0.23 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.29% <= 1 milliseconds
    99.76% <= 2 milliseconds
    100.00% <= 2 milliseconds
    44052.86 requests per second
    
    ====== SADD ======
    requests completed in 0.22 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    2.37% <= 1 milliseconds
    99.81% <= 2 milliseconds
    100.00% <= 2 milliseconds
    44444.45 requests per second
    
    ====== SPOP ======
    requests completed in 0.22 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    4.27% <= 1 milliseconds
    99.84% <= 2 milliseconds
    100.00% <= 2 milliseconds
    44642.86 requests per second
    
    ====== LPUSH (needed to benchmark LRANGE) ======
    requests completed in 0.22 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    12.35% <= 1 milliseconds
    99.62% <= 2 milliseconds
    100.00% <= 2 milliseconds
    46082.95 requests per second
    
    ====== LRANGE_100 (first 100 elements) ======
    requests completed in 0.48 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.01% <= 1 milliseconds
    3.27% <= 2 milliseconds
    98.71% <= 3 milliseconds
    99.93% <= 4 milliseconds
    100.00% <= 4 milliseconds
    20964.36 requests per second
    
    ====== LRANGE_300 (first 300 elements) ======
    requests completed in 1.26 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.01% <= 2 milliseconds
    0.14% <= 3 milliseconds
    0.90% <= 4 milliseconds
    7.03% <= 5 milliseconds
    31.68% <= 6 milliseconds
    78.93% <= 7 milliseconds
    98.88% <= 8 milliseconds
    99.56% <= 9 milliseconds
    99.72% <= 10 milliseconds
    99.95% <= 11 milliseconds
    100.00% <= 11 milliseconds
    7961.78 requests per second
    
    ====== LRANGE_500 (first 450 elements) ======
    requests completed in 1.82 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.01% <= 2 milliseconds
    0.06% <= 3 milliseconds
    0.14% <= 4 milliseconds
    0.30% <= 5 milliseconds
    0.99% <= 6 milliseconds
    2.91% <= 7 milliseconds
    8.11% <= 8 milliseconds
    43.15% <= 9 milliseconds
    88.38% <= 10 milliseconds
    97.25% <= 11 milliseconds
    98.61% <= 12 milliseconds
    99.26% <= 13 milliseconds
    99.30% <= 14 milliseconds
    99.44% <= 15 milliseconds
    99.48% <= 16 milliseconds
    99.64% <= 17 milliseconds
    99.85% <= 18 milliseconds
    99.92% <= 19 milliseconds
    99.95% <= 20 milliseconds
    99.96% <= 21 milliseconds
    99.97% <= 22 milliseconds
    100.00% <= 23 milliseconds
    5491.49 requests per second
    
    ====== LRANGE_600 (first 600 elements) ======
    requests completed in 2.29 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.01% <= 2 milliseconds
    0.05% <= 3 milliseconds
    0.10% <= 4 milliseconds
    0.19% <= 5 milliseconds
    0.34% <= 6 milliseconds
    0.46% <= 7 milliseconds
    0.58% <= 8 milliseconds
    4.46% <= 9 milliseconds
    21.80% <= 10 milliseconds
    40.48% <= 11 milliseconds
    60.14% <= 12 milliseconds
    79.81% <= 13 milliseconds
    93.77% <= 14 milliseconds
    97.14% <= 15 milliseconds
    98.67% <= 16 milliseconds
    99.08% <= 17 milliseconds
    99.30% <= 18 milliseconds
    99.41% <= 19 milliseconds
    99.52% <= 20 milliseconds
    99.61% <= 21 milliseconds
    99.79% <= 22 milliseconds
    99.88% <= 23 milliseconds
    99.89% <= 24 milliseconds
    99.95% <= 26 milliseconds
    99.96% <= 27 milliseconds
    99.97% <= 28 milliseconds
    99.98% <= 29 milliseconds
    100.00% <= 29 milliseconds
    4359.20 requests per second
    
    ====== MSET (10 keys) ======
    requests completed in 0.37 seconds
    parallel clients
    bytes payload
      keep alive: 1
    
    0.01% <= 1 milliseconds
    2.00% <= 2 milliseconds
    18.41% <= 3 milliseconds
    88.55% <= 4 milliseconds
    96.09% <= 5 milliseconds
    99.50% <= 6 milliseconds
    99.65% <= 7 milliseconds
    99.75% <= 8 milliseconds
    99.77% <= 9 milliseconds
    99.78% <= 11 milliseconds
    99.79% <= 12 milliseconds
    99.80% <= 13 milliseconds
    99.81% <= 15 milliseconds
    99.82% <= 16 milliseconds
    99.83% <= 17 milliseconds
    99.84% <= 19 milliseconds
    99.85% <= 21 milliseconds
    99.86% <= 23 milliseconds
    99.87% <= 24 milliseconds
    99.88% <= 25 milliseconds
    99.89% <= 27 milliseconds
    99.90% <= 28 milliseconds
    99.91% <= 30 milliseconds
    99.92% <= 32 milliseconds
    99.93% <= 34 milliseconds
    99.95% <= 35 milliseconds
    99.96% <= 36 milliseconds
    99.97% <= 37 milliseconds
    99.98% <= 39 milliseconds
    99.99% <= 41 milliseconds
    100.00% <= 41 milliseconds
    27173.91 requests per second
    

    参照ドキュメント:http://www.cnblogs.com/silent2012/p/4514901.html http://www.runoob.com/redis/server-client-list.html http://dba10g.blog.51cto.com/764602/1846068 http://blog.csdn.net/cxhgg/article/details/67640263