bsm / redeo

High-performance framework for building redis-protocol compatible TCP servers/services
Apache License 2.0
438 stars 39 forks source link

Give example for multi exec commands #21

Closed buzzdan closed 5 years ago

buzzdan commented 5 years ago

When using multi each command returns the string "QUEUED" exec returns the values of the executed commands how do i fetch that value in the client ?

for example for this code:

multi := tx.TxPipeline()
cmd := multi.RPushX(key, ".")
cmds, err := multi.Exec()

i try to use those mocks:


srv.HandleFunc("multi", func(w resp.ResponseWriter, c *resp.Command) {
        w.AppendOK()
    })

srv.Handle("rpushx", redeo.WrapperFunc(func(c *resp.Command) interface{} {
        return "QUEUED"
    }))

srv.Handle("exec", redeo.WrapperFunc(func(c *resp.Command) interface{} {
        return []int{1}
    }))

how can i get the value 1 ? i tried:

c := cmd.Val() // returns 0

or:

count = cmds[0].(*redis.IntCmd).Val() //returns 0 too

Thanks Dan

buzzdan commented 5 years ago

my bad, cmd.Val() returns 1 sorry for that!