taoensso / carmine

Redis client + message queue for Clojure
https://www.taoensso.com/carmine
Eclipse Public License 1.0
1.15k stars 131 forks source link

evalsha is fining #157

Closed junjiemars closed 8 years ago

junjiemars commented 8 years ago

input: #: keys: (:TYPE :NOT_NULL :PRIMARY_KEY :DEFAULT) keys-count: 4 args: (T1 ID NUMBER 1 1 0)

call evalsha with keys-count, keys, args, then I got

ExceptionInfo ERR Number of keys can't be greater than number of args  clojure.core/ex-info (core.clj:4593)
ptaoussanis commented 8 years ago

Hello,

I'm sorry, I don't understand well. Can you please show an example of your evalsha call?

Have you tried the lua function? It is a bit easier to use.

junjiemars commented 8 years ago

Hi @ptaoussanis , I loaded lua script into the Redis, then use Carmine to call evalsha,

(defn make-table
  [sha t c d]
    (let [m {:TYPE "NUMBER" :NOT_NULL 1 :PRIMARY_KEY 1 :DEFAULT 0}
          k (keys m)
          nk (count k)
          v (conj (vals m) c t)]
      (let [x (c* (c/evalsha sha nk k v))]
        x))))

May be I need make such call (c/evalsha she k v)?

ptaoussanis commented 8 years ago

I see, thank you.

I think maybe you don't understand the API of evalsha command.

The Redis commands eval and evalsha take keys and args.

keys means Redis key names that your script will be writing to or reading from. args means anything else.

Does that make sense?

Are "TYPE", "NOT_NULL", "PRIMARY_KEY" and "DEFAULT" all names of Redis keys that you will be writing to or reading from in your script?

Also: you must call evalsha command like:

(c/evalsha sha nk k1 k2 k3 ... v1 v2 v3 ...) ; Correct
(c/evalsha sha nk [k1 k2 k3 ...] [v1 v2 v3 ...]) ; Wrong, like you do now

So:

(defn make-table
  [sha t c d]
  (let [m {:TYPE "NUMBER" :NOT_NULL 1 :PRIMARY_KEY 1 :DEFAULT 0}
        ks   (keys m)  ; (k1 k2 ...)
        nk   (count k) ; 4
        vs   (conj (vals m) c t) ; (v1 v2 ...)
        args (into (vec ks) vs)  ; (k1 k2 ... kn v1 v2 ... vn)
        ]

    (let [x (c* (apply ; You need this
                  c/evalsha sha nk args))]
      x)))

Does that help?

Good luck! :-)

junjiemars commented 8 years ago

@ptaoussanis It's works, thanks. (c/evalsha sha nk k1 k2 k3 ... v1 v2 v3 ...) ;; it's greate

ptaoussanis commented 8 years ago

No problem :-)