windows - 无法创建连接到 Cassandra 的 session

标签 windows go cassandra gocql

我正在使用这个 gocql包。

我正在努力让这个例子发挥作用。

func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
    cluster.ProtoVersion = 3
    cluster.Keyspace = "example"
    cluster.Consistency = gocql.Quorum
    session, err := cluster.CreateSession()
    defer session.Close()
    if err != nil {
       fmt.Printf("%v\n", err)
       return
    }

    uuid := gocql.TimeUUID()
    fmt.Printf("UUID : %v", uuid)

    query := session.Query(`INSERT INTO tweet (timeline, id, text) VALUES         
    (?, ?, ?)`, "me", uuid, "hello world")

    fmt.Println("About to exec")
    err = query.Exec()

    // insert a tweet
    if err != nil {
        log.Fatal(err)
    }

    var id gocql.UUID
    var text string

    /* Search for a specific set of records whose 'timeline' column matches
     * the value 'me'. The secondary index that we created earlier will be
     * used for optimizing the search */
    if err := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?     
    LIMIT 1`,"me").Consistency(gocql.One).Scan(&id, &text); err != nil {
        log.Fatal(err)
    }
    fmt.Println("Tweet:", id, text)

    // list all tweets
    iter := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?`, 
    "me").Iter()
    for iter.Scan(&id, &text) {
        fmt.Println("Tweet:", id, text)
    }
    if err := iter.Close(); err != nil {
        log.Fatal(err)
    }
}

我使用 Cassandra shell 创建了键空间“example”和表“tweet”,它们都工作正常。

但是,当我运行这个程序时,它给我这个错误:

2017/04/14 20:52:55 gocql: unable to dial control conn 192.168.1.3: dial tcp     
192.168.1.3:9042: i/o timeout
gocql: unable to create session: control: unable to connect to initial 
hosts: dial tcp 192.168.1.3:9042: i/o timeoutpanic: runtime error: invalid 
memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x60236d]

goroutine 1 [running]:
github.com/gocql/gocql.(*Session).Close(0x0)
    /home/mda/.local/go/src/github.com/gocql/gocql/session.go:344 +0x2d

由于某种原因,gocql 无法拨通localhost 连接,超时。我不确定如何解决这个问题,到目前为止,stackoverflow 和谷歌搜索都没有帮助。

有什么想法吗?

最佳答案

IP 地址似乎与您计算机上的集群情况不符。在给我 nodetool 状态后,我认为你应该更新 cluster := gocql.NewCluster 以只有 127.0.0.1 地址而不是示例中的地址。

我认为实际上您只是在运行单节点 cassandra 本地实例。这有利于发展。

基本上:

cluster := gocql.NewCluster("127.0.0.1")

把这一行放在一起

cluster.ProtoVersion = 3

关于windows - 无法创建连接到 Cassandra 的 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43422152/

相关文章:

google-app-engine - 中间件错误处理

cassandra - 如何在 CQL3 中设置单个 CQL 查询的一致性级别?

go - 如何修复 Golang 中的 %!(EXTRA int=3) 错误?

cassandra - 这个主键如何获取组中的所有用户?

cassandra - order by 子句在 Cassandra 查询中不起作用

c - C程序控制台输入的奇怪现象

windows - 如何使用 FFmpeg 和 GeForce 硬件将 4K MKV 电影解码和编码为 1080p

c++ - 匿名管道

Python 脚本不能在 Ubuntu 上运行

c - 戈朗 : How to correctly parse UTF-8 string from C