Skip to content

Instantly share code, notes, and snippets.

@isterin
Created August 6, 2010 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isterin/510707 to your computer and use it in GitHub Desktop.
Save isterin/510707 to your computer and use it in GitHub Desktop.
(defgeneric put-method-for (mode)
(:method ((mode (eql :replace))) #'kcdbset)
(:method ((mode (eql :keep))) #'kcdbadd)
(:method ((mode (eql :concat))) #'kcdbappend))
(defun put (key value &key (mode :replace))
(funcall (put-method-for mode) key value))
;; definitions of methods for kcdbset, kcdbadd, and kcdbappend define methods
;; that store key/value pairs with different behaviors based on whether
;; that key already exists.
;; For more info see: http://github.com/isterin/cl-kyoto-cabinet
;; Usage...
;; Will store some_val under some_key
(put "some_key" "some_val" :mode :replace)
;; Will not do anything, as it will invoke kcdbadd, which does
;; nothing if the key exists
(put "some_key" "some_val" :mode :keep)
;; Will add some_val2 to some_key by using kcdbappend
(put "some_key" "some_val2" :mode :concat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment