Go memcached Usage--Details of parameters and commands

Source: Internet
Author: User
Tags cas delete key memcached

memcached Usage--arguments and commands in detail 1. Memcached parameter Description:
# memcached -h
1.1 Parameters of Memcached

Common parameters

-p <num> 监听的TCP端口号,默认是11211;(port)-l <addr> 监听的主机地址,默认是INADDR_ANY,即所有地址,<addr>可以是host:port的形式,如果没有指定port,则使用-p或者-U的值;可以指定多个地址,以逗号分隔或者多次使用-l参数;尽量不要使用默认值,有安全隐患。(listen)-d 以守护进程运行 (daemon)-u <username> 指定进程的所有者(只有以root用户执行时才可以使用该参数)(username)-m <num> 用于存储数据的最大内存,单位是MB,默认是64MB;(memory)-c <num> 最大并发连接数,默认是1024;-vv 显示更详细的信息(还显示客户端的命令和响应)-vvv 显示最详细的信息(还显示内部的状态转变)-h 显示帮助信息-P <file> 将PID保存到<file>中,仅和-d参数一起使用;-f <factor> chunk的增幅因子,默认是1.25,不同的slab class,slab page大小相同,但是chunk大小不等,chunk的大小根据这个增幅因子增长;(factor)-n <bytes> 为key+value+flags分配的最小内存,单位bytes,默认是48;chunk数据结构本身要占据48字节,所以实际大小是n+48;-t <num> 使用多少个线程,默认是4;(thread)-I 设置slab page的大小,即设置可以保存的item的最大值,默认1MB,最小是1K,最大值128M;

Other parameters

-U <num> 监听的UDP端口号,默认是11211,0表示关闭UDP监听;(UDP)-s <file> 要监听的UNIX socket路径(禁用网络支持)(socket)-a <mask> UNIX socket的访问掩码(access mask),八进制表示,默认是0700. (mask)-r 文件数量的最大值 (rlimit)-M 内存耗尽时返回错误,而不是通过LRU淘汰内容;-k 锁定所有页内存;允许被锁定的内存是有限制的,超过限制可能会失败。-v 显示启动信息(错误和警告信息)(verbose)-i 显示memcached和libevent的licence信息-L 一次申请大的内存页(如果可以);增大内存页的大小,可以提高性能;-D <char> 指定key前缀与ID的分隔符,用于stats信息显示,默认是冒号:,如果使用了该参数,则stats收集自动启用了,否则,需要发送命令“stats detail on”命令来启动stats的收集。-R 每一个事件(event)的最大请求数,限制最大请求数可以防止线程饥饿,默认是20;-C 禁用CAS;-b 设置backlog队列限制,默认1024;-B 指定绑定协议,ascii,binary或者auto,其中auto是默认值;
1.2 Parameters of repcached:
-x <ip_addr> peer主机的主机名或者ip地址;-X peer主机的TCP端口,即主从同步端口,共同的监听端口
1.3 Common combinations of parameters
# memcached -d -m -p 11212 -u nobody -l 127.0.0.1 -x 127.0.0.1 -X 11222 -P /tmp/localhost_slave.pid -vv
2. Basic commands and Operations 2.1 stored commands

Main: set,add,replace,append,prepend,cas; format:

command key flag expiration_time bytesvalue

Key represents the keys, flag represents key/value additional information, expiration_time indicates the expiration time, in seconds, 0 means never expires, bytes represents the value of the number of bytes, must exactly match, value represents the value corresponding to key, always appear in the second row.

The set command indicates that a key/value pair is stored, and if the key already exists, the corresponding value value is updated, and if successful, stored is returned.

set file_path 0 0 5/opt/<29 rep file_path 0 0 5 12REP>29 STOREDSTORED

The Add command also indicates an increase in key/value, and if the key/value already exists, the add operation fails, the save succeeds returning STORED, and the failure returns not_stored.

add file_path 0 60 5/opt/NOT_STOREDadd file_suffix 0 0 2js<29 rep file_suffix 0 0 2 16REP>29 STOREDSTORED

The Replace command indicates that the value corresponding to the key is updated, and if Key/value does not exist, the replace operation fails, the STORED succeeds, and the failure returns not_stored;

replace first 0 0 7tianjinSTOREDreplace second 0 0 8shanghaiNOT_STORED

Append indicates that the value of the key corresponds to the append data, the key must already exist, otherwise the operation failed; successfully returned STORED, failed to return not_stored;

append second 0 0 8shanghaiNOT_STOREDappend first 0 0 3 goSTORED

Prepend append the data to the value of the key corresponding key must already exist, otherwise the operation fails, the STORED is returned successfully, the failure returns not_stored;

prepend second 0 0 2hiNOT_STOREDprepend first 0 0 2hiSTOREDget firstVALUE first 0 15hitianjin go goEND

CAS (check and set): Compare after store, that is, atom update, the principle is similar to optimistic. Each time a data request is stored with a CAS value, the memcached is equal to the CAS value of the current stored data, and if it is equal, the data is updated, otherwise the operation fails; the currently stored CAs value is obtained by the get command. Successfully returned stored, failed to return exists.

