NAME
Cassandra::Lite - Simple way to access Cassandra 0.7/0.8
VERSION
version 0.4.0
DESCRIPTION
This module will offer you a simple way to access Cassandra 0.7/0.8 (maybe later version). Some parts are not same as standard API document (especially arguments order), it's because I want to keep this module easy to use.
Before using this module, you need to know about the basic model of Cassandra. http://wiki.apache.org/cassandra/DataModel is a good start.
You'll need to install Thrift perl modules first to use Cassandra::Lite.
WARNING: All API might be changed during development version.
SYNOPSIS
First to initialize:
use Cassandra::Lite;
# Create with default options (C<keyspace> is a mantorary option):
my $c = Cassandra::Lite->new(keyspace => 'Keyspace1');
# Now just define $columnFamily and $key
my $columnFamily = 'BlogArticle';
my $key = 'key12345';
Then you can insert data:
# Insert it.
$c->put($columnFamily, $key, {title => 'testing title', body => '...'});
And get data:
# Get a column
my $scalarValue = $c->get($columnFamily, $key, 'title');
# Get all columns
my $hashRef = $c->get($columnFamily, $key);
More, to delete data:
# Remove it
$c->delete($columnFamily, $key);
Others:
# Change keyspace
$c->keyspace('BlogArticleComment');
# Get count
my $num2 = $c->get_count('Foo', 'key1');
# Truncate column family
$c->truncate('Foo');
FUNCTION
new(...)
-
All supported options:
my $c = Cassandra::Lite->new( server_name => 'server1', # optional, default to '127.0.0.1' server_port => 9160, # optional, default to 9160 username => 'username', # optional, default to empty string '' password => 'xxx', # optional, default to empty string '' consistency_level_read => 'ONE' # optional, default to 'ONE' consistency_level_write => 'ONE' # optional, default to 'ONE' transport_read => 1024, # optional, default to 1024 transport_write => 1024, # optional, default to 1024 keyspace => 'Keyspace1', );
So, usually we can use this in dev environment:
my $c = Cassandra::Lite->new(keyspace => 'Keyspace1');
cql($query)
delete($columnFamily, $key, $options)
-
Delete entire row.
get($columnFamily, $key, $column, $options)
-
The simplest syntax is to get all columns:
my $cf = 'BlogArticle'; my $key1 = 'key12345'; my $allColumns = $c->get($cf, $key1);
You can get a single column:
my $title = $c->get($cf, $key1, 'title');
Also, you can get range column (this example will query from 'Column001' to 'Column999'):
my $columns = $c->get($cf, $key1, {start => 'Column001', finish => 'Column999'});
With multiple keys:
my $key2 = 'key56789'; my $datas1 = $c->get($cf, [$key1, $key2]); my $datas2 = $c->get($cf, [$key1, $key2], {start => 'Column001', finish => 'Column999'});
With key range:
my $datas3 = $c->get($cf, {start_key => 'a', end_key => 'b'}); my $datas4 = $c->get($cf, {start_key => 'a', end_key => 'b'}, 'column'); my $datas5 = $c->get($cf, {start_key => 'a', end_key => 'b'}, {start => 'Column001', finish => 'Column999'});
In order words,
$key
can be scalar string (single key) or array reference (multiple keys). And$column
can be undef (to get all columns), scalar string (to get one column), or hash reference (to get columns by range). get_count($columnFamily, $key, $column, $options)
put($columnFamily, $key, $columns, $options)
truncate($columnFamily)
-
Truncate entire column family.
SEE ALSO
Cassandra API
Cassandra Thrift Interface
AUTHOR
Gea-Suan Lin, <gslin at gslin.org>
LICENSE AND COPYRIGHT
Copyright 2011 Gea-Suan Lin.
This software is released under 3-clause BSD license. See http://www.opensource.org/licenses/bsd-license.php for more information.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 162:
'=item' outside of any '=over'
- Around line 392:
You forgot a '=back' before '=head1'