wiki:waue/2011/1207

Version 3 (modified by waue, 13 years ago) (diff)

--

cassandra + thrift + python
cassandra 0.8.1 + thrift 0.6.1 + python 2.6

Download Thrift and Cassandra

  • 下載 cassandra-0.8.1 於 /opt/cassandra-0.8.1
  • thrift-0.6.1 於 /opt/cassandra-0.8.1/thrift-0.6.1

cassandra 是 java 因此只需要驅動即可,但thrift 是中介平台,因此需要make install 來加載到各語言的函式庫

之後在 cassandra 的資料夾下執行 gen-語言 則會產生該語言的驅動檔,透過驅動檔使用

install thrift

cd /opt/cassandra-0.8.1/thrift-0.6.1
./configure
make
make install

注意 /usr/lib/python2.6/site-packages/thrift/ 內有資料才是 thrift python 安裝完成

sudo cp -rf /usr/lib/python2.6/site-packages/thrift /usr/local/lib/python2.6/dist-packages/

注意!由於 python 的 sys.path 僅引用到 /usr/local/lib/python2.6/dist-packages/ 及 /usr/lib/python2.6/dist-packages,因此若不做上面這行指令則會報 "No module named thrift.transport" 的錯誤

generate gen-py

cd /opt/cassandra-0.8.1/interface
thrift -gen py cassandra.thrift
cd gen-py/cassandra 

use

./Cassandra-remote -h cass-1:9160 insert Keyspace1 eevans "ColumnPath('Standard1', column='fruit')" apple 1 ConsistencyLevel.QUORUM