gets firstVALUE first 0 7 12        // 12表示cas id,可以理解为版本号chengduENDcas first 0 0 8 10        // 10 != 12,cas失败shanghaiEXISTScas first 0 0 8 12        // 12表示gets后没有修改key的值,因此可以setshanghaiSTORED
2.2 Commands to read

Get value by key, can get the value of multiple keys; get key | Get Key1 Key2

get firstVALUE first 0 8shanghaiENDget first fineVALUE first 0 8shanghaiVALUE fine 0 5yes!!END

Get is a command that is used with CAS, which returns an additional CAS value, which can be understood as a version; If the CAS value changes after the last get, the value of the CAS setting is not stored; Get key | Gets Key1 Key2

gets firstVALUE first 0 8 13shanghaiENDset first 0 0 7chengduSTOREDcas first 0 0 7 13        // 因为gets后set了,所以cas id改变了,cas失败chengduEXISTS

Delete command deletes key/value pair, only one key/value pair can be deleted at a time; if the key to be removed does not exist, the operation fails: Delete key

delete first secondCLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]delete firstDELETED

INCR/DECR: If the value of key represents a 64-bit integer, the value can be increased or decreased by the incr and DECR commands: INCR/DECR key num

set id 0 120 210STOREDincr id 1020decr id 515
2.3 Statistics of the order

Stats displays information such as process and current status.

Statsstat PID 1224//Process Idstat uptime 30385//system run event in seconds Stat time 1392199633//system current event when Unix timestamp represented Room: 2/12/2014 6:25:40 pmstat version 1.4.13//memcached version stat libevent 2.0.21-stable//libevent version Stat Pointe R_size 64//Os Word size (64 bit) stat Rusage_user 1.892712//Process Cumulative User Time stat Rusage_system 0.996848//Process cumulative system Time STAT cur R_connections 8//Number of connections currently open stat Total_connections 9//Total number of connections that have been turned on stat connection_structures 9//server allocated number of connection structures STA            T Reserved_fds 20STAT cmd_get 29//Total number of Execute GET commands stat cmd_set 29//Total number of Execute SET commands stat Cmd_flush 2 Total number of execution Flush_all commands stat Cmd_touch 0 stat get_hits Stat get_misses Delete_misses 3 STAT delete_hits 3STAT incr_misses 0STAT incr_hits 4STAT decr_misses 0STAT decr_hits 2STAT Cas_miss Es 1STAT cas_hits 2STAT cas_badval 2STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 1503STAT Bytes_written 4125STAT limit_maxbytes 134217728STAT Accepting_conns 1STAT listen_disabled_num 0STAT threads 4//Thread Count stat C Onn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT expired_unfetched 0STAT evicted_ unfetched 0STAT replication Masterstat repcached_version 2.3.1STAT repcached_qi_free 8191STAT bytes 217// Number of item bytes stored stat curr_items 3//Current Item Quantity stat Total_items//Item Total STAT Evictions 0// Number of item to get space deleted stat reclaimed 2END

Stats items show information about items

stats itemsSTAT items:1:number 3STAT items:1:age 1552STAT items:1:evicted 0STAT items:1:evicted_nonzero 0STAT items:1:evicted_time 0STAT items:1:outofmemory 0STAT items:1:tailrepairs 0STAT items:1:reclaimed 2STAT items:1:expired_unfetched 0STAT items:1:evicted_unfetched 0END

Stats Slabs Show information about the slab

stats slabsSTAT 1:chunk_size 96STAT 1:chunks_per_page 10922STAT 1:total_pages 1STAT 1:total_chunks 10922STAT 1:used_chunks 3STAT 1:free_chunks 0STAT 1:free_chunks_end 10919STAT 1:mem_requested 217STAT 1:get_hits 14STAT 1:cmd_set 29STAT 1:delete_hits 3STAT 1:incr_hits 4STAT 1:decr_hits 2STAT 1:cas_hits 2STAT 1:cas_badval 2STAT 1:touch_hits 0STAT active_slabs 1STAT total_malloced 1048512END

Stats sizes

stats sizesSTAT 96 3END

Stats Cachedump Displays information about items in slab (this command may no longer be supported in the future): Stats cachedump [slab ID] [number of items, 0 for all items]

set city 0 0 7tianjinSTOREDstats cachedump 1 0ITEM city [7 b; 1392169248 s]ENDget cityVALUE city 0 7tianjinEND

Flush_all causes all items in the cache to expire, the server does not stop, and the memory is not refreshed or freed.

flush_allOKget firstEND
Reference
    • Memcached Wiki
    • memcached command-line Operations
    • memcached command-line parameter description
    • Memcached detailed
    • this article Daniel
    • This article link: http://nkcoder.github.io/2014/02/15/memcached-usage-parameters-commands/

Go memcached Usage--Details of parameters and commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.