官术网_书友最值得收藏!

How to configure keyspaces

In the previous chapter, we learned a little bit about keyspaces. A keyspace is essentially a namespace for various tables in a cluster. It is somewhat analogous to a database in the relational world. All data will reside within some keyspace. The main function of declaring keyspaces over declaring tables directly is not to serve as a mapping layer, but to control the replication of closely related tables.

Let's create the keyspace for our MyStatus application by executing the following command in CQL shell:

    
CREATE KEYSPACE "my_status"
WITH REPLICATION = {
'class': 'SimpleStrategy', 'replication_factor': 1
};

When creating a keyspace, you have to specify certain configuration parameters such as the replication strategy and the replication factor. The replication strategy tells the Cassandra cluster how to distribute various copies of the same data across the different data centers and racks of cluster. The replication factor specifies how many copies of each record to store. There is another configuration parameter called durable writes, which we will learn about later.

For now, we will use SimpleStrategy and a replication factor of 1 since we have a single node cluster running. This keyspace will serve as the namespace for all the tables we create in the rest of the book.

In CQL, you select the keyspace to use via the USE command. To ensure all the future tables reside within the my_status keyspace, we enter the following statement:

    USE "my_status";

Another way to select a keyspace is to prefix a table name with the keyspace name wherever we use it, such as <keyspace_name> and <table_name>.

主站蜘蛛池模板: 汾阳市| 荔浦县| 庆云县| 桐梓县| 曲阜市| 嘉禾县| 宁安市| 台江县| 海城市| 绥德县| 焉耆| 浪卡子县| 上栗县| 天门市| 阿拉尔市| 西乡县| 苏尼特左旗| 通许县| 银川市| 资中县| 临夏县| 大石桥市| 黄浦区| 合山市| 孟津县| 莱州市| 沙坪坝区| 汽车| 穆棱市| 邵武市| 虞城县| 利川市| 永城市| 连云港市| 昂仁县| 眉山市| 彩票| 石泉县| 修水县| 南投县| 宜良县|