Quantcast
Channel: Concourse Guide » jnelson
Viewing all articles
Browse latest Browse all 10

Tutorial

$
0
0

Now that you’ve installed Concourse and learned how to use CaSH, its time to explore some of Concourse’s unique features.

The Basics

Concourse makes it very easy to do basic read/write operations. Since Concourse is schemaless, you don’t have to create any structure (i.e. tables, indexes, etc) upfront. Everything is created for you dynamically.

Add

The add operation appends a value to a key in a record. A key in record may contain multiple values and those values may have different types.

Add name as John Doe to record 1

cash$ add "name", "John Doe", 1
Returned 'true' in 92 ms

Notice that I didn’t explicitly create Record 1. Non-existing records are created dynamically when you write data. Otherwise, new data is appended to the existing record.
Also add name as Johnny Doe, Jonathan Doe and J. Doe to record 1

cash$ add "name", "Johnny Doe", 1
Returned 'true' in 28 ms

cash$ add "name", "Jonathan Doe", 1
Returned 'true' in 24 ms

cash$ add "name", "J. Doe", 1
Returned 'true' in 24 ms

A key in a record cannot contain duplicate data, so Concourse prevents you from adding a value that already exists.

cash$ add "name", "John Doe", 1
Returned 'false' in 92 ms

Add age as 30, 30.5, '30' and true to record 1.

cash$ add "age", 30, 1
Returned 'true' in 28 ms

cash$ add "age", 30.5F, 1
Returned 'true' in 26 ms

cash$ add "age", "30", 1
Returned 'true' in 28 ms

cash$ add "age", true, 1
Returned 'true' in 25 ms

Remove

The remove operation deletes a previously added value from a key in a record.

Remove age as true from record 1.

cash$ remove "age", true, 1
Returned 'true' in 28 ms

Fetch

The fetch operation retrieves all the values for a key in a record.

Fetch name from record 1.

cash$ fetch "name", 1
Returned '[John Doe, Johnny Doe, Jonathan Doe, J. Doe]' in 23 ms

Get

The get operation retrieves the oldest value that exists for a key in a record.

Get name from record 1

cash$ get "name", 1
Returned 'John Doe' in 27 ms

Set

The set operation atomically removes all the values for a key in a record before adding a new value.

Use a for-loop to add multiple values to baz in record 1 and then set baz as 6 in record 1.

cash$ for(int i = 0; i < 5; i++){add("baz", i, 1)}
Completed in 43 ms

cash$ fetch "baz", 1
Returned '[0, 1, 2, 3, 4]' in 50 ms

cash$ set "baz", 6, 1
Completed in 54 ms

cash$ fetch "baz", 1
Returned '[6]' in 21 ms

Describe

The describe operation lists all the keys in a record.

Describe record 1.

cash$ describe 1
Returned '[name, age, baz]' in 23 ms

Verify

The verify operation returns true if the specified value exists for the key in the record.

Verify age as 30 in record 1.

cash$ verify "age", 30, 1
Returned 'true' in 28 ms

Find

The find operation queries the database for records that match a criteria. Concourse automatically indexes data on the fly, so you can use this operation on any key without explicitly creating a secondary index.

The find() operation is similar to the SELECT statement in SQL.

Create a for loop from 1 to 1000 and add count as <codei in record i and then find all the records with a value for count between 100 and300.

cash$ for(int i = 1; i <= 1000; i++){ add("count", i, i)}
Completed in 866 ms

cash$ find "count", bw, 100, 300
Returned '[100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299]' in 199 ms

The BETWEEN operator is inclusive of the smaller value and exclusive of the larger one.


Viewing all articles
Browse latest Browse all 10

Trending Articles