   [root-key]
   (let [last-key (core/last-key (wcar {} (car/get root-key)))] ; need last key to bootstrap
     (core/resolve
-      (->RedisAddr last-key root-key))))
+      (->RedisAddr last-key root-key (synthesize-storage-addr root-key)))))
 
 (comment
   (wcar {} (car/ping) (car/set "foo" "bar") (car/get "foo"))

(ns tree.redis
  (:require [clojure.pprint :as pp]
            [taoensso.carmine :as car :refer (wcar)]
            [tree.core :as core]
            [clojure.core.memoize :as memo]
            [tree.messaging :as msg]))

(def totally-fetch
  (memo/lru (fn [redis-key]

                   (->RedisBackend)
                   ))
  )

(comment

(do
  (wcar {}
      (doseq [k ["foo" "bar" "baz" "quux"]
              e ["" ":rc" ":rs" ":rl"]]
        (car/del (str k e))))

  (do (wcar {} (car/set "foo" 22))
      (wcar {} (car/set "foo:rc" 1))
      (wcar {} (car/set "bar" 33))
      (wcar {} (car/set "baz" "onehundred"))
      (wcar {} (car/set "quux" "teply"))
      (wcar {} (add-refs "baz" ["quux"]))
      (wcar {} (add-refs "foo" ["bar" "baz"])))
  (wcar {} (drop-ref "foo")))
  (doseq [k ["foo" "bar" "baz" "quux"]
          e ["" ":rc" ":rs" ":rl"]]
    (println (str k e) "=" (wcar {} ((if (= e ":rl")
                                       #(car/lrange % 0 -1)
                                       car/get) (str k e))))) 
  (wcar {} (drop-ref "foo"))

  (wcar {} (create-refcounted "foo" 22))

  (wcar {} (car/flushall))
  (count (wcar {} (car/keys "*")))    
  (count (msg/lookup-fwd-iter (create-tree-from-root-key @(:storage-addr (:tree my-tree))) -1))
  (count (msg/lookup-fwd-iter (create-tree-from-root-key @(:storage-addr (:tree my-tree-updated))) -1))
  (def my-tree (core/flush-tree
                 (time (reduce msg/insert
                               (core/b-tree (core/->Config 17 300 (- 300 17)))
                               (range 50000))) 
                 (->RedisBackend)
                 ))
  (def my-tree-updated (core/flush-tree
                         (msg/delete (:tree my-tree) 10)
                         (->RedisBackend)
                         ))
  (wcar {} (car/get (str @(:storage-addr (:tree my-tree)))))
  (wcar {} (car/get (str @(:storage-addr (:tree my-tree-updated)))))
  (wcar {} (car/set "foo" 10))
  (wcar {} (car/get "foo"))
  (wcar {} (drop-ref "foo"))
  (wcar {} (drop-ref @(:storage-addr (:tree my-tree))))
  (wcar {} (drop-ref @(:storage-addr (:tree my-tree-updated))))
  )
