Skip to content
Browse files

make mget corrent

  • Loading branch information...
1 parent b075c86 commit 4881a499a0b729c242e9b350d08d9a1509652e2c @echou committed
Showing with 17 additions and 14 deletions.
  1. +5 −1 README.markdown
  2. +7 −7 c_src/memcached_drv.cpp
  3. +4 −5 src/mcache.erl
  4. +1 −1 src/memcached_drv.erl
View
6 README.markdown
@@ -28,17 +28,21 @@ application:start(mcache).
fetches \<Prefix>:\<Key> from memcached.
+* Prefix and Key can be atom, string, binary, list or tuple. tuple/list items are separated by ":".
+* returns `undefined` if not found.
+* unbox to correct format according to the type it was set. (see `mcache:set`)
**set**
mcache:set(Prefix, Key, Value, Type, Timeout)
+* Prefix and Key can be atom, list, binary, iolist or integer.
* Value: depends on `Type`, can be binary, iolist, int or erlang term.
* Type: can be one of `raw` (binary), `native` (erlang term, saved in `term_to_binary` format), `int` (an integer).
* Timeout: can be one of `default` (default expiration: 300 seconds), `infinity`, `{X, seconds}`, `{X, minutes}`, `{X, hours}`, `{X, days}`, or an integer (as is).
*Note 1*: no reply is returned for best performance.
-*Note 2*: `Type` is encoded as memcached protocol field `flags`: 0 - `raw`, 1 - `native`, 100 - `int`.
+*Note 2*: `Type` is encoded as memcached protocol field `flags`: 0 - `raw`, 100 - `native`, 103 - `int`.
**delete**
View
14 c_src/memcached_drv.cpp
@@ -239,7 +239,7 @@ class Driver
td.open_tuple();
td.add_buf(result->item_key, result->key_length);
- td.add_buf(result->value.string, result->value.current_size);
+ td.add_buf(result->value.string, result->value.end - result->value.string);
td.add_uint(result->item_flags);
td.close_tuple();
}
@@ -253,16 +253,16 @@ class Driver
TermData td = createReply(seq);
// <<Count:32, KeyLen:32, Key/binary, ...>>
- int num_keys;
- if (!vec.get(num_keys) || num_keys <= 0 || num_keys>2000)
+ size_t num_keys;
+ if (!vec.get(num_keys) || num_keys == 0 || num_keys>2000)
goto L_badarg;
char * keys[num_keys];
size_t lengths[num_keys];
- for(int i=0;i<num_keys;i++)
+ for(size_t i=0;i<num_keys;i++)
{
- if (!(vec.get(lengths[i]) && vec.get(keys[i], lengths[i]+1))) // trailing zero is included
+ if (!(vec.get(lengths[i]) && vec.get(keys[i], lengths[i])))
goto L_badarg;
//printf("key #%d = %s\r\n", i, keys[i]);
}
@@ -297,7 +297,7 @@ class Driver
td.open_list();
int ri = 0;
- for(int i=0; i<num_keys; i++)
+ for(size_t i=0; i<num_keys; i++)
{
memcached_result_st* r = NULL;
for(size_t j=ri; j<results.size(); j++)
@@ -314,7 +314,7 @@ class Driver
{
td.open_tuple();
//td.add_buf(result->key, result->key_length);
- td.add_buf(r->value.string, r->value.current_size);
+ td.add_buf(r->value.string, r->value.end-r->value.string);
td.add_uint(r->item_flags);
td.close_tuple();
}
View
9 src/mcache.erl
@@ -29,12 +29,11 @@ get_raw(Class, Key) ->
mget(Class, [_|_]=Keys) ->
{Pool, _Expiry} = mcache_expires:expire(Class),
- RealKeys = lists:foldl(fun(K, Acc) ->
- K1 = mcache_util:map_key(Class, K),
- [K1|Acc]
- end, [], Keys),
+ RealKeys = lists:map(fun(K) ->
+ mcache_util:map_key(Class, K)
+ end, Keys),
- {mc_async, 0, {ok, Values}} = memcached_drv:mget(Pool, 0, lists:reverse(RealKeys)),
+ {mc_async, 0, {ok, Values}} = memcached_drv:mget(Pool, 0, RealKeys),
mget_zip(Keys, Values, []).
set(Class, Key, Value, Format, Expiry) ->
View
2 src/memcached_drv.erl
@@ -183,7 +183,7 @@ ab_mget(Pool, Seq, [_|_]=Keys) ->
K1 = to_binary(K),
KLen = byte_size(K1),
<<A/binary, KLen:32, K1/binary>>
- end, <<?CMD_MGET, Seq:32, NumKeys:32>>, Keys),
+ end, <<?CMD_MGET2, Seq:32, NumKeys:32>>, Keys),
erlang:port_command(Port, Data).
mget(Pool, Seq, Keys, Timeout) ->

0 comments on commit 4881a49

Please sign in to comment.
Something went wrong with that request. Please try again.