1、Cassandra支持宽列数据,mysql的话就需要分表了;
2、Cassandra支持命令行查看集群状态,直接输入cqlsh即可,然后可以select,可以create,可以alter;
3、Cassandra有个key space的概念,类似mysql的db的;
4、Cassandra有个副本因子的概念,用于高活;
5、Cassandra的数据同步跟mysql和redis的刷盘类似,有wal机制;
6、Cassandra支持类似mysql explain的能力,不过需要显示的开启。通过cqlsh,执行:
7、Cassandra想支持范围查询需要在sql里显示表明,allow filtering:
8、用golang来读取Cassandra:
前置条件,先创建表:
package mainimport ("fmt""time""github.com/gocql/gocql""github.com/google/uuid"
)func main() {cluster := gocql.NewCluster("127.0.0.1") // 替换为您的Cassandra节点IP地址cluster.Keyspace = "tanxiaolong_test" // 替换为您的Cassandra keyspace名称session, err := cluster.CreateSession()if err != nil {fmt.Println("create cas session err: ", err)return}defer session.Close()// 执行查询var result stringvar id string = "c5675fa6-c7bd-4ef9-89a1-0aede1872424"start := time.Now()if err := session.Query("SELECT name FROM users WHERE id = ?", id).Scan(&result); err != nil {// 处理查询错误fmt.Println("query cas err: ", err)return}fmt.Println(result, "time cost: ", time.Since(start))// 执行插入id = uuid.New().String()fmt.Println("new id: ", id)start = time.Now()if err := session.Query("INSERT INTO users (id, name, age) VALUES (?,?, ?)", id, "tanxiaolong", 35).Exec(); err != nil {// 处理插入错fmt.Println("insert cas err: ", err)}fmt.Println("insert time cost: ", time.Since(start))
}