cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Cassandra Wiki] Update of "CassandraCli" by jeremyhanna
Date Mon, 21 Feb 2011 16:55:45 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The "CassandraCli" page has been changed by jeremyhanna.
The comment on this change is: Starting to cleaning up this page post 0.7.x. More work to
do..
http://wiki.apache.org/cassandra/CassandraCli?action=diff&rev1=22&rev2=23

--------------------------------------------------

- Cassandra ships with a very basic interactive command line interface, or shell. Using the
CLI you can connect to remote nodes in the cluster, set and retrieve records and columns,
or query node and cluster meta-data (i.e. cluster name, keyspace listings and disposition,
etc). The CLI is handy for quick tests or for familiarizing yourself with the data-model.
+ Cassandra ships with a very basic interactive command line interface, or shell. Using the
CLI you can connect to remote nodes in the cluster, create or update your schema, set and
retrieve records and columns, or query node and cluster meta-data (i.e. cluster name, keyspace
listings and disposition, etc).
  
  You can start the CLI using the `bin/cassandra-cli` startup script.
  
  {{{
- evans@achilles:~/cassandra$ bin/cassandra-cli -host localhost -port 9160
+ evans@achilles:~/cassandra$ bin/cassandra-cli
+ Welcome to cassandra CLI.
+ 
+ Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit.
+ [default@unknown] connect localhost/9160;
+ Connected to: "Test Cluster" on localhost/9160
+ [default@unknown] create keyspace Keyspace1;
+ d105c4f1-3c93-11e0-9fb5-e700f669bcfc
+ [default@unknown] use Keyspace1;
+ Authenticated to keyspace: Keyspace1
+ [default@Keyspace1] create column family Standard2;
+ 00389812-3c94-11e0-9fb5-e700f669bcfc
+ [default@Keyspace1] quit;
+ evans@achilles:~/cassandra$
+ }}}
+ In the above example we started the cli with no options. You can can also specify things
like `-keyspace`, `-username`, `-password`, etc. Use `bin/cassandra-cli -?` for a full set
of options.  We went on to connect to our local Cassandra node. We created keyspace `Keyspace1`
and column family `Standard2` with the default options. Then we exited from our cli shell.
+ 
+ Let's get back into the shell with some options specified and create some data.
+ 
+ {{{
+ tblose@quasar:~/dev/workspaces/cassandra$ bin/cassandra-cli -host localhost -port 9160 -keyspace
Keyspace1
  Connected to localhost/9160
  Welcome to cassandra CLI.
  
- Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
+ Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit.
- cassandra>
+ [default@Keyspace1] set Standard2['jsmith']['first'] = 'John';
+ Value inserted.
+ [default@Keyspace1] set Standard2['jsmith']['last'] = 'Smith';
+ Value inserted.
+ [default@Keyspace1] set Standard2['jsmith']['age'] = '42';
+ Value inserted.
  }}}
+ In the example above, we created a record in the `Standard2` column family using the key
`jsmith`. This record has three columns, `first`, `last`, and `age`. Each of these commands
is the equivalent to an `insert()` using the [[API|Thrift API]].
- 
- If you are using SimpleAuthenticator (instead of !AllowAllAuthenticator) you can specify
the username, password and keyspace by adding the following options to cassandra-cli: -username
username -password password -keyspace keyspace):
  
  {{{
+ [default@unknown] use Keyspace1;
+ cassandra> set Standard2['jsmith']['first'] = 'John';
- tblose@quasar:~/dev/workspaces/cassandra$ bin/cassandra-cli -host localhost -port 9160 -username
todd -keyspace Keyspace1 -password blah
- Connected to: "Test Cluster" on localhost/9160
- Welcome to cassandra CLI.
- 
- Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
- [todd@Keyspace1] 
- }}}
- 
- 
- As the banner says, you can use 'help' or '?' to see what the CLI has to offer, and 'quit'
or 'exit' when you've had enough fun. But lets try something slightly more interesting...
- 
- {{{
- [todd@Keyspace1] set Keyspace1.Standard2['jsmith']['first'] = 'John'
  Value inserted.
- [todd@Keyspace1] set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
+ cassandra> set Standard2['jsmith']['last'] = 'Smith';
  Value inserted.
- [todd@Keyspace1] set Keyspace1.Standard2['jsmith']['age'] = '42'
+ cassandra> set Standard2['jsmith']['age'] = '42';
  Value inserted.
  }}}
+ Note that before we can start adding data, we have to `use Keyspace1` to set our current
keyspace.
- 
- Cassandra 0.7 introduces the `use` command to reduce keystrokes. The above example can be
reduced to...
- 
- {{{
- [default@unknown] use Keyspace1 todd 'blah$'
- Authenticated to keyspace: Keyspace1
- [todd@Keyspace1] set Standard2['jsmith']['first'] = 'John'
- Value inserted.
- [todd@Keyspace1] set Standard2['jsmith']['last'] = 'Smith'
- Value inserted.
- [todd@Keyspace1] set Standard2['jsmith']['age'] = '42'
- Value inserted.
- }}}
- 
- In the example above we authenticated to 'Keyspace1' and created a record in the `Standard2`
column family using the key `jsmith`. This record has three columns, `first`, `last`, and
`age`. Each of these commands is the equivalent to an `insert()` using the [[API|Thrift API]].
- 
- In API version 2.1.0 the example would go like the following due to changes in the API.
- 
- {{{
- cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John' 
- Value inserted.
- cassandra> set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
- Value inserted.
- cassandra> set Keyspace1.Standard2['jsmith']['age'] = '42'
- Value inserted.
- }}}
  
  Now let's read back the `jsmith` row to see what it contains:
  
  {{{
+ [default@Keyspace1] get Standard2['jsmith'];
- [todd@Keyspace1] get Standard2['jsmith']                  
- => (column=last, value=Smith, timestamp=1271921526614000)
- => (column=first, value=John, timestamp=1271921521923000)
- => (column=age, value=42, timestamp=1271921532713000)
+ => (column=616765, value=3432, timestamp=1298168118014000)
+ => (column=6669727374, value=4a6f686e, timestamp=1298166059047000)
+ => (column=6c617374, value=536d697468, timestamp=1298168112533000)
  Returned 3 results.
  }}}
  Note: Using the `get` command in this form is the equivalent to a `get_slice()` using the
[[API|Thrift API]].
  
- 
- Once again, with the API being different, you need to specify the Keyspace
- 
- {{{
- cassandra> get Keyspace1.Standard2['jsmith']
- => (column=last, value=Smith, timestamp=1278953905903000)
- => (column=first, value=John, timestamp=1278953848952000)
- => (column=age, value=42, timestamp=1278953919182000)
- Returned 3 results.
- }}}
- 

Mime
View raw message