Browse files

improve README.markdown

  • Loading branch information...
1 parent 313d692 commit d923579703336653557e0552f5903097e8ff15bb @echou committed Dec 4, 2009
Showing with 51 additions and 42 deletions.
  1. +51 −42 README.markdown
View
93 README.markdown
@@ -12,63 +12,72 @@ application:start(mcache)
application:stop(mcache).
</pre>
-It requires the following configuration (in -config <ConfigFile> or sys.config)
+It requires the following configuration (in `-config <ConfigFile>` or `sys.config`)
<pre>
{mcache,
- [{pools,[
- [{name, generic}, % Pool name is "generic"
- {servers, [ { {1,0,0,1}, 11211, 256 }, % Servers definition. IP address should be in {A,B,C,D} format
- { {1,0,0,2}, 11211, 256 }
- ]}]
- ]}
-]}
+ [
+ {pools,[
+ [{name, generic}, % Pool name is "generic"
+ {servers,
+ [
+ { {1,0,0,1}, 11211, 256 }, % Servers definition. IP address should be in {A,B,C,D} format
+ { {1,0,0,2}, 11211, 256 }
+ ]}
+ ]
+ ]}
+ ]
+}
</pre>
## Usage
1. Get a single key.
-<pre>
-mcache:get(Class, Key).
-</pre>
+ <pre>
+ mcache:get(Class, Key).
+ </pre>
+ For example: `mcache:get(my.friends, foobar)` gets the key `"my.friends:foobar"`
+
+ Which memcached server is selected? The following steps go:
+ 1. Get expiry config from `Class`. Default is `{generic, 300}` (i.e. `{PoolName, ExpireSeconds}`)
+ 1. Get the server continuum from the pool name. (in ketama's consistent hashing algorithm)
+ 1. Calc the server from Key's MD5 hash value according the above continuum.
-For example: <code>mcache:get(my.friends, foobar)</code> gets the key <code>"my.friends:foobar"</code>
+ **Return values**:
+ - `undefined`, if key not found.
+ - `Value`, any other values.
-Which memcached server is selected? The following steps go:
-1. Get expiry config from <code>Class</code>, default is <code>{generic, 300}</code> (i.e. <code>{PoolName, ExpireSeconds}</code>)
-2. Get the server continuum from the pool name. (in ketama's consistent hashing algorithm)
-3. Calc the server from Key's MD5 hash value.
-
-Return values:
-- <code>undefined</code>, if key not found.
-- <code>Value</code>, any other values.
+1. Get multiple keys.
+ <pre>
+ mcache:mget(Class, [Key|_]).
+ </pre>
-2. Get multiple keys.
-<pre>
-mcache:mget(Class, [Key|_]).
-</pre>
-
-Note: it gets all the keys with the same <code>Class</code>.
-
-3. Set a key and value.
-<pre>
-mcache:set(Class, Key, Value, Format, Expiry)
-</pre>
+ Note: it gets all the keys with the same `Class`.
-Format can be the following atoms:
+1. Set a key and value.
+ <pre>
+ mcache:set(Class, Key, Value, Format, Expiry)
+ </pre>
-- <code>raw</code>, as iolist.
-- <code>native</code>, term_to_binary()
-- <code>json</code>, convert to json string (using an enhanced version of EEP0018)
-- <code>int</code>, data in <<Int:32>> format.
+ **Class** is any atom or iolist.
+ **Key** can be any iolist.
-Expiry can be as follows:
+ **Format** can be the following atoms:
+ - `raw`, an iolist.
+ - `native`, any Erlang term (uses `term_to_binary()`)
+ - `json`, convert to json string (using an enhanced version of EEP0018)
+ - `int`, data in `<<Int:32>>` format.
-- <code>default</code>, uses ExpireConfig
-- <code>infinity</code>, no expiration
-- <code>{X, seconds}</code>, or minutes, hours, days, etc.
-- <code>Integer</code>, any numeric seconds.
+ **Expiry** can be as following:
+ - `default`, uses ExpireConfig
+ - `infinity`, no expiration
+ - `{X, seconds}`, or minutes, hours, days, etc.
+ - `Integer`, any numeric seconds.
+ This argument can be ignored. `default` is used in this case.
-This argument can be ignored. <code>default</code> is used in this case.
+ **Return**
+ * A list of {Key, Value} pairs. The key doesn't contain `Class` part.
+ * Missing keys **won't** show in the list.
+ * If all keys are missing, an empty list ([]) is returned.

0 comments on commit d923579

Please sign in to comment.