mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
121 lines
10 KiB
Markdown
121 lines
10 KiB
Markdown
# Memcache Commands
|
|
|
|
{{#include ../../banners/hacktricks-training.md}}
|
|
|
|
|
|
## Commands Cheat-Sheet
|
|
|
|
**Da** [**https://lzone.de/cheat-sheet/memcached**](https://lzone.de/cheat-sheet/memcached)
|
|
|
|
I comandi supportati (quelli ufficiali e alcuni non ufficiali) sono documentati nel documento [doc/protocol.txt](https://github.com/memcached/memcached/blob/master/doc/protocol.txt).
|
|
|
|
Purtroppo la descrizione della sintassi non è molto chiara e un semplice comando di aiuto che elenchi i comandi esistenti sarebbe molto meglio. Ecco una panoramica dei comandi che puoi trovare nella [source](https://github.com/memcached/memcached) (a partire dal 19.08.2016):
|
|
|
|
| Command | Description | Example |
|
|
| -------------------- | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
| get | Legge un valore | `get mykey` |
|
|
| set | Imposta una chiave incondizionatamente | <p><code>set mykey <flags> <ttl> <size></code><br><br><p>Assicurati di usare \r\n come interruzioni di riga quando usi strumenti CLI Unix. Ad esempio</p> <code>printf "set mykey 0 60 4\r\ndata\r\n" | nc localhost 11211</code></p> |
|
|
| add | Aggiunge una nuova chiave | `add newkey 0 60 5` |
|
|
| replace | Sovrascrive una chiave esistente | `replace key 0 60 5` |
|
|
| append | Aggiunge dati a una chiave esistente | `append key 0 60 15` |
|
|
| prepend | Prepend dati a una chiave esistente | `prepend key 0 60 15` |
|
|
| incr | Incrementa il valore numerico della chiave di un numero dato | `incr mykey 2` |
|
|
| decr | Decrementa il valore numerico della chiave di un numero dato | `decr mykey 5` |
|
|
| delete | Elimina una chiave esistente | `delete mykey` |
|
|
| flush_all | Invalida immediatamente tutti gli elementi | `flush_all` |
|
|
| flush_all | Invalida tutti gli elementi in n secondi | `flush_all 900` |
|
|
| stats | Stampa statistiche generali | `stats` |
|
|
| | Stampa statistiche di memoria | `stats slabs` |
|
|
| | Stampa statistiche di allocazione di livello superiore | `stats malloc` |
|
|
| | Stampa informazioni sugli elementi | `stats items` |
|
|
| | | `stats detail` |
|
|
| | | `stats sizes` |
|
|
| | Resetta i contatori delle statistiche | `stats reset` |
|
|
| lru_crawler metadump | Dump (la maggior parte) dei metadati per (tutti) gli elementi nella cache | `lru_crawler metadump all` |
|
|
| version | Stampa la versione del server. | `version` |
|
|
| verbosity | Aumenta il livello di log | `verbosity` |
|
|
| quit | Termina la sessione | `quit` |
|
|
|
|
#### Traffic Statistics <a href="#traffic-statistics" id="traffic-statistics"></a>
|
|
|
|
Puoi interrogare le statistiche di traffico attuali utilizzando il comando
|
|
```
|
|
stats
|
|
```
|
|
Otterrai un elenco che fornisce il numero di connessioni, byte in/out e molto altro.
|
|
|
|
Esempio di output:
|
|
```
|
|
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
|
|
```
|
|
#### Statistiche di Memoria <a href="#memory-statistics" id="memory-statistics"></a>
|
|
|
|
Puoi interrogare le statistiche di memoria attuali utilizzando
|
|
```
|
|
stats slabs
|
|
```
|
|
Sure! Please provide the text you would like me to translate.
|
|
```
|
|
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
|
|
```
|
|
Se non sei sicuro di avere abbastanza memoria per la tua istanza memcached, controlla sempre i contatori di "evictions" forniti dal comando "stats". Se hai abbastanza memoria per l'istanza, il contatore "evictions" dovrebbe essere 0 o almeno non in aumento.
|
|
|
|
#### Quali Chiavi Sono Utilizzate? <a href="#which-keys-are-used" id="which-keys-are-used"></a>
|
|
|
|
Non esiste una funzione integrata per determinare direttamente l'attuale insieme di chiavi. Tuttavia, puoi utilizzare il
|
|
```
|
|
stats items
|
|
```
|
|
comando per determinare quanti chiavi esistono.
|
|
```
|
|
stats items
|
|
STAT items:1:number 220
|
|
STAT items:1:age 83095
|
|
STAT items:2:number 7
|
|
STAT items:2:age 1405
|
|
[...]
|
|
END
|
|
```
|
|
Questo aiuta almeno a vedere se vengono utilizzate delle chiavi. Per estrarre i nomi delle chiavi da uno script PHP che già accede a memcache, puoi utilizzare il codice PHP di [100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html).
|
|
|
|
{{#include ../../banners/hacktricks-training.md}}
|