Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

init atoms from core, handle varios errors

  • Loading branch information...
commit dea953f80604a7756a85baa7c8ee8b2b51c0fb5d 1 parent bb013b8
@yankov authored
View
16 src/memobot/core.clj
@@ -30,6 +30,11 @@
[db]
[:pong])
+
+(defn init-atom
+ [k v]
+ (intern (symbol (namespace k)) (symbol (name k)) (atom v)))
+
(defn exec
"Executes a command"
[db protocol-str]
@@ -39,14 +44,19 @@
command-table ((keyword (symbol (first redis-command))) commands)
mode (command-table 1)
command (command-table 0)
+ empty-val (command-table 2)
key-exists? (not (nil? (exists? k)))]
(try
(cond
(and (not key-exists?) (= mode "w"))
- (do
- (eval (conj args (resolve command))))
+ (if (contains? #{:nokeyerr :czero} empty-val)
+ [empty-val]
+ (do
+ (if (not (nil? empty-val))
+ (init-atom k empty-val))
+ (eval (conj args (resolve command)))))
(and (not key-exists?) (= mode "r"))
- [(command-table 2)]
+ [empty-val]
(and key-exists? (= mode "r"))
(eval (conj args (resolve command)))
(and key-exists? (= mode "w"))
View
14 src/memobot/redis.clj
@@ -10,14 +10,14 @@
{:use 'use-db
:set ['memobot.strings/set-cmd "w" nil]
:get ['memobot.strings/get-cmd "r" :nokeyerr]
- :keys ['memobot.core/keys-cmd "r"]
+ :keys ['memobot.core/keys-cmd "r" nil]
:type ['memobot.core/type-cmd "r" "none"]
- :del ['memobot.core/del-cmd "w" nil]
- :ping ['memobot.core/ping-cmd "r"]
- :incr ['memobot.strings/incr-cmd "w" "0"]
- :decr ['memobot.strings/decr-cmd "w" "0"]
- :incrby ['memobot.strings/incrby-cmd "w" "0"]
- :decrby ['memobot.strings/decrby-cmd "w" "0"]
+ :del ['memobot.core/del-cmd "w" :czero]
+ :ping ['memobot.core/ping-cmd "r" nil]
+ :incr ['memobot.strings/incr-cmd "w" 0]
+ :decr ['memobot.strings/decr-cmd "w" 0]
+ :incrby ['memobot.strings/incrby-cmd "w" 0]
+ :decrby ['memobot.strings/decrby-cmd "w" 0]
:setnx ['memobot.strings/setnx-cmd "w" nil]
:strlen ['memobot.strings/strlen-cmd "r" :czero]
:hdel ['memobot.hashes/hdel-cmd "w" nil]
View
2  src/memobot/strings.clj
@@ -33,8 +33,6 @@
[db k]
(let [ck (symbol (str db "/" k))]
(try
- (if (not (resolve ck))
- (set-cmd db k "0"))
[:int (swap! (eval ck) inc)]
(catch ClassCastException e (do (prn "caught exception: " (.getMessage e)) [:nointerr])))))
Please sign in to comment.
Something went wrong with that request. Please try again.