Designing a Clojure library for working with FoundationDB
This talk introduces the reader to the basic concepts of FoundationDB and takes them through the journey of building a Clojure library - https://github.com/vedang/clj_fdb - for interacting with it.
Key must be byte-array / Tuple, returns byte-ar (fc/set db k v) ; Key/Val must be byte-array or Tuple (fc/clear db k) ; Key must be byte-array or Tuple (fc/get-range db k) ; Returns a map of all kvs under k (fc/clear-range db k) ; Clears all kvs under k 24
opts contains: {:async? true :limit 10 ;; ... } ;; If opts takes up the 4th arity, having subspace in the ;; top-level becomes awkward. ;; Clojure's arglists metadata help here. (fc/get-range db k) (fc/get-range db k opts) ; These two clash, but okay (fc/get-range db s k) ; These two clash, but okay (fc/get-range db s k opts) 30
(fc/get db s k) (fc/set db k v), (fc/set db s k v) (fc/clear db k), (fc/clear db s k) (fc/get-range db k), (fc/get-range db s k) (fc/clear-range db k), (fc/clear-range db s k) 31
it for the latest API (let [prev (to-int (fc/get db attendance))] (fc/set db members-spc [member-id "attends" event-id] []) (fc/set db events-spc [event-id "attendance_counter"] (to-byte-array (inc prev)))) 34
result of the function (ftr/run db (fn [tr])) ;; Blocking, only accepts reads on DB keys (ftr/read db (fn [tr])) ;; Non-blocking, immediately returns future (ftr/run-async! db (fn [tr])) ;; Non-blocking, immediately returns future (ftr/read-async! db (fn [tr])) 41
me and sharing his code! Talk to me about: 1. This Library: Use v0.3.0 and above • vedang/clj_fdb 2. Data modeling using FDB 3. Design patterns. 4. Working at Helpshift! mailto:[email protected] / @vedang on Twitter 46