1: <?php
2: namespace phpcassa;
3:
4: use cassandra\ConsistencyLevel;
5: use cassandra\CounterColumn;
6:
7: /**
8: * Representation of a column family in Cassandra.
9: *
10: * All data insertions, deletions, or retrievals will go through a ColumnFamily.
11: * This may only be used for standard column families; you must use
12: * \phpcassa\SuperColumnFamily for super column families.
13: *
14: * @package phpcassa
15: */
16: class ColumnFamily extends AbstractColumnFamily {
17:
18: /**
19: * Increment or decrement a counter.
20: *
21: * `value` should be an integer, either positive or negative, to be added
22: * to a counter column. By default, `value` is 1.
23: *
24: * This method is not idempotent. Retrying a failed add may result
25: * in a double count. You should consider using a separate
26: * ConnectionPool with retries disabled for column families
27: * with counters.
28: *
29: * Only available in Cassandra 0.8.0 and later.
30: *
31: * @param string $key the row to insert or update the columns in
32: * @param mixed $column the column name of the counter
33: * @param int $value the amount to adjust the counter by
34: * @param ConsistencyLevel $consistency_level affects the guaranteed
35: * number of nodes that must respond before the operation returns
36: */
37: public function add($key, $column, $value=1, $consistency_level=null) {
38: $packed_key = $this->pack_key($key);
39: $cp = $this->create_column_parent();
40: $counter = new CounterColumn();
41: $counter->name = $this->pack_name($column);
42: $counter->value = $value;
43: return $this->pool->call("add", $packed_key, $cp, $counter,
44: $this->wcl($consistency_level));
45: }
46: }
47: