Skip to content

Commit

Permalink
ok, now checking type is working
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Yankov committed Sep 12, 2012
1 parent a3039bc commit 8078bec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/memobot/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@

(defn run-func
[command-table k args]

(let [command (first command-table)
response-type (command-table 4)
allowed-types (command-table 1)
mode (command-table 2)]

(if (and (not (= allowed-types [:any])) (not (contains? allowed-types (keyword (type-cmd (deref (eval k)))))))
(do
(prn (type-cmd (fix-type (deref (eval k)))))
[:wrongtypeerr])
(if (or (= allowed-types #{:any}) (contains? allowed-types (keyword (type-cmd (deref (eval k))))))
(if (= mode "r")
[response-type (apply (resolve command) (deref (eval k)) args)]
[response-type (swap! (eval k) #( apply (resolve command) % args ) )]))
[response-type (swap! (eval k) #( apply (resolve command) % args ) )])
[:wrongtypeerr])
))

(defn exec
Expand Down Expand Up @@ -74,7 +73,7 @@
(run-func command-table k args)))
(and (not key-exists?) (= mode "r"))
[empty-val]
(key-exists?)
(true? key-exists?)
(run-func command-table k args))
(catch clojure.lang.ArityException e [:just-err, (str " wrong number of arguments for '" command "' command")])
(catch NullPointerException e [:just-err, (str " unknown command '" (first redis-command) "'")]))))
Expand Down
16 changes: 8 additions & 8 deletions src/memobot/redis.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

(def commands
{:use 'use-db
:set ['memobot.strings/set-cmd #{:string :integer} "w" nil :just-ok]
:get ['memobot.strings/get-cmd #{:string :integer} "r" :nokeyerr :ok]
:set ['memobot.strings/set-cmd #{:string :long :integer} "w" nil :just-ok]
:get ['memobot.strings/get-cmd #{:string :long :integer} "r" :nokeyerr :ok]
:keys ['memobot.core/keys-cmd #{:any} "r" nil :ok]
:type ['memobot.core/type-cmd #{:any} "r" :cnone :ok]
:del ['memobot.core/del-cmd #{:any} "w" :czero :cone]
:ping ['memobot.core/ping-cmd #{:any} "r" nil :pong]
:incr ['memobot.strings/incr-cmd #{:integer} "w" 0 :int]
:decr ['memobot.strings/decr-cmd #{:integer} "w" 0 :int]
:incrby ['memobot.strings/incrby-cmd #{:integer} "w" 0 :int]
:decrby ['memobot.strings/decrby-cmd #{:integer} "w" 0 :int]
:setnx ['memobot.strings/setnx-cmd #{:string :integer} "w" :czero :cone]
:strlen ['memobot.strings/strlen-cmd #{:string :integer} "r" :czero :int]
:incr ['memobot.strings/incr-cmd #{:long :integer} "w" 0 :int]
:decr ['memobot.strings/decr-cmd #{:long :integer} "w" 0 :int]
:incrby ['memobot.strings/incrby-cmd #{:long :integer} "w" 0 :int]
:decrby ['memobot.strings/decrby-cmd #{:long :integer} "w" 0 :int]
:setnx ['memobot.strings/setnx-cmd #{:string :long :integer} "w" :czero :cone]
:strlen ['memobot.strings/strlen-cmd #{:string :long :integer} "r" :czero :int]
:hdel ['memobot.hashes/hdel-cmd "w" nil]
:hget ['memobot.hashes/hget-cmd "r" :nokeyerr]
:hgetall ['memobot.hashes/hgetall-cmd "r" :emptymultibulk]
Expand Down

0 comments on commit 8078bec

Please sign in to comment.