insert the record in to Cassandra using by Pycassa

by mariganesh 2013-01-10 12:20:37

Insert the record in to Cassandra using by Pycassa

step1:First create the keyspace in cassandra

step2:use this keyspace create the colum family

step3:Connect the cassandra and python using pycassa

Here
Keyspace : test

Columfamily: record



import pycassa
from pycassa.index import *
def connect():
"""Connect to a test database"""
connection = pycassa.connect('test', ['localhost:9160'])
db = pycassa.ColumnFamily(connection,'record')
return db

def random_insert(db):
"""Insert a record into the database. The record has the following format
ID timestamp
4 random strings
3 random integers"""
record = {}
record['name'] = 'hiox'
db.insert(str(time.time()), record)



939
like
0
dislike
0
mail
flag

You must LOGIN to add comments