Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Syntax highlighting for the README
Browse files Browse the repository at this point in the history
  • Loading branch information
thobbs committed Aug 2, 2011
1 parent fdf8b9e commit 32e9686
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions README.mkd
Expand Up @@ -58,53 +58,60 @@ Basic Usage


To get a connection pool, pass a Keyspace and an optional list of servers: To get a connection pool, pass a Keyspace and an optional list of servers:


>>> import pycassa ~~~~~~ {python}
>>> pool = pycassa.ConnectionPool('Keyspace1') # Defaults to connecting to the server at 'localhost:9160' >>> import pycassa
>>> pool = pycassa.ConnectionPool('Keyspace1', server_list=['192.168.2.10']) >>> pool = pycassa.ConnectionPool('Keyspace1') # Defaults to connecting to the server at 'localhost:9160'
>>> pool = pycassa.ConnectionPool('Keyspace1', server_list=['192.168.2.10'])
~~~~~~


To use the standard interface, create a ColumnFamily instance. To use the standard interface, create a ColumnFamily instance.


>>> pool = pycassa.ConnectionPool('Keyspace1') ~~~~~~ {python}
>>> cf = pycassa.ColumnFamily(pool, 'Standard1') >>> pool = pycassa.ConnectionPool('Keyspace1')
>>> cf.insert('foo', {'column1': 'val1'}) >>> cf = pycassa.ColumnFamily(pool, 'Standard1')
1261349837816957 >>> cf.insert('foo', {'column1': 'val1'})
>>> cf.get('foo') >>> cf.get('foo')
{'column1': 'val1'} {'column1': 'val1'}
~~~~~~


insert() also acts to update values: insert() also acts to update values:


>>> cf.insert('foo', {'column1': 'val2'}) ~~~~~~ {python}
1261349910511572 >>> cf.insert('foo', {'column1': 'val2'})
>>> cf.get('foo') >>> cf.get('foo')
{'column1': 'val2'} {'column1': 'val2'}
~~~~~~


You may insert multiple columns at once: You may insert multiple columns at once:


>>> cf.insert('bar', {'column1': 'val3', 'column2': 'val4'}) ~~~~~~ {python}
1261350013606860 >>> cf.insert('bar', {'column1': 'val3', 'column2': 'val4'})
>>> cf.multiget(['foo', 'bar']) >>> cf.multiget(['foo', 'bar'])
{'foo': {'column1': 'val2'}, 'bar': {'column1': 'val3', 'column2': 'val4'}} {'foo': {'column1': 'val2'}, 'bar': {'column1': 'val3', 'column2': 'val4'}}
>>> cf.get_count('bar') >>> cf.get_count('bar')
2 2
~~~~~~


get_range() returns an iterable. Call it with list() to convert it to a list. get_range() returns an iterable. Call it with list() to convert it to a list.


>>> list(cf.get_range()) ~~~~~~ {python}
[('bar', {'column1': 'val3', 'column2': 'val4'}), ('foo', {'column1': 'val2'})] >>> list(cf.get_range())
>>> list(cf.get_range(row_count=1)) [('bar', {'column1': 'val3', 'column2': 'val4'}), ('foo', {'column1': 'val2'})]
[('bar', {'column1': 'val3', 'column2': 'val4'})] >>> list(cf.get_range(row_count=1))
[('bar', {'column1': 'val3', 'column2': 'val4'})]
~~~~~~


You can remove entire keys or just a certain column. You can remove entire keys or just a certain column.


>>> cf.remove('bar', columns=['column1']) ~~~~~~ {python}
1261350220106863 >>> cf.remove('bar', columns=['column1'])
>>> cf.get('bar') >>> cf.get('bar')
{'column2': 'val4'} {'column2': 'val4'}
>>> cf.remove('bar') >>> cf.remove('bar')
1261350226926859 >>> cf.get('bar')
>>> cf.get('bar') Traceback (most recent call last):
Traceback (most recent call last): ...
... cassandra.ttypes.NotFoundException: NotFoundException()
cassandra.ttypes.NotFoundException: NotFoundException() ~~~~~~


See the [tutorial](http://pycassa.github.com/pycassa/tutorial.html#connecting-to-cassandra) for more details. See the [tutorial](http://pycassa.github.com/pycassa/tutorial.html#connecting-to-cassandra) for more details.

0 comments on commit 32e9686

Please sign in to comment.