Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how to get values from pipeline.Exec() #13

Closed
ihsw opened this issue Nov 2, 2013 · 7 comments
Closed

Unclear how to get values from pipeline.Exec() #13

ihsw opened this issue Nov 2, 2013 · 7 comments

Comments

@ihsw
Copy link

ihsw commented Nov 2, 2013

Hi, I'm not sure how to get values from pipeline.Exec().

cmd.Val() results in type redis.Cmder has no field or method Val

It's very odd because reflect.TypeOf(cmd) does indeed return *redis.StringCmd, and both the docs and the code quite clearly indicate that the Val() method should be working.

@vmihailenco
Copy link
Collaborator

Hi,

I updated pipelined example to show how to get *redis.StringCmd from redis.Cmder: http://godoc.org/github.com/vmihailenco/redis/v2#example-Client-Pipelined . Also take a look at http://godoc.org/github.com/vmihailenco/redis/v2#example-Pipeline , which can be useful in your case.

@ihsw
Copy link
Author

ihsw commented Nov 6, 2013

Thanks for the quick reply! I'm new to Go so I didn't consider type assertion. I will try this out tomorrow.

@vmihailenco
Copy link
Collaborator

You are welcome.

@echoface
Copy link

echoface commented Apr 2, 2018

the follow link broken,
http://godoc.org/github.com/vmihailenco/redis/v2#example-Client-Pipelined http://godoc.org/github.com/vmihailenco/redis/v2#example-Pipeline
I Got A Error ‘redis: nil’ when i execute code as below:

	pip := redisClient.Pipeline()
	if _, err := pip.Ping().Result(); err != nil {
		log.Errorln("redis pipeline ping failed, err:", err.Error())
	} else {
		//here is ok
		log.Errorln("redis pipeline ping ok")
	}
	results := make([]*redis.StringCmd, 0)
	for _, key := range keys {
		results = append(results, pip.Get(key))
	}
	_, err := pip.Exec()
	if err != nil {
		return make([]int64, len(keys)), errors.Wrapf(err, "Redis Pipeline Execute Error")
	}

@pedrobertao
Copy link

You have to check if the err is equal to redis.Nil

res, err := pipeline.Exec(ctx)
if err != redis.Nil {
	log.Fatal(err)
}

@MatteoGioioso
Copy link

MatteoGioioso commented Jan 20, 2022

Both links are broken and I cannot find it, but this is what I have worked out.

       ......
	pipeline := redisClient.Pipeline()
	pipeline.Get("123")
	pipeline.Get("456")
        ....

	exec, err := pipeline.Exec()
	if err != nil {
		log.Fatal(err)
	}

	results := make([]*redis.StringCmd, 0)
	for _, cmder := range exec {
		results = append(results, cmder.(*redis.StringCmd))
	}

	fmt.Printf("%+v\n", results[0].Val())

Although it works, I am not 100% sure this is correct.

@vmihailenco
Copy link
Collaborator

Docs for pipelines are at https://redis.uptrace.dev/guide/pipelines.html . Let me know if anythign is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants