英文:
golang gocql failed to connect to 127.0.0.1:9042 not enough bytes to read header require 9 got: 8
问题
我在尝试编译时遇到了这个错误:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex string
age int
)
func main() {
// 连接到集群
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
cluster.ProtoVersion = 4
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
我在阅读了这里的内容之后添加了这行代码:
cluster.ProtoVersion = 4
但是我还是太新了,不太明白这是否是我的问题,或者我在其他地方做错了什么。我是否需要等待一个修复此问题的 gocql 更新,或者我应该做些什么?
英文:
I get this error trying to compile:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex string
age int
)
func main() {
// connect to the cluster
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
cluster.ProtoVersion = 4
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
I added the line
cluster.ProtoVersion = 4
After reading about it <a href="https://github.com/gocql/gocql/issues/538">here</a> but I'm too new to understand if that's my issue, or I did something wrong elsewhere. Do I have to wait for an update to gocql that fixes this, or what should I do?
答案1
得分: 3
好的,我为你翻译如下内容:
好的,我在github问题#538的讨论中与@Zariel解决了问题。你需要在第一个gocql的代码部分中添加ProtoVersion = 4,像这样:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex, age string
)
func main() {
// 连接到集群
cluster := gocql.NewCluster("127.0.0.1")
cluster.ProtoVersion = 4
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
希望对其他人有所帮助
英文:
Okay, I sorted out with @Zariel on the github issue #538 thread. You have to put the ProtoVersion = 4 up by the first gocql stuff like:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex, age string
)
func main() {
// connect to the cluster
cluster := gocql.NewCluster("127.0.0.1")
cluster.ProtoVersion = 4
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
Hope that helps someone else
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论