Commits

Alexey Kishkin committed 3d44a43

Add comments and LGPL license

Comments (0)

Files changed (2)

                                                                      
  @author Alexey Kishkin odobenus-rosmarus@ya.ru                      
 
+
+ This file is part of omcbp.
+ 
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+     
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+         
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 **********************************************************************)
 
 (* Low level operations *)
 
 exception Bad_memcache_format of string;;
 
+(* Some auxilary functions for buffer constructing *)
+
 let set_i8 buffer i =
    Buffer.add_char buffer (Char.chr (i land 0xff));;
 
    badd (ex i 8);
    badd (ex i 0);;
 
+(* Buffer disassembling *)
+
 let get_i8 str n = Char.code(str.[n]);;
 
 let get_i16 str n =
    and b8 = Int64.of_int (Char.code str.[n + 7]) in
    Int64.logor (Int64.logor (Int64.logor b1 b2) (Int64.logor b3 b4)) (Int64.logor (Int64.logor b5 b6) (Int64.logor b7 b8));;
 
+
+(* Main class for binary protocol
+  Parameters:
+    host - string - address of memcache server 
+    port - integer - internet port 
+ *)
+
 class memcache_connector (host: string) (port: int) =
 object(self)
    val host = host
       let (key, extras, value) = self#decode_body body keylength extralength total_body_length in
       (status, op, key, value, extras, opaque, cas)
    
+   (* Set cache data.
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
    method set key v flags expiration =
       let buf = Buffer.create 8 in
       let _ = set_i32 buf flags and _ = set_i32 buf expiration in
          let (status, op, ky, value, extras, opaque, cas) = self#read_answer in
          (status, ky, value)
       end
+
+   (* Set 'quietly' (don't wait for answer) cache data.
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
    
    method setq key v flags expiration =
       let buf = Buffer.create 8 in
          output_string o_channel cargo;
          flush o_channel
       end
+  
+  (* Add (operation fails if key already exists) cache data.
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
+
    
    method add key v flags expiration =
       let buf = Buffer.create 8 in
          let (status, op, ky, value, extras, opaque, cas) = self#read_answer in
          (status, ky, value)
       end
+
+  (* Add (operation fails if key already exists) cache data. Dont wait the answer.
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
    
    method addq key v flags expiration =
       let buf = Buffer.create 8 in
          output_string o_channel cargo;
          flush o_channel;
       end
+      
+      
+  (* replace (operation fails if key doesnt exist) cache data.
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
+      
    
    method replace key v flags expiration =
       let buf = Buffer.create 8 in
          (status, key, value)
       end
    
+ (* replace quietly (dont wait answer)  cache data. Ooperation fails if key doesn't exist
+   Params:
+   
+     key  - string 
+     value - string 
+     flags - integer - 
+     expiration - integer - seconds to invalidation this record
+   *)
+ 
    method replaceq key v flags expiration =
       let buf = Buffer.create 8 in
       let _ = set_i32 buf flags and _ = set_i32 buf expiration in
          output_string o_channel cargo;
          flush o_channel;
       end
+ 
+   (* Delete key *)
    
    method delete key =
       let cargo = self#encode_packet Delete key "" "" 0 0L in
          (status, key, value)
       end
    
+   (* Delete key , dont wait the answer *)
+   
    method deleteq key =
       let cargo = self#encode_packet DeleteQ key "" "" 0 0L in
       begin
          flush o_channel;
       end
    
+   (* Retrieve key
+   Param  
+      key - string
+   returns:
+      (status, key, value)
+      Key and value -- strings,  Status is 'response_status" type 
+    *)
    method get key =
       let cargo = self#encode_packet GetK key "" "" 0 0L in
       begin
          let (status, op, key, value, extras, opaque, cas) = self#read_answer in
          (status, key, value)
       end
+
+
+   (* Retrieve  a lot of records at once
+   Param  
+      keys - list of string
+   returns:
+      list of (status, key, value)
+      Key and value -- strings,  Status is 'response_status" type 
+    *)
    
    method multiget keys =
       List.iter (fun key ->
          done;
          !answers
       end
+
+  (* Increment value in the cache
+   Param  
+      key - string
+      value_to_add int64
+      initial_value int64
+      expiration - time in seconds to invalidation
+   returns:
+      (status, key, value)
+      Key and value -- strings,  Status is 'response_status" type 
+    *)
    
    method incr key (value_to_add: int64) (initial_value: int64) expiration =
       let buf = Buffer.create 20 in
          let (status, op, key, value, extras, opaque, cas) = self#read_answer in
          (status, key, value)
       end
+
+
+
+  (* Increment value in the cache, dont wait for answer
+   Param  
+      key - string
+      value_to_add int64
+      initial_value int64
+      expiration - time in seconds to invalidation
+    *)
    
    method incrq key (value_to_add: int64) (initial_value: int64) expiration =
       let buf = Buffer.create 20 in
          output_string o_channel cargo;
          flush o_channel;
       end
-   
+
+      
+   (* Decrement valie in the cache 
+   Param  
+      key - string
+      value_to_add int64
+      initial_value int64
+      expiration - time in seconds to invalidation
+   returns:
+      (status, key, value)
+      Key and value -- strings,  Status is 'response_status" type 
+    *)
    method decr key (value_to_sub: int64) (initial_value: int64) expiration =
       let buf = Buffer.create 20 in
       let _ = set_int64 buf value_to_sub
          let (status, op, key, value, extras, opaque, cas) = self#read_answer in
          (status, key, (get_int64 value 0))
       end
-   
+   (* The same but dont wait for answer *)
    method decrq key (value_to_sub: int64) (initial_value: int64) expiration =
       let buf = Buffer.create 20 in
       let _ = set_int64 buf value_to_sub
          output_string o_channel cargo;
          flush o_channel;
       end
-   
+  
+  (* Close connection *) 
    method quit =
       let cargo = self#encode_packet Quit "" "" "" 0 0L in
       begin
          let (status, op, key, value, extras, opaque, cas) = self#read_answer in
          (status, key, value)
       end
-   
+
+  (* Close connection, dont wait for answer *) 
    method quitq =
       let cargo = self#encode_packet QuitQ "" "" "" 0 0L in
       begin
    
 end;;
 
+
+
+(* Example *)
 let print_result (status, key, value) =
    print_string (key^" :: ");
    print_endline (match status with
+(***********************************************************************
+                                                                     
+ Memcached Client library module (binary protocol)                   
+                                                                     
+ @author Alexey Kishkin odobenus-rosmarus@ya.ru                      
+
+
+ This file is part of omcbp.
+ 
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+     
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+         
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+**********************************************************************)
+
 type operation =
     Get
   | Set