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. JavaScript(第二十七天)【错误处理与调试】

    JavaScript在错误处理调试上一直是它的软肋,如果脚本出错,给出的提示经常也让人摸不着头脑.ECMAScript第3版为了解决这个问题引入了try...catch和throw语句以及一些错误类型 ...

  2. 杭电OJ2004——成绩转换

    /*成绩转换Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. Hibernate学习错误集锦-GenericJDBCException: could not execute statement

    初次使用Hibernate,进行junit测试,报如下错误. 原因:Hibernate帮我们管理主键了,我们不需要对主键赋值,并且主键是自增的.所以在数据库中,逐渐选项应当勾选 org.hiberna ...

  4. C++数据结构中的基本算法排序

    冒泡排序 基本思想:两两比较待排序的数,发现反序时交换,直到没有反序为止. public static void BubbleSort(int[] R) { for (int i = 0; i < ...

  5. python的项目结构

    项目结构 知识点 创建项目,编写 __init__ 文件 使用 setuptools 模块,编写 setup.py 和 MANIFEST.in 文件 创建源文件的发布版本 项目注册&上传到 P ...

  6. tableView//collectionView加载时的动画

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:( ...

  7. 剑指offer-二叉树中和为某一值的路径

    题目描述 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.   解题思路 利用前序遍历的思想,定义FindP ...

  8. [翻译]现代java开发指南 第三部分

    现代java开发指南 第三部分 第三部分:Web开发 第一部分,第二部分,第三部分 =========================== 欢迎来到现代 Java 开发指南第三部分.在第一部分中,我们 ...

  9. webpack你值得拥有-从四个核心配置谈起

    很久没有发文章了,但是强调一点,大-熊同学最近可没闲着.学习算法,复习计算机网络,也顺便学习了一下webpack,看了看操作系统(没办法,都没学,要是不学连实习笔试都过不了,伤心--).本来比较纠结是 ...

  10. 老帖收藏,留供参考:SpringMvc2.5+Mybatis3.2.7

    一.项目背景 SpringMvc+Mybatis 数据库连接池是阿里巴巴的druid.日志框架式logback 二.配置文件 1.SpringMvc-servlet.xml <?xml vers ...