Created
March 15, 2011 06:29
-
-
Save mix3/870395 to your computer and use it in GitHub Desktop.
Accessing Cassandra 0.7.0 from Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use lib $ENV{'CASSANDRA_HOME'}.'/interface/gen-perl/'; | |
use Cassandra::Cassandra; | |
use Cassandra::Constants; | |
use Cassandra::Types; | |
use Thrift; | |
use Thrift::BinaryProtocol; | |
use Thrift::Socket; | |
use Thrift::FramedTransport; | |
use Data::Dumper; | |
# settings | |
my $socket = new Thrift::Socket('localhost', 9160); | |
my $transport = new Thrift::FramedTransport($socket,1024,1024); | |
my $protocol = new Thrift::BinaryProtocol($transport); | |
my $client = new Cassandra::CassandraClient($protocol); | |
eval { | |
# open | |
$transport->open(); | |
# set keyspace | |
my $keyspace = 'Keyspace1'; | |
$client->set_keyspace($keyspace); | |
my $column_parent = new Cassandra::ColumnParent( { column_family => 'Standard2' } ); | |
my $consistency_level = Cassandra::ConsistencyLevel::ONE; | |
my $auth_request = new Cassandra::AuthenticationRequest(); | |
# get_slice, unset range | |
my $slice_range = new Cassandra::SliceRange( { start => '', finish => '' } ); | |
my $predicate = new Cassandra::SlicePredicate( { slice_range => $slice_range } ); | |
print Dumper $client->get_slice('jsmith', $column_parent, $predicate, $consistency_level); | |
# get_slice, set range | |
my $slice_range = new Cassandra::SliceRange( { start => 'age', finish => 'first' } ); | |
my $predicate = new Cassandra::SlicePredicate( { slice_range => $slice_range } ); | |
print Dumper $client->get_slice('jsmith', $column_parent, $predicate, $consistency_level); | |
# get, column: first | |
my $column_path = new Cassandra::ColumnPath( { column_family => 'Standard2', column => 'first' } ); | |
print Dumper $client->get('jsmith', $column_path, $consistency_level); | |
# get, column: last | |
my $column_path = new Cassandra::ColumnPath( { column_family => 'Standard2', column => 'last' } ); | |
print Dumper $client->get('jsmith', $column_path, $consistency_level); | |
# get, column: age | |
my $column_path = new Cassandra::ColumnPath( { column_family => 'Standard2', column => 'age' } ); | |
print Dumper $client->get('jsmith', $column_path, $consistency_level); | |
# cassandra command | |
#print Dumper($client->describe_keyspaces); | |
#print Dumper($client->describe_keyspace($keyspace)); | |
#print Dumper($client->describe_cluster_name); | |
#print Dumper($client->describe_version); | |
# close | |
$transport->close(); | |
}; | |
die Dumper($@) if $@; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment