53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
1 |
#! /usr/bin/perl -l
|
2 |
||
22
by Filipe Gonçalves
Added Counters support |
3 |
use strict; |
4 |
use warnings; |
|
5 |
||
6 |
use Data::Dumper; |
|
7 |
||
8 |
use Cassandra::Simple; |
|
9 |
use Cassandra::Composite qw/composite composite_to_array/; |
|
10 |
||
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
11 |
my ( $keyspace, $column_family) = qw/simple countersimple/; |
22
by Filipe Gonçalves
Added Counters support |
12 |
|
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
13 |
my $sys_conn = Cassandra::Simple->new(); |
14 |
unless ( grep { $_ eq $keyspace } @{ $sys_conn->list_keyspaces() } ) { |
|
15 |
print "Creating keyspace $keyspace"; |
|
65
by Filipe Gonçalves
* Proper error handling. |
16 |
$sys_conn->create_keyspace(keyspace => $keyspace); |
22
by Filipe Gonçalves
Added Counters support |
17 |
}
|
18 |
||
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
19 |
my $conn = Cassandra::Simple->new( keyspace => $keyspace, ); |
22
by Filipe Gonçalves
Added Counters support |
20 |
|
21 |
my $present = |
|
65
by Filipe Gonçalves
* Proper error handling. |
22 |
grep { $_ eq $column_family } @{ $conn->list_keyspace_cfs() }; |
22
by Filipe Gonçalves
Added Counters support |
23 |
|
24 |
unless ($present) { |
|
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
25 |
print "Creating $column_family in $keyspace"; |
65
by Filipe Gonçalves
* Proper error handling. |
26 |
$conn->create_column_family( column_family => $column_family, |
27 |
comparator_type => 'UTF8Type', |
|
28 |
key_validation_class => 'UTF8Type', |
|
29 |
default_validation_class => 'CounterColumnType', |
|
30 |
);
|
|
22
by Filipe Gonçalves
Added Counters support |
31 |
}
|
32 |
||
33 |
||
34 |
#Method to test code here success
|
|
35 |
#add 100% 100%
|
|
36 |
#remove_counter 100% 100%
|
|
37 |
#get 100% 100%
|
|
38 |
||
39 |
||
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
40 |
print "\$conn->add($column_family, 'ChaveA', 'ColunaA')"; |
65
by Filipe Gonçalves
* Proper error handling. |
41 |
print Dumper $conn->add(column_family => $column_family, key => 'ChaveA', column => 'ColunaA'); |
22
by Filipe Gonçalves
Added Counters support |
42 |
|
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
43 |
print "\$conn->get($column_family, 'ChaveA', {columns => ['ColunaA']})"; |
65
by Filipe Gonçalves
* Proper error handling. |
44 |
print Dumper $conn->get(column_family => $column_family, key => 'ChaveA', columns => ['ColunaA']); |
22
by Filipe Gonçalves
Added Counters support |
45 |
#Expected result: ColunaA -> 1
|
46 |
||
54
by Filipe Gonçalves
fixes #9 - adding 0 to counter column increases value by 1 |
47 |
print "\$conn->add($column_family, 'ChaveA', 'ColunaA', 0)"; |
65
by Filipe Gonçalves
* Proper error handling. |
48 |
print Dumper $conn->add(column_family => $column_family, key => 'ChaveA', column => 'ColunaA', value => 0); |
54
by Filipe Gonçalves
fixes #9 - adding 0 to counter column increases value by 1 |
49 |
|
50 |
print "\$conn->get($column_family, 'ChaveA', {columns => ['ColunaA']})"; |
|
65
by Filipe Gonçalves
* Proper error handling. |
51 |
print Dumper $conn->get(column_family => $column_family, key => 'ChaveA', columns => ['ColunaA']); |
54
by Filipe Gonçalves
fixes #9 - adding 0 to counter column increases value by 1 |
52 |
#Expected result: ColunaA -> 1
|
53 |
||
55
by Filipe Gonçalves
Added batch_add call to allow bulk update counters. fixes #8 |
54 |
print "\$conn->batch_add($column_family, {'ChaveA'=> {'ColunaA'=> 10}})"; |
65
by Filipe Gonçalves
* Proper error handling. |
55 |
print Dumper $conn->batch_add(column_family => $column_family, rows => {'ChaveA'=> {'ColunaA'=> 10}}); |
22
by Filipe Gonçalves
Added Counters support |
56 |
|
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
57 |
print "\$conn->get($column_family, 'ChaveA', {columns => ['ColunaA']})"; |
65
by Filipe Gonçalves
* Proper error handling. |
58 |
print Dumper $conn->get(column_family => $column_family, key => 'ChaveA', columns => ['ColunaA']); |
22
by Filipe Gonçalves
Added Counters support |
59 |
#Expected result: ColunaA -> 11
|
60 |
||
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
61 |
print "\$conn->remove_counter($column_family, 'ChaveA', 'ColunaA')"; |
65
by Filipe Gonçalves
* Proper error handling. |
62 |
print Dumper $conn->remove_counter(column_family => $column_family, key => 'ChaveA', column => 'ColunaA'); |
22
by Filipe Gonçalves
Added Counters support |
63 |
|
53
by Filipe Gonçalves
Added weights to servers in pool. Modified examples for clarity. |
64 |
print Dumper "\$conn->drop_keyspace($keyspace)"; |
65
by Filipe Gonçalves
* Proper error handling. |
65 |
print Dumper $sys_conn->drop_keyspace(keyspace => $keyspace); |