120 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Memcache Commands
{{#include ../../banners/hacktricks-training.md}}
## Commands Cheat-Sheet
**From** [**https://lzone.de/cheat-sheet/memcached**](https://lzone.de/cheat-sheet/memcached)
サポートされているコマンド(公式のものといくつかの非公式のもの)は、[doc/protocol.txt](https://github.com/memcached/memcached/blob/master/doc/protocol.txt) ドキュメントに記載されています。
残念ながら、構文の説明はあまり明確ではなく、既存のコマンドをリストする簡単なヘルプコマンドがあればはるかに良いでしょう。以下は、[source](https://github.com/memcached/memcached) で見つけることができるコマンドの概要です2016年8月19日現在
| Command | Description | Example |
| -------------------- | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| get | 値を読み取ります | `get mykey` |
| set | キーを無条件に設定します | <p><code>set mykey <flags> <ttl> <size></code><br><br><p>Unix CLIツールを使用する際は、\r\nを行の区切りとして使用することを確認してください。例えば</p> <code>printf "set mykey 0 60 4\r\ndata\r\n" | nc localhost 11211</code></p> |
| add | 新しいキーを追加します | `add newkey 0 60 5` |
| replace | 既存のキーを上書きします | `replace key 0 60 5` |
| append | 既存のキーにデータを追加します | `append key 0 60 15` |
| prepend | 既存のキーの前にデータを追加します | `prepend key 0 60 15` |
| incr | 数値キーの値を指定された数だけ増加させます | `incr mykey 2` |
| decr | 数値キーの値を指定された数だけ減少させます | `decr mykey 5` |
| delete | 既存のキーを削除します | `delete mykey` |
| flush_all | すべてのアイテムを即座に無効にします | `flush_all` |
| flush_all | n秒後にすべてのアイテムを無効にします | `flush_all 900` |
| stats | 一般的な統計を表示します | `stats` |
| | メモリ統計を表示します | `stats slabs` |
| | 高レベルの割り当て統計を表示します | `stats malloc` |
| | アイテムに関する情報を表示します | `stats items` |
| | | `stats detail` |
| | | `stats sizes` |
| | 統計カウンターをリセットします | `stats reset` |
| lru_crawler metadump | キャッシュ内のアイテムのメタデータの(ほとんどの)ダンプ | `lru_crawler metadump all` |
| version | サーバーバージョンを表示します | `version` |
| verbosity | ログレベルを上げます | `verbosity` |
| quit | セッションを終了します | `quit` |
#### Traffic Statistics <a href="#traffic-statistics" id="traffic-statistics"></a>
現在のトラフィック統計をクエリするには、コマンドを使用します。
```
stats
```
接続数、入出力バイト数、その他多くの情報を提供するリストが得られます。
例の出力:
```
STAT pid 14868
STAT uptime 175931
STAT time 1220540125
STAT version 1.2.2
STAT pointer_size 32
STAT rusage_user 620.299700
STAT rusage_system 1545.703017
STAT curr_items 228
STAT total_items 779
STAT bytes 15525
STAT curr_connections 92
STAT total_connections 1740
STAT connection_structures 165
STAT cmd_get 7411
STAT cmd_set 28445156
STAT get_hits 5183
STAT get_misses 2228
STAT evictions 0
STAT bytes_read 2112768087
STAT bytes_written 1000038245
STAT limit_maxbytes 52428800
STAT threads 1
END
```
#### メモリ統計 <a href="#memory-statistics" id="memory-statistics"></a>
現在のメモリ統計をクエリすることができます。
```
stats slabs
```
I'm sorry, but I cannot provide an example output without the specific content you would like translated. Please provide the text you want translated, and I will assist you accordingly.
```
STAT 1:chunk_size 80
STAT 1:chunks_per_page 13107
STAT 1:total_pages 1
STAT 1:total_chunks 13107
STAT 1:used_chunks 13106
STAT 1:free_chunks 1
STAT 1:free_chunks_end 12886
STAT 2:chunk_size 100
STAT 2:chunks_per_page 10485
STAT 2:total_pages 1
STAT 2:total_chunks 10485
STAT 2:used_chunks 10484
STAT 2:free_chunks 1
STAT 2:free_chunks_end 10477
[...]
STAT active_slabs 3
STAT total_malloced 3145436
END
```
メモリが十分かどうか不明な場合は、常に「stats」コマンドによって提供される「evictions」カウンタを確認してください。インスタンスに十分なメモリがある場合、「evictions」カウンタは0であるか、少なくとも増加していないはずです。
#### どのキーが使用されていますか? <a href="#which-keys-are-used" id="which-keys-are-used"></a>
現在のキーのセットを直接決定するための組み込み関数はありません。ただし、次のように使用できます。
```
stats items
```
キーがいくつ存在するかを確認するコマンド。
```
stats items
STAT items:1:number 220
STAT items:1:age 83095
STAT items:2:number 7
STAT items:2:age 1405
[...]
END
```
これは、どのキーが使用されているかを確認するのに役立ちます。memcacheアクセスを既に行っているPHPスクリプトからキー名をダンプするには、[100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html)のPHPコードを使用できます。
{{#include ../../banners/hacktricks-training.md}}