kan*_*rbk 2 go cassandra datastax gocql
我们正在使用gocql
(https://github.com/gocql/gocql)驱动程序从我们的golang服务器连接到Cassandra。对于每个http请求,我们将创建一个新会话并将行插入cassandra中。我们认为为每个请求创建会话都非常耗费资源。
典型代码
func NewSession() (*gocql.Session, error) {
config := NewClusterConfig()
if config == nil {
return nil, &CassandraError{"Oops! Cluster initialization failed."}
}
return config.CreateSession()
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在gocql
golang或任何其他cassandra驱动程序中合并连接?
您不需要游泳池。创建一个全球性的Session
。从https://godoc.org/github.com/gocql/gocql#Session:
对于多个goroutine并发使用是安全的,典型的使用场景是让一个全局会话对象与整个Cassandra集群进行交互。
归档时间: |
|
查看次数: |
1732 次 |
最近记录: |