Last active
December 14, 2018 20:20
-
-
Save jwkidd3/21aaa2b7c8b496b16105ef6c2ba8dad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Docker | |
docker ps | |
docker images | |
docker ps -a | |
docker rm -f <name> | |
docker run --name cass_one -d -v /home/ops:/data -p 9042:9042 cassandra | |
docker run --name cass_two -e CASSANDRA_SEEDS=<ip of other node> -d cassandra | |
Nodetool | |
nodetool ring | |
nodetool status | |
nodetool info | |
nodetool describering killrvideo | |
nodetool removenode <node name> | |
nodetool getendpoints killrvideo videos_by_tag 'cassandra' | |
General DDL/DML | |
CREATE KEYSPACE killrvideo | |
WITH replication = {'class': 'SimpleStrategy', | |
'replication_factor': 1 }; | |
USE killrvideo; | |
CREATE TABLE videos ( | |
id uuid, | |
added_date timestamp, | |
title text, | |
PRIMARY KEY ((id)) | |
); | |
COPY videos(id, added_date, title) | |
FROM '/data/videos.csv' | |
WITH HEADER=TRUE; | |
CREATE TABLE videos_by_tag ( | |
tag text, | |
video_id uuid, | |
added_date timestamp, | |
title text, | |
PRIMARY KEY ((tag), added_date, video_id)); | |
COPY videos_by_tag(tag, video_id, added_date, title) | |
FROM '/data/videos-by-tag.csv' | |
WITH HEADER=TRUE; | |
Python Script | |
from cassandra.cluster import Cluster | |
cluster = Cluster(protocol_version = 3) | |
session = cluster.connect('killrvideo') | |
for val in session.execute("SELECT * FROM videos_by_tag"): | |
print(val[0]) | |
print('{0:12} {1:40} {2:5}'.format('Tag', 'ID', 'Title')) | |
for val in session.execute("select * from videos_by_tag"): | |
print('{0:12} {1:40} {2:5}'.format(val[0], val[2], val[3])) | |
session.execute( | |
"INSERT INTO videos_by_tag (tag, added_date, video_id, title)" + "VALUES ('cassandra', '2013-01-10', uuid(), 'Cassandra Is My Friend')") | |
print('{0:12} {1:40} {2:5}'.format('Tag', 'ID', 'Title')) | |
for val in session.execute("select * from videos_by_tag"): | |
print('{0:12} {1:40} {2:5}'.format(val[0], val[2], val[3])) | |
session.execute("DELETE FROM videos_by_tag " + | |
"WHERE tag = 'cassandra' AND added_date = '2013-01-10' AND " + | |
"video_id = INSERT_YOUR_UUID_HERE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment