Storage Commands

set

Most common command. Store this data, possibly overwriting any existing data. New items are at the top of the LRU.

add

Store this data, only if it does not already exist. New items are at the top of the LRU. If an item already exists and an add fails, it promotes the item to the front of the LRU anyway.

replace

Store this data, but only if the data already exists. Almost never used, and exists for protocol completeness (set, add, replace, etc)

append

Add this data after the last byte in an existing item. This does not allow you to extend past the item limit. Useful for managing lists.

prepend

Same as append, but adding new data before existing data.

cas

Check And Set (or Compare And Swap). An operation that stores data, but only if no one else has updated the data since you read it last. Useful for resolving race conditions on updating cache data.

Retrieval Commands

get

Command for retrieving data. Takes one or more keys and returns all found items.

gets

An alternative get command for using with CAS. Returns a CAS identifier (a unique 64bit number) with the item. Return this value with the cas command. If the item's CAS value has changed since you gets'ed it, it will not be stored.

delete

Removes an item from the cache, if it exists.

incr/decr

Increment and Decrement. If an item stored is the string representation of a 64bit integer, you may run incr or decr commands to modify that number. You may only incr by positive values, or decr by positive values. They does not accept negative values.

If a value does not already exist, incr/decr will fail.

Statistics

There're a handful of commands that return counters and settings of the memcached server. These can be inspected via a large array of tools or simply by telnet or netcat. These are further explained in the protocol docs.

stats

ye 'ole basic stats command.

stats items

Returns some information, broken down by slab, about items stored in memcached.

stats slabs

Returns more information, broken down by slab, about items stored in memcached. More centered to performance of a slab rather than counts of particular items.

stats sizes

A special command that shows you how items would be distributed if slabs were broken into 32byte buckets instead of your current number of slabs. Useful for determining how efficient your slab sizing is.

WARNING this is a development command. As of 1.4 it is still the only command which will lock your memcached instance for some time. If you have many millions of stored items, it can become unresponsive for several minutes. Run this at your own risk. It is roadmapped to either make this feature optional or at least speed it up.

flush_all

Invalidate all existing cache items. Optionally takes a parameter, which means to invalidate all items after N seconds have passed.

This command does not pause the server, as it returns immediately. It does not free up or flush memory at all, it just causes all items to expire.

Expiration in memcached

Expiration in memcached is lazy. In general, an item cannot be known to be expired until something looks at it.

If you fetch an expired item, memcached will find the item, notice that it's expired, and free its memory. This gives you the common case of normal cache churn reusing its own memory.

Think of it this way: You can add billions of items to memcached that all expire at the exact same second, but no additional work is performed during that second by memcached itself. Only as you attempt to retrieve (or update) those items will memcached ever notice that they shouldn't be there. At this point, curr_items will be decremented by each item it has seen expired.

We may also notice expired items while searching for memory for new items, though this isn't likely to create an observable difference in curr_items because we'll be replacing it with a new item anyway.

Storing sets or lists

Storing lists of data into memcached can mean either storing a single item with a serialized array, or trying to manipulate a huge "collection" of data by adding, removing items without operating on the whole set. Both should be possible.

One thing to keep in mind is memcached's 1 megabyte limit on item size, so storing the whole collection (ids, data) into memcached might not be the best idea.

Steven Grimm explains a better approach on the mailing list: http://lists.danga.com/pipermail/memcached/2007-July/004578.html

Chris Hondl and Paul Stacey detail alternative approaches to the same ideal: http://lists.danga.com/pipermail/memcached/2007-July/004581.html

A combination of both would make for very scalable lists. IDs between a range are stored in separate keys, and data is strewn about using individual keys.

Reference

Click for more detail about memcached

Recommend to Read

Basic command and advice for memcached的更多相关文章

  1. linux shell basic command

    Learning basic Linux commands Command Description $ ls This command is used to check the contents of ...

  2. unix basic command

    1. get start Command Example Description ls ls ls -a ls -l 输出目录文件 输出文件包括隐藏文件 输出文件详细信息 pwd pwd show p ...

  3. Raspberry Pi 3 Basic Command and Information

    default username : pi default password : raspberry enter system setting interface : sudo raspi-confi ...

  4. [转]Installing Memcached on Windows

    Installing Memcached on Windows 原文链接https://commaster.net/content/installing-memcached-windows   Sub ...

  5. Linux--Introduction and Basic commands(Part one)

    Welcome to Linux world! Introduction and Basic commands--Part one J.C 2018.3.11 Chapter 1 What Is Li ...

  6. memcached空指针内存错误与死循环问题分析(memcached dead loop and crash bug! issue #260 and issue #370)

    (由于这是发在memcached邮件列表的,所以只能用一下蹩脚的英文了) (you should read the discuss about issue #260 first:  https://g ...

  7. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  8. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  9. Awesome Go (http://awesome-go.com/)

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

随机推荐

  1. c语言程序设计第6周编程作业一(分解质因数)

    分解质因数 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. 现在,你的程 ...

  2. Beta第三天

    听说

  3. Beta版本敏捷冲刺每日报告——Day4

    1.情况简述 Beta阶段第四次Scrum Meeting 敏捷开发起止时间 2017.11.5 08:00 -- 2017.11.5 22:00 讨论时间地点 2017.11.5晚9:00,软工所实 ...

  4. transient 与 volatile 笔记

    1. transient 词义:瞬间的,短暂的 首先说说"序列化",把一个对象的表示转化为字节流的过程称为串行化(也称为序列化,serialization),从字节流中把对象重建出 ...

  5. NOIP2016 天天爱跑步 正解

    暴力移步 http://www.cnblogs.com/TheRoadToTheGold/p/6673430.html 首先解决本题应用的知识点: dfs序——将求子树的信息(树形)转化为求一段连续区 ...

  6. HTML 字符集

    在 HTML 中,正确的字符编码是什么?   HTML5 中默认的字符编码是 UTF-8. 这并非总是如此.早期网络的字符编码是 ASCII 码.后来,从 HTML 2.0 到 HTML 4.01,I ...

  7. Ajax 的onreadystatechange事件注意事项.

    <script type="text/javascript"> function createXHR() { var request = false; try { re ...

  8. JAVA_SE基础——60.初识Object

    java是面向对象的语言,核心思想:找适合 的对象做适合 的事情:方式一:自定义类,然后通过自定义的类创建对象.方式二:sun提供了很多的类给我使用,我们只需要认识这些类,我们就可以通过这些类创建对象 ...

  9. Linux的rsync 配置,用于服务器之间远程传大量的数据

    [教程主题]:rsync [课程录制]: 创E [主要内容] [1] rsync介绍 Rsync(Remote Synchronize) 是一个远程资料同步工具,可通过LAN/WAN快速同步多台主机, ...

  10. 【笔记】HybridApp中使用Promise化的JS-Bridge

    背景: HybridApp,前端采用JS-bridge的方式调用Native的接口,如获取设备信息.拍照.人脸识别等 前端封装了调用库,每次调用Native接口,需要进行两步操作(1.在window下 ...