Go + Redis – 入门教程无法正常工作

huangapple go评论132阅读模式
英文:

Go + Redis - Tutorial Get Started doesn't work

问题

你好,

我制作了几个关于Redis和Go的教程网站。
其中大部分页面都无法正常工作。
这是一个非常简单的无法工作的示例。

https://developer.redis.com/develop/golang/

以下是错误信息:

# command-line-arguments
./main.go:17:29: 调用client.cmdable.Ping时参数过多
	已有 (context.Context)
	期望 ()

如何使教程正常工作?

英文:

Hi,

I have made several redis and go tutorial sites.
Most of the pages don't work.
Here's a very simple one that doesn't work.

https://developer.redis.com/develop/golang/

And here is the error message.

# command-line-arguments
./main.go:17:29: too many arguments in call to client.cmdable.Ping
	have (context.Context)
	want ()

How to make the tutorial work?

答案1

得分: 2

你使用的是哪个版本的go-redis?在版本8中应该可以工作。github.com/go-redis/redis/v8

请参考这个示例代码,了解如何使用它:https://github.com/go-redis/redis/blob/master/example_test.go

go-redisv1版本中,函数签名不包括context.Context查看代码。你很可能导入了没有v8后缀的go redis,因此导入了go-redis v1(在go中,库的v1版本不需要v...后缀)。

英文:

What version of go-redis are you using? In version 8 it should work.
github.com/go-redis/redis/v8.

See this example code on how to use it: https://github.com/go-redis/redis/blob/master/example_test.go

In v1 of go-redis the function signature does not include context.Context. See the code. You've most likely imported go redis without the v8 suffix, thus importing go-redis v1. (in go the v1 version of a library does not require the v... suffix).

huangapple
  • 本文由 发表于 2022年9月14日 14:24:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/73712364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定