├── Chapter01 └── README.txt ├── Chapter02 ├── crud-op.txt └── query.txt ├── Chapter03 ├── 6996_03_06_01.txt ├── 6996_03_06_02.txt ├── 6996_03_06_03.txt ├── 6996_03_06_04.txt ├── 6996_03_06_05.txt ├── 6996_03_06_06.txt ├── 6996_03_06_07.txt ├── 6996_03_06_08.txt ├── 6996_03_06_09.txt ├── 6996_03_06_10.txt ├── 6996_03_06_11.txt ├── 6996_03_06_12.txt ├── 6996_03_06_13.txt ├── 6996_03_06_14.txt ├── 6996_03_06_15.txt ├── 6996_03_06_16.txt ├── 6996_03_07_01.txt ├── 6996_03_07_02.txt ├── 6996_03_07_03.txt ├── 6996_03_07_04.txt ├── 6996_03_07_05.txt ├── 6996_03_07_06.txt ├── 6996_03_07_07.txt ├── 6996_03_07_08.txt ├── 6996_03_07_09.txt ├── 6996_03_07_10.txt ├── 6996_03_07_11.txt ├── 6996_03_07_12.txt ├── 6996_03_07_13.txt ├── 6996_03_07_14.txt ├── 6996_03_07_15.txt ├── 6996_03_07_16.txt ├── 6996_03_07_17.txt ├── 6996_03_07_18.txt ├── 6996_03_07_19.txt ├── 6996_03_07_20.txt ├── 6996_03_07_21.txt ├── 6996_03_07_22.txt ├── 6996_03_07_23.txt ├── 6996_03_07_24.txt ├── 6996_03_07_25.txt ├── 6996_03_07_26.txt ├── 6996_03_07_27.txt ├── 6996_03_07_28.txt ├── 6996_03_07_29.txt ├── 6996_03_07_30.txt ├── 6996_03_07_31.txt ├── 6996_03_07_32.txt ├── 6996_03_07_33.txt ├── 6996_03_07_34.txt ├── 6996_03_07_35.txt ├── 6996_03_07_36.txt ├── 6996_03_07_37.txt ├── 6996_03_07_38.txt ├── 6996_03_07_39.txt ├── 6996_03_07_40.txt ├── 6996_03_07_41.txt ├── 6996_03_07_42.txt ├── 6996_03_07_43.txt ├── 6996_03_07_44.txt ├── 6996_03_07_45.txt ├── 6996_03_07_46.txt ├── 6996_03_07_47.txt ├── 6996_03_07_48.txt ├── 6996_03_07_49.txt ├── 6996_03_07_50.txt ├── 6996_03_07_51.txt ├── 6996_03_07_52.txt ├── 6996_03_07_53.txt ├── 6996_03_07_54.txt ├── 6996_03_07_55.txt ├── 6996_03_07_56.txt ├── 6996_03_07_57.txt ├── 6996_03_07_58.txt ├── 6996_03_07_59.txt └── 6996_03_07_60.txt ├── Chapter04 ├── 6996_04_05_01.txt ├── 6996_04_06_01.txt ├── 6996_04_06_02.txt ├── 6996_04_06_03.txt ├── 6996_04_06_04.txt ├── 6996_04_06_05.txt ├── 6996_04_06_06.txt ├── 6996_04_06_07.txt ├── 6996_04_06_08.txt ├── 6996_04_06_09.txt ├── 6996_04_06_10.txt ├── 6996_04_06_11.txt ├── 6996_04_06_12.txt ├── 6996_04_06_13.txt ├── 6996_04_06_14.txt ├── 6996_04_06_15.txt ├── 6996_04_06_16.txt ├── 6996_04_06_17.txt ├── 6996_04_06_18.txt ├── 6996_04_06_19.txt ├── 6996_04_06_20.txt ├── 6996_04_06_21.txt ├── 6996_04_06_22.txt ├── 6996_04_07_01.txt ├── 6996_04_07_02.txt ├── 6996_04_07_03.txt ├── 6996_04_07_04.txt ├── 6996_04_07_05.txt ├── 6996_04_07_06.txt ├── 6996_04_07_07.txt ├── 6996_04_07_08.txt ├── 6996_04_07_09.txt ├── 6996_04_07_10.txt ├── 6996_04_07_11.txt ├── 6996_04_07_12.txt ├── 6996_04_07_13.txt ├── 6996_04_07_14.txt ├── 6996_04_07_15.txt ├── 6996_04_07_16.txt ├── 6996_04_07_17.txt ├── 6996_04_07_18.txt ├── 6996_04_07_19.txt ├── 6996_04_07_20.txt ├── 6996_04_07_21.txt ├── 6996_04_07_22.txt ├── 6996_04_07_23.txt ├── 6996_04_07_24.txt ├── 6996_04_07_25.txt ├── 6996_04_07_26.txt ├── 6996_04_07_27.txt ├── 6996_04_07_28.txt ├── 6996_04_07_29.txt ├── 6996_04_07_30.txt ├── 6996_04_07_31.txt ├── 6996_04_07_32.txt ├── 6996_04_07_33.txt ├── 6996_04_07_34.txt ├── 6996_04_07_35.txt ├── 6996_04_07_36.txt ├── 6996_04_07_37.txt ├── 6996_04_07_38.txt ├── 6996_04_07_39.txt ├── 6996_04_07_40.txt ├── 6996_04_07_41.txt ├── 6996_04_07_42.txt ├── 6996_04_07_43.txt ├── 6996_04_07_44.txt ├── 6996_04_07_45.txt ├── 6996_04_07_46.txt ├── 6996_04_07_47.txt ├── 6996_04_07_48.txt ├── 6996_04_07_49.txt ├── 6996_04_07_50.txt ├── 6996_04_07_51.txt ├── 6996_04_07_52.txt ├── 6996_04_07_53.txt ├── 6996_04_07_54.txt ├── 6996_04_07_55.txt ├── 6996_04_07_56.txt ├── 6996_04_07_57.txt ├── 6996_04_07_58.txt ├── 6996_04_07_59.txt ├── 6996_04_07_60.txt ├── 6996_04_07_61.txt ├── 6996_04_07_62.txt ├── 6996_04_07_63.txt ├── 6996_04_07_64.txt ├── 6996_04_07_65.txt ├── 6996_04_07_66.txt ├── 6996_04_07_67.txt ├── 6996_04_07_68.txt ├── 6996_04_07_69.txt ├── 6996_04_07_70.txt ├── 6996_04_07_71.txt ├── 6996_04_07_72.txt ├── 6996_04_07_73.txt ├── 6996_04_07_74.txt ├── 6996_04_07_75.txt ├── 6996_04_07_76.txt ├── 6996_04_07_77.txt ├── 6996_04_07_78.txt ├── 6996_04_07_79.txt ├── 6996_04_07_80.txt ├── 6996_04_07_81.txt ├── 6996_04_07_82.txt ├── 6996_04_07_83.txt ├── 6996_04_07_84.txt ├── 6996_04_07_85.txt ├── 6996_04_07_86.txt ├── 6996_04_07_87.txt ├── 6996_04_07_88.txt ├── 6996_04_07_89.txt ├── 6996_04_07_90.txt └── 6996_04_07_91.txt ├── Chapter05 ├── 6996_05_04_01.txt ├── 6996_05_04_02.txt ├── 6996_05_04_03.txt ├── 6996_05_04_04.txt ├── 6996_05_06_01.txt ├── 6996_05_06_02.txt ├── 6996_05_06_03.txt ├── 6996_05_06_04.txt ├── 6996_05_06_05.txt ├── 6996_05_06_06.txt ├── 6996_05_06_07.txt ├── 6996_05_06_08.txt ├── 6996_05_06_09.txt ├── 6996_05_07_01.txt ├── 6996_05_07_02.txt ├── 6996_05_07_03.txt ├── 6996_05_07_04.txt ├── 6996_05_07_05.txt ├── 6996_05_07_06.txt ├── 6996_05_07_07.txt ├── 6996_05_08_01.txt ├── 6996_05_08_02.txt ├── 6996_05_08_03.txt ├── 6996_05_08_04.txt ├── 6996_05_08_05.txt ├── 6996_05_08_06.txt ├── 6996_05_08_07.txt ├── 6996_05_08_08.txt ├── 6996_05_08_09.txt ├── 6996_05_08_10.txt ├── 6996_05_08_11.txt ├── 6996_05_09_01.txt ├── 6996_05_09_02.txt ├── 6996_05_09_03.txt ├── 6996_05_09_04.txt ├── 6996_05_09_05.txt ├── 6996_05_09_06.txt ├── 6996_05_09_07.txt ├── 6996_05_09_08.txt ├── 6996_05_09_09.txt ├── 6996_05_09_10.txt ├── 6996_05_09_11.txt ├── 6996_05_09_12.txt ├── 6996_05_09_13.txt ├── 6996_05_09_14.txt ├── 6996_05_09_15.txt ├── 6996_05_09_16.txt ├── 6996_05_09_17.txt ├── 6996_05_09_18.txt ├── 6996_05_09_19.txt ├── 6996_05_09_20.txt ├── 6996_05_09_21.txt ├── 6996_05_09_22.txt ├── 6996_05_09_23.txt ├── 6996_05_09_24.txt ├── 6996_05_09_25.txt ├── 6996_05_09_26.txt ├── 6996_05_09_27.txt ├── 6996_05_09_28.txt ├── 6996_05_09_29.txt ├── 6996_05_09_30.txt ├── 6996_05_09_31.txt ├── 6996_05_09_32.txt ├── 6996_05_09_33.txt ├── 6996_05_09_34.txt ├── 6996_05_09_35.txt ├── 6996_05_09_36.txt ├── 6996_05_09_37.txt ├── 6996_05_09_38.txt ├── 6996_05_09_39.txt ├── 6996_05_09_40.txt ├── 6996_05_09_41.txt ├── 6996_05_09_42.txt ├── 6996_05_09_43.txt ├── 6996_05_09_44.txt ├── 6996_05_09_45.txt ├── 6996_05_09_46.txt ├── 6996_05_09_47.txt ├── 6996_05_09_48.txt ├── 6996_05_09_49.txt ├── 6996_05_09_50.txt ├── 6996_05_09_51.txt ├── 6996_05_09_52.txt ├── 6996_05_09_53.txt └── 6996_05_09_54.txt ├── Chapter06 └── README.txt ├── Chapter07 └── local-query-request ├── Chapter08 ├── data │ ├── cpu_alert.tick │ └── ticker_data.txt ├── goclientInfluxDBtest.go └── influxdb-test │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── sample │ └── influxdb │ └── InfluxDBApiTest.java ├── LICENSE └── README.md /Chapter01/README.txt: -------------------------------------------------------------------------------- 1 | This chapter doesnot contain any code files -------------------------------------------------------------------------------- /Chapter02/crud-op.txt: -------------------------------------------------------------------------------- 1 | /* 2 | create and switch to sample_db 3 | */ 4 | 5 | use sample_db; 6 | 7 | /* 8 | list all the databases in the system 9 | */ 10 | show databases(); 11 | 12 | /* 13 | create collection names users_profile 14 | */ 15 | db.createCollection("users_profile"); 16 | 17 | /* 18 | inserting single document in collection users_profile 19 | */ 20 | db.users_profile.insertOne({ 21 | userId:1, 22 | firstName:"John", 23 | lastName:"Richard", 24 | age:26, 25 | email:"john2992@mail.com" 26 | }); 27 | 28 | /* 29 | inserting multiple documents in collection users_profile 30 | */ 31 | db.users_profile.insertMany([{ 32 | userId:1, 33 | firstName:"John", 34 | lastName:"Richard", 35 | age:26, 36 | email:"john2992@mail.com" 37 | }, 38 | { 39 | userId:2, 40 | firstName:"Kedar", 41 | lastName:"Sans", 42 | age:29, 43 | email:"kedar.sans@mail.com" 44 | }, 45 | { 46 | userId:3, 47 | firstName:"Chan", 48 | lastName:"Kuli", 49 | age:27, 50 | email:"chan.k@mail.com" 51 | }]); 52 | /* 53 | getting all the documents from users_profile collection 54 | */ 55 | db.users_profile.find({}); 56 | /* 57 | getting documents from users_profile where firstName is john 58 | */ 59 | db.users_profile.find({firstName:"John"}); 60 | /* 61 | finding all the documents where firstName is John and Kedar 62 | */ 63 | db.users_profile.find({ 64 | firstName:{ 65 | $in : ["John", "Kedar"] 66 | } 67 | }); 68 | /* 69 | getting users_profile where name is john and age is less than 30 70 | */ 71 | db.users_profile.find({ 72 | firstName:"John", 73 | age :{ 74 | $lt : 30 75 | } 76 | }); 77 | 78 | /* 79 | getting documents where firstName is John or age less than 30 80 | */ 81 | 82 | db.users_profile.find({ 83 | $or : [ 84 | { "firstName" : "John" }, 85 | { "age" : { $lt : 30 } } 86 | ] 87 | }); 88 | 89 | /* 90 | 91 | */ 92 | db.users_profile.find({ 93 | "firstName" : "John", 94 | $or : [ 95 | { "age" : { $lt : 30 } }, 96 | { "lastName" : /^s/ }, 97 | ] 98 | }); 99 | /* 100 | update single document 101 | */ 102 | db.users_profile.updateOne( 103 | { "userId" : 1 }, 104 | { $set : { "age" : 20 }} 105 | ); 106 | 107 | /* 108 | update multiple documents 109 | */ 110 | 111 | 112 | db.users_profile.updateMany( 113 | { "age" : 20 }, 114 | { $set : { "age" : 35 }} 115 | ); 116 | /* 117 | replace document 118 | */ 119 | 120 | db.users_profile.replaceOne( 121 | { "userId" : 1 }, 122 | { 123 | "userId" : 1.0, 124 | "firstName" : "Sam", 125 | "lastName" : "Billings", 126 | "age" : 26.0, 127 | "email" : "sam2992@mail.com" 128 | }) 129 | /* 130 | delete single document 131 | */ 132 | db.users_profile.deleteOne({"userId":1}); 133 | 134 | /* 135 | delete all the documents 136 | */ 137 | 138 | db.users_profile.deleteMany({}); 139 | 140 | -------------------------------------------------------------------------------- /Chapter02/query.txt: -------------------------------------------------------------------------------- 1 | /* 2 | create index on user_profiles field firstName 3 | */ 4 | db.user_profiles.createIndex({ "firstName" : 1 }); 5 | 6 | 7 | /* 8 | inserting documents in review collection 9 | */ 10 | 11 | db.reviews.insertMany([{"comments":"movie is nice", "subject":"comedy"}, 12 | {"comments":"fiction movie", "subject":"fiction"}]); 13 | 14 | 15 | /* 16 | creating multikey index on review collection 17 | */ 18 | db.reviews.createIndex({ 19 | "comments" : "text", 20 | "subject" : "text" 21 | }); 22 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_01.txt: -------------------------------------------------------------------------------- 1 | sudo mkdir /local 2 | sudo chown $USER:$USER /local 3 | cd /local 4 | mv ~/Downloads/neo4j-community-3.3.3-unix.tar.gz . 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_02.txt: -------------------------------------------------------------------------------- 1 | tar -zxvf neo4j-community-3.3.3-unix.tar.gz -------------------------------------------------------------------------------- /Chapter03/6996_03_06_03.txt: -------------------------------------------------------------------------------- 1 | mv neo4j-community-3.3.3/ neo4j/ -------------------------------------------------------------------------------- /Chapter03/6996_03_06_04.txt: -------------------------------------------------------------------------------- 1 | # The name of the database to mount 2 | dbms.active_database=graph.db 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_05.txt: -------------------------------------------------------------------------------- 1 | # Paths of directories in the installation. 2 | #dbms.directories.data=data 3 | #dbms.directories.plugins=plugins 4 | #dbms.directories.certificates=certificates 5 | #dbms.directories.logs=logs 6 | #dbms.directories.lib=lib 7 | #dbms.directories.run=run 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_06.txt: -------------------------------------------------------------------------------- 1 | dbms.directories.data=/data0 2 | dbms.directories.logs=/var/log/neo4j 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_07.txt: -------------------------------------------------------------------------------- 1 | dbms.connectors.default_listen_address=192.168.0.100 2 | dbms.connectors.default_advertised_address=192.168.0.100 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_08.txt: -------------------------------------------------------------------------------- 1 | # Bolt connector 2 | dbms.connector.bolt.enabled=true 3 | dbms.connector.bolt.listen_address=:7687 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_09.txt: -------------------------------------------------------------------------------- 1 | # HTTP Connector. There must be exactly one HTTP connector. 2 | dbms.connector.http.enabled=true 3 | #dbms.connector.http.listen_address=:7474 4 | 5 | # HTTPS Connector. There can be zero or one HTTPS connectors. 6 | dbms.connector.https.enabled=true 7 | #dbms.connector.https.listen_address=:7473 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_10.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j-admin set-initial-password flynnLives 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_11.txt: -------------------------------------------------------------------------------- 1 | dbms.udc.enabled=false 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_12.txt: -------------------------------------------------------------------------------- 1 | dbms.jvm.additional=-Xss1M 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_13.txt: -------------------------------------------------------------------------------- 1 | dbms.memory.heap.max_size=24G 2 | dbms.memory.heap.initial_size=24G 3 | dbms.jvm.additional=-XX:+UseG1GC 4 | dbms.jvm.additional=-XX:MaxGCPauseMillis=200 5 | 6 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_14.txt: -------------------------------------------------------------------------------- 1 | ha.server_id=1 2 | ha.initial_hosts=192.168.0.100:5001,192.168.0.101:5001,192.168.0.102:5001 3 | dbms.mode=HA 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_15.txt: -------------------------------------------------------------------------------- 1 | causal_clustering.initial_discovery_members=192.168.0.100:5000,192.168.0.101:5000,192.168.0.102:5000 2 | causal_clustering.expected_core_cluster_size=3 3 | dbms.mode=CORE 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_06_16.txt: -------------------------------------------------------------------------------- 1 | dbms.mode=READ_REPLICA 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_01.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j console 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_02.txt: -------------------------------------------------------------------------------- 1 | Active database: graph.db 2 | Directories in use: 3 | home: /local/neo4j 4 | config: /local/neo4j/conf 5 | logs: /local/neo4j/logs 6 | plugins: /local/neo4j/plugins 7 | import: /local/neo4j/import 8 | data: /local/neo4j/data 9 | certificates: /local/neo4j/certificates 10 | run: /local/neo4j/run 11 | Starting Neo4j. 12 | 2017-07-09 17:10:05.300+0000 INFO ======== Neo4j 3.2.2 ======== 13 | 2017-07-09 17:10:05.342+0000 INFO Starting... 14 | 2017-07-09 17:10:06.464+0000 INFO Bolt enabled on 192.168.0.100:7687. 15 | 2017-07-09 17:10:09.576+0000 INFO Started. 16 | 2017-07-09 17:10:10.982+0000 INFO Remote interface available at http://192.168.0.100:7474/ 17 | 18 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_03.txt: -------------------------------------------------------------------------------- 1 | tail -f /local/neo4j/log/neo4j.log 2 | 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_04.txt: -------------------------------------------------------------------------------- 1 | sudo service neo4j start 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_05.txt: -------------------------------------------------------------------------------- 1 | INFO Remote interface available at http://192.168.0.100:7474/ 2 | 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_06.txt: -------------------------------------------------------------------------------- 1 | CREATE (:Message { title:"Welcome",text:"Hello world!" }); 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_07.txt: -------------------------------------------------------------------------------- 1 | MATCH (n:Message) RETURN n LIMIT 25; 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_08.txt: -------------------------------------------------------------------------------- 1 | : 0 text: Hello world! Title: Welcome 2 | 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_09.txt: -------------------------------------------------------------------------------- 1 | CREATE (:Language { name:"Cypher",version:"Cypher w/ Neo4j 3.2.2" }); 2 | 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_10.txt: -------------------------------------------------------------------------------- 1 | MATCH (m:Message),(c:Language) 2 | WHERE m.title = 'Welcome' AND c.name = 'Cypher' 3 | CREATE (m)-[:ACCESSED_FROM]->(c); 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_11.txt: -------------------------------------------------------------------------------- 1 | pip install neo4j-driver 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_12.txt: -------------------------------------------------------------------------------- 1 | python neoCmdFile.py 192.168.0.100 neo4j flynnLives astronaut_data.neo 2 | 3 | Data from astronaut_data.neo loaded! 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_13.txt: -------------------------------------------------------------------------------- 1 | dbms.jvm.additional=-Xss2M 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_14.txt: -------------------------------------------------------------------------------- 1 | MATCH p=()-[r:RECRUITED_IN_CLASS]->(g {group:"1"}) RETURN p; 2 | 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_15.txt: -------------------------------------------------------------------------------- 1 | MATCH (a:Astronaut)-[:FLEW_ON]->(m:Mission {name:'Apollo 13'}) 2 | RETURN a, m; 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_16.txt: -------------------------------------------------------------------------------- 1 | MATCH (s:School)<-[:EDUCATED_AT]- 2 | (a:Astronaut)-[:FLEW_ON]->(m:Mission {name:'Apollo 13'}) 3 | RETURN a, m, s; 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_17.txt: -------------------------------------------------------------------------------- 1 | sudo pip install neo4j-driver 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_18.txt: -------------------------------------------------------------------------------- 1 | from neo4j.v1 import GraphDatabase, basic_auth 2 | import sys 3 | 4 | hostname=sys.argv[1] 5 | username=sys.argv[2] 6 | password=sys.argv[3] 7 | 8 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_19.txt: -------------------------------------------------------------------------------- 1 | driver = GraphDatabase.driver("bolt://" + hostname + ":7687", 2 | auth=basic_auth(username,password)) 3 | session = driver.session() 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_20.txt: -------------------------------------------------------------------------------- 1 | createLanguage = "CREATE (:Language {name:{name},version:{ver}});" 2 | session.run(createLanguage,{"name":"Python","ver":"2.7.13"}) 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_21.txt: -------------------------------------------------------------------------------- 1 | createRelationship = """MATCH (m:Message),(l:Language) 2 | WHERE m.title = 'Welcome' AND l.name='Python' 3 | CREATE (m)-[:ACCESSED_FROM]->(l);""" 4 | session.run(createRelationship) 5 | 6 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_22.txt: -------------------------------------------------------------------------------- 1 | queryRelationship = """MATCH (m:Message)-[:ACCESSED_FROM]-> 2 | (l:Language {name:'Python'}) 3 | RETURN m,l;""" 4 | resultSet = session.run(queryRelationship) 5 | 6 | for result in resultSet: 7 | print("%s from %s" % (result["m"]["text"], result["l"]["name"])) 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_23.txt: -------------------------------------------------------------------------------- 1 | session.close() 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_24.txt: -------------------------------------------------------------------------------- 1 | python neo4jHelloWorld.py 192.168.0.100 neo4j flynnLives 2 | Hello world! from Python 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_25.txt: -------------------------------------------------------------------------------- 1 | from neo4j.v1 import GraphDatabase, basic_auth 2 | import sys 3 | 4 | hostname=sys.argv[1] 5 | username=sys.argv[2] 6 | password=sys.argv[3] 7 | 8 | driver = GraphDatabase.driver("bolt://" + hostname + ":7687", 9 | auth=basic_auth(username,password)) 10 | session = driver.session() 11 | 12 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_26.txt: -------------------------------------------------------------------------------- 1 | createMission = "CREATE (:Mission {name:{name}});" 2 | session.run(createMission,{"name":"ISS-51/52 (Soyuz)"}) 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_27.txt: -------------------------------------------------------------------------------- 1 | createRelationship = """MATCH (m:Mission),(a:Astronaut) 2 | WHERE m.name={mname} AND a.name={aname} 3 | CREATE (a)-[:FLEW_ON]->(m);""" 4 | session.run(createRelationship,{"mname":"ISS-51/52 (Soyuz)", 5 | "aname":"Jack D. Fischer"}) 6 | session.run(createRelationship,{"mname":"ISS-51/52 (Soyuz)", 7 | "aname":"Peggy A. Whitson"}) 8 | session.run(createRelationship,{"mname":"ISS-51/52 (Soyuz)", 9 | "aname":"Randolph J. Bresnik"}) 10 | 11 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_28.txt: -------------------------------------------------------------------------------- 1 | queryRelationship = """MATCH (m:Mission {name:'ISS-51/52 (Soyuz)'}) 2 | <-[:FLEW_ON]-(a:Astronaut) RETURN m,a;""" 3 | resultSet = session.run(queryRelationship) 4 | 5 | for result in resultSet: 6 | print("%s flew on %s" % (result["a"]["name"],result["m"]["name"])) 7 | 8 | session.close() 9 | 10 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_29.txt: -------------------------------------------------------------------------------- 1 | python neo4jISS52.py 192.168.0.100 neo4j flynnLives 2 | Randolph J. Bresnik flew on ISS-51/52 (Soyuz) 3 | Peggy A. Whitson flew on ISS-51/52 (Soyuz) 4 | Jack D. Fischer flew on ISS-51/52 (Soyuz) 5 | 6 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_30.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.neo4j.driver 4 | neo4j-java-driver 5 | 1.2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_31.txt: -------------------------------------------------------------------------------- 1 | import org.neo4j.driver.v1.AuthTokens; 2 | import org.neo4j.driver.v1.Driver; 3 | import org.neo4j.driver.v1.GraphDatabase; 4 | import org.neo4j.driver.v1.Session; 5 | 6 | public class Neo4jConnection { 7 | private Driver driver; 8 | private Session session; 9 | 10 | public Neo4jConnection() { 11 | } 12 | 13 | public Neo4jConnection(String node, String user, String pwd) { 14 | connect(node,user,pwd); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_32.txt: -------------------------------------------------------------------------------- 1 | public void connect(String node, String user, String pwd) { 2 | driver = GraphDatabase.driver( "bolt://" 3 | + node + ":7687", AuthTokens.basic( user, pwd ) ); 4 | session = driver.session(); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_33.txt: -------------------------------------------------------------------------------- 1 | public Session getSession() { 2 | return session; 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_34.txt: -------------------------------------------------------------------------------- 1 | public void close() { 2 | session.close(); 3 | driver.close(); 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_35.txt: -------------------------------------------------------------------------------- 1 | import org.neo4j.driver.v1.Session; 2 | import org.neo4j.driver.v1.StatementResult; 3 | import org.neo4j.driver.v1.Record; 4 | import static org.neo4j.driver.v1.Values.parameters; 5 | 6 | public class Neo4jHelloWorld { 7 | public static void main(String[] args) { 8 | Neo4jConnection conn = new Neo4jConnection( 9 | "192.168.0.100","neodba","flynnLives"); 10 | Session session = conn.getSession(); 11 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_36.txt: -------------------------------------------------------------------------------- 1 | session.run( "CREATE (:Language {name:{name},version:{ver}})", 2 | parameters("name", "Java", "ver", "1.8.0_74")); 3 | 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_37.txt: -------------------------------------------------------------------------------- 1 | String createRelationship = "MATCH (m:Message),(l:Language) " 2 | + "WHERE m.title = {title} AND l.name={language} " 3 | + "CREATE (m)-[:ACCESSED_FROM]->(l);"; 4 | session.run(createRelationship, 5 | parameters("title", "Welcome", "language", "Java")); 6 | 7 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_38.txt: -------------------------------------------------------------------------------- 1 | String queryRelationship = "MATCH (m:Message)-[:ACCESSED_FROM]->" 2 | + "(l:Language {name:{language}}) " 3 | + "RETURN m.title,l.name;"; 4 | StatementResult resultSet = session.run(queryRelationship, 5 | parameters("language", "Java")); 6 | 7 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_39.txt: -------------------------------------------------------------------------------- 1 | while (resultSet.hasNext()) { 2 | Record result = resultSet.next(); 3 | System.out.println( result.get("m.title") 4 | + " from " + result.get("l.name")); 5 | } 6 | 7 | session.close(); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_40.txt: -------------------------------------------------------------------------------- 1 | "Welcome" from "Java" 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_41.txt: -------------------------------------------------------------------------------- 1 | public class Neo4jISS53 { 2 | public static void main(String[] args) { 3 | Neo4jConnection conn = new 4 | Neo4jConnection("192.168.0.100","neodba","flynnLives"); 5 | Session session = conn.getSession(); 6 | 7 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_42.txt: -------------------------------------------------------------------------------- 1 | String createMission = "CREATE (:Mission {name:{name}})"; 2 | session.run(createMission, 3 | parameters("name","ISS-52/53 (Soyuz)")); 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_43.txt: -------------------------------------------------------------------------------- 1 | String createRelationship = "MATCH (m:Mission),(a:Astronaut) " 2 | + "WHERE m.name={mname} AND a.name={aname} " 3 | + "CREATE (a)-[:FLEW_ON]->(m)"; 4 | session.run(createRelationship, 5 | parameters("mname","ISS-52/53 (Soyuz)", 6 | "aname","Joseph M. Acaba")); 7 | session.run(createRelationship, 8 | parameters("mname","ISS-52/53 (Soyuz)", 9 | "aname","Mark T. VandeHei")); 10 | session.run(createRelationship, 11 | parameters("mname","ISS-52/53 (Soyuz)", 12 | "aname","Randolph J. Bresnik")); 13 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_44.txt: -------------------------------------------------------------------------------- 1 | String queryRelationship = "MATCH (m:Mission {name:{name}})” 2 | + "<-[:FLEW_ON]-" 3 | + "(a:Astronaut) RETURN m.name,a.name;"; 4 | StatementResult resultSet = session.run(queryRelationship, 5 | parameters("name", "ISS-52/53 (Soyuz)")); 6 | 7 | while (resultSet.hasNext()) { 8 | Record result = resultSet.next(); 9 | System.out.println( result.get("a.name") 10 | + " flew on " + result.get("m.name")); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_45.txt: -------------------------------------------------------------------------------- 1 | session.close(); 2 | } 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_46.txt: -------------------------------------------------------------------------------- 1 | "Randolph J. Bresnik" flew on "ISS-52/53 (Soyuz)" 2 | "Mark T. Vande Hei" flew on "ISS-52/53 (Soyuz)" 3 | "Joseph M. Acaba" flew on "ISS-52/53 (Soyuz)" 4 | 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_47.txt: -------------------------------------------------------------------------------- 1 | dbms.backup.enabled=true 2 | dbms.backup.address=192.168.0.100:6362 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_48.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j-admin backup --from=192.168.0.100 --backup-dir=/backups/ --name=astronaut.db-backup 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_49.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j-admin backup --from=192.168.0.100 --backup-dir=/backups/ --name=astronaut.db-backup --fallback-to-full=true 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_50.txt: -------------------------------------------------------------------------------- 1 | neo4j stop 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_51.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j-admin restore -from=/backups/astronaut.db-backup --database=graph.db --force 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_52.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j stop 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_53.txt: -------------------------------------------------------------------------------- 1 | mkdir /backups/astronaut.db-backup/ 2 | bin/neo4j-admin dump --database=graph.db --to=/backups/astronaut.db-backup/2017-09-11.dump 3 | bin/neo4j start 4 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_54.txt: -------------------------------------------------------------------------------- 1 | CREATE (m:Mission {name: 'ISS-53/54 (Soyuz)'}); 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_55.txt: -------------------------------------------------------------------------------- 1 | MATCH (m:Mission),(a:Astronaut) WHERE m.name='ISS-53/54 (Soyuz)' AND 2 | a.name='Neil A. Armstrong' CREATE (a)-[:FLEW_ON]->(m); 3 | MATCH (m:Mission),(a:Astronaut) WHERE m.name='ISS-53/54 (Soyuz)' AND 4 | a.name='Janet L. Kavandi' CREATE (a)-[:FLEW_ON]->(m); 5 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_56.txt: -------------------------------------------------------------------------------- 1 | MATCH (m:Mission {name:"ISS-53/54 (Soyuz)"})<-[:FLEW_ON]-(a:Astronaut) RETURN m,a; 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_57.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j stop 2 | bin/neo4j-admin load --from=backups/astronaut.db-backup/2017-9-11.dump --database=graph.db -force 3 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_58.txt: -------------------------------------------------------------------------------- 1 | bin/neo4j start 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_59.txt: -------------------------------------------------------------------------------- 1 | MATCH (m:Mission {name:"ISS-53/54 (Soyuz)"})<-[:FLEW_ON]-(a:Astronaut) RETURN m,a; 2 | -------------------------------------------------------------------------------- /Chapter03/6996_03_07_60.txt: -------------------------------------------------------------------------------- 1 | MATCH (m:Mission {name:"ISS-53/54 (Soyuz)"})RETURN m; 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_05_01.txt: -------------------------------------------------------------------------------- 1 | sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled 2 | 3 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_01.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli --intrinsic-latency 30 2 | 3 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_02.txt: -------------------------------------------------------------------------------- 1 | Max latency so far: 1 microseconds. 2 | Max latency so far: 2 microseconds. 3 | Max latency so far: 44 microseconds. 4 | Max latency so far: 54 microseconds. 5 | Max latency so far: 59 microseconds. 6 | 7 | 284459835 total runs (avg latency: 0.1055 microseconds / 105.46 nanoseconds per run). 8 | Worst run took 559x longer than the average latency. 9 | 10 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_03.txt: -------------------------------------------------------------------------------- 1 | Machine #1: AMD A8-5500, quad core, 8GB RAM, Ubuntu 16.04 2 | Machine #2: Intel i7-4870, quad core, 16GB RAM, OSX 10.12 3 | Machine #3: VM hosted on OpenStack cloud, dual core, 16GB RAM, CentOS 7.3 -------------------------------------------------------------------------------- /Chapter04/6996_04_06_04.txt: -------------------------------------------------------------------------------- 1 | sudo mkdir /local 2 | sudo chown $USER:$USER /local 3 | cd /local 4 | mv ~/Downloads/redis-4.0.8.tar.gz . -------------------------------------------------------------------------------- /Chapter04/6996_04_06_05.txt: -------------------------------------------------------------------------------- 1 | tar -zxvf redis-4.0.8.tar.gz -------------------------------------------------------------------------------- /Chapter04/6996_04_06_06.txt: -------------------------------------------------------------------------------- 1 | mv redis-4.0.8/ redis -------------------------------------------------------------------------------- /Chapter04/6996_04_06_07.txt: -------------------------------------------------------------------------------- 1 | curl -O http://download.redis.io/redis-stable.tar.gz 2 | 3 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_08.txt: -------------------------------------------------------------------------------- 1 | tar -zxvf redis-stable.tar.gz 2 | 3 | mv redis-stable/ redis 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_09.txt: -------------------------------------------------------------------------------- 1 | sudo apt-get update 2 | 3 | sudo apt-get install gcc make tcl build-essential 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_10.txt: -------------------------------------------------------------------------------- 1 | cd redis 2 | 3 | make 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_11.txt: -------------------------------------------------------------------------------- 1 | make test 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_12.txt: -------------------------------------------------------------------------------- 1 | \o/ All tests passed without errors! 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_13.txt: -------------------------------------------------------------------------------- 1 | sudo utils/install_server.sh 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_14.txt: -------------------------------------------------------------------------------- 1 | Selected config: 2 | 3 | Port : 6379 4 | 5 | Config file : /etc/redis/6379.conf 6 | 7 | Log file : /var/log/redis_6379.log 8 | 9 | Data dir : /var/lib/redis/6379 10 | 11 | Executable : /local/redis/src/redis-server 12 | 13 | Cli Executable : /local/redis/src/redis-cli 14 | 15 | Is this ok? Then press ENTER to go on or Ctrl-C to abort. 16 | 17 | Copied /tmp/6379.conf => /etc/init.d/redis_6379 18 | 19 | Installing service... 20 | 21 | Success! 22 | 23 | Starting Redis server... 24 | 25 | Installation successful! 26 | 27 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_15.txt: -------------------------------------------------------------------------------- 1 | sudo service redis_6379 stop 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_16.txt: -------------------------------------------------------------------------------- 1 | requirepass currentHorseBatteryStaple 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_17.txt: -------------------------------------------------------------------------------- 1 | protected-mode yes 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_18.txt: -------------------------------------------------------------------------------- 1 | bind 127.0.0.1 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_19.txt: -------------------------------------------------------------------------------- 1 | sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled 2 | 3 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_20.txt: -------------------------------------------------------------------------------- 1 | src/redis-server 2 | redis.conf -------------------------------------------------------------------------------- /Chapter04/6996_04_06_21.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli 2 | 3 | 127.0.0.1:6379> ping 4 | 5 | (error) NOAUTH Authentication required. 6 | 7 | 127.0.0.1:6379> auth currentHorseBatteryStaple 8 | 9 | OK 10 | 11 | 127.0.0.1:6379> ping 12 | 13 | PONG 14 | 15 | 127.0.0.1:6379> exit 16 | 17 | -------------------------------------------------------------------------------- /Chapter04/6996_04_06_22.txt: -------------------------------------------------------------------------------- 1 | ps -ef | grep redis 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_01.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple -n 0 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_02.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> SELECT 0 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_03.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> set packt:welcome "Hello world!" 2 | 3 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_04.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> get packt:welcome 2 | 3 | “Hello world!” 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_05.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> getset packt:welcome "Hello world from getset!" 2 | 3 | "Hello world!" 4 | 5 | 127.0.0.1:6379> get packt:welcome 6 | 7 | "Hello world from getset!" 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_06.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> zadd games:joust 48850 Connor 2 | 3 | (integer) 1 4 | 5 | 127.0.0.1:6379> zadd games:joust 58150 Dad 6 | 7 | (integer) 1 8 | 9 | 127.0.0.1:6379> zadd games:joust 49910 Toria 10 | 11 | (integer) 1 12 | 13 | 127.0.0.1:6379> zadd games:joust 29910 Toria 14 | 15 | (integer) 0 16 | 17 | 127.0.0.1:6379> zrange games:joust 0 -1 WITHSCORES 18 | 19 | 1) "Toria" 20 | 21 | 2) "29910" 22 | 23 | 3) "Connor" 24 | 4) "48850" 25 | 26 | 5) "Dad" 27 | 28 | 6) "58150" 29 | 30 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_07.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> zrevrange games:joust 0 -1 WITHSCORES 2 | 3 | 1) "Dad" 4 | 5 | 2) "58150" 6 | 7 | 3) "Connor" 8 | 9 | 4) "48850" 10 | 11 | 5) "Toria" 12 | 13 | 6) "29910" 14 | 15 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_08.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379>lpush packt:logins "aploetz 10.0.0.4 2017-06-24 16:22:04.144998" 2 | 3 | (integer) 1 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_09.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> lpush packt:logins "aploetz 10.0.0.4 2017-06-24 16:31:58.171875" 2 | 3 | (integer) 2 4 | 5 | 127.0.0.1:6379> lrange packt:logins 0 -1 6 | 7 | 1) "aploetz 10.0.0.4 2017-06-24 16:31:58.171875" 8 | 9 | 2) "aploetz 10.0.0.4 2017-06-24 16:22:04.144998" 10 | 11 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_10.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple -n 0 2 | 127.0.0.1:6379> subscribe greeting 3 | Reading messages... (press Ctrl-C to quit) 4 | 1) "subscribe" 5 | 2) "greeting" 6 | 3) (integer) 1 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_11.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple -n 0 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_12.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> publish greeting "Hello world!" 2 | (integer) 1 3 | 127.0.0.1:6379> publish greeting "Hello world from pub/sub" 4 | (integer) 1 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_13.txt: -------------------------------------------------------------------------------- 1 | 1) "message" 2 | 2) "greeting" 3 | 3) "Hello world!" 4 | 1) "message" 5 | 2) "greeting" 6 | 3) "Hello world from pub/sub!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_14.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> unsubscribe 2 | 1) "unsubscribe" 3 | 2) (nil) 4 | 3) (integer) 0 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_15.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> EVAL 'local text="Hello world!" return text' 0 2 | "Hello world!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_16.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> EVAL 'local text=redis.call("get","packt:welcome") return 2 | text' 0 3 | "Hello world from getset!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_17.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> set packt:welcome "Hello world from Lua!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_18.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> EVAL 'local text=redis.call("get","packt:welcome") return 2 | text' 0 3 | "Hello world from Lua!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_19.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> EVAL 'local text=redis.call("get",KEYS[1]) return text' 1 2 | packt:welcome 3 | "Hello world from Lua!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_20.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> EVAL 'local text=redis.call("get",KEYS[1]) return "Dear " 2 | .. ARGV[1] .. ", " .. text' 1 packt:welcome Coriene 3 | "Dear Coriene, Hello world from Lua!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_21.txt: -------------------------------------------------------------------------------- 1 | local msg=redis.call("get",KEYS[1]) 2 | local name=ARGV[1] 3 | local output="Dear "..name..", "..msg 4 | return output -------------------------------------------------------------------------------- /Chapter04/6996_04_07_22.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple --eval welcomeName.lua 2 | packt:welcome , Coriene 3 | "Dear Coriene, Hello world from Lua!" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_23.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> zrevrange games:joust 0 -1 WITHSCORES -------------------------------------------------------------------------------- /Chapter04/6996_04_07_24.txt: -------------------------------------------------------------------------------- 1 | return redis.call("zrevrange", KEYS[1], 0, -1,"WITHSCORES") -------------------------------------------------------------------------------- /Chapter04/6996_04_07_25.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple --eval getHighScores.lua 2 | games:joust 3 | 1) "Dad" 4 | 2) "58150" 5 | 3) "Connor" 6 | 4) "48850" 7 | 5) "Toria" 8 | 6) "29910" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_26.txt: -------------------------------------------------------------------------------- 1 | return redis.call("zrevrange", "games:joust", 0, -1, "WITHSCORES") -------------------------------------------------------------------------------- /Chapter04/6996_04_07_27.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple --eval getJoustScores.lua 2 | 1) "Dad" 3 | 2) "58150" 4 | 3) "Connor" 5 | 4) "48850" 6 | 5) "Toria" 7 | 6) "29910" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_28.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> lrange packt:logins 0 -1 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_29.txt: -------------------------------------------------------------------------------- 1 | return redis.call("lrange", KEYS[1], 0, -1) -------------------------------------------------------------------------------- /Chapter04/6996_04_07_30.txt: -------------------------------------------------------------------------------- 1 | src/redis-cli -a currentHorseBatteryStaple --eval getList.lua packt:logins 2 | 1) "aploetz 10.0.0.4 2017-06-24 16:31:58.171875" 3 | 2) "aploetz 10.0.0.4 2017-06-24 16:22:04.144998" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_31.txt: -------------------------------------------------------------------------------- 1 | pip install redis 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_32.txt: -------------------------------------------------------------------------------- 1 | pip install hiredis 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_33.txt: -------------------------------------------------------------------------------- 1 | from redis import StrictRedis 2 | 3 | import sys 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_34.txt: -------------------------------------------------------------------------------- 1 | hostname = sys.argv[1] 2 | 3 | password = sys.argv[2] 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_35.txt: -------------------------------------------------------------------------------- 1 | r = StrictRedis(host=hostname,port=6379,password=password,db=0) 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_36.txt: -------------------------------------------------------------------------------- 1 | def setPacktWelcome(): 2 | 3 | #SET new value packt:welcome 4 | 5 | print("Writing \"Hello world from Python!\" to Redis...") 6 | 7 | r.set('packt:welcome','Hello world from Python!') 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_37.txt: -------------------------------------------------------------------------------- 1 | def getPacktWelcome(): 2 | 3 | #GET value stored in packt:welcome 4 | 5 | print("Displaying current welcome message...") 6 | 7 | value = r.get('packt:welcome') 8 | 9 | print("message = " + str(value)) 10 | 11 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_38.txt: -------------------------------------------------------------------------------- 1 | getPacktWelcome() 2 | 3 | setPacktWelcome() 4 | 5 | getPacktWelcome() 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_39.txt: -------------------------------------------------------------------------------- 1 | python redisHelloWorld.py 127.0.0.1 2 | currentHorseBatteryStaple 3 | 4 | Displaying current welcome message... 5 | 6 | message = Hello world! 7 | 8 | Writing "Hello world from Python!" to Redis... 9 | 10 | Displaying current welcome message... 11 | 12 | message = Hello world from Python! 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_40.txt: -------------------------------------------------------------------------------- 1 | from redis import StrictRedis 2 | 3 | from datetime import datetime 4 | 5 | import sys 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_41.txt: -------------------------------------------------------------------------------- 1 | hostname=sys.argv[1] 2 | 3 | password=sys.argv[2] 4 | 5 | userid=sys.argv[3] 6 | 7 | ip=sys.argv[4] 8 | 9 | 10 | r = StrictRedis(host=hostname,port=6379,password=password,db=0) 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_42.txt: -------------------------------------------------------------------------------- 1 | def addNewLogin(user,ipaddress): 2 | 3 | print("Logging entry for " + user + " from " + ipaddress) 4 | 5 | time = str(datetime.now()) 6 | 7 | r.lpush('packt:logins',user + " " + ipaddress + " " + time) 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_43.txt: -------------------------------------------------------------------------------- 1 | r.ltrim('packt:logins',0,2) 2 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_44.txt: -------------------------------------------------------------------------------- 1 | def getList(): 2 | 3 | list = r.lrange('packt:logins',0,-1) 4 | 5 | print(list) 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_45.txt: -------------------------------------------------------------------------------- 1 | addNewLogin(userid,ip) 2 | 3 | getList() 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_46.txt: -------------------------------------------------------------------------------- 1 | python redisQueryUser.py 127.0.0.1 currentHorseBatteryStaple aploetz 10.0.0.6 2 | 3 | Logging entry for aploetz from 10.0.0.6 4 | 5 | ['aploetz 10.0.0.6 2017-06-24 16:43:29.228135', 'aploetz 10.0.0.4 2017-06-24 16:31:58.171875', 'aploetz 10.0.0.4 2017-06-24 16:22:04.144998'] 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_47.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> lrange packt:logins 0 -1 2 | 3 | 1) "aploetz 10.0.0.9 2017-06-24 16:43:49.958260" 4 | 5 | 2) "aploetz 10.0.0.6 2017-06-24 16:43:29.228135" 6 | 7 | 3) "aploetz 10.0.0.4 2017-06-24 16:31:58.171875" 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_48.txt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from redis import StrictRedis 3 | import sys 4 | if len(sys.argv) < 4: 5 | print "Please enter a valid hostname, password, and channel." 6 | exit(len(sys.argv)) 7 | hostname=sys.argv[1] 8 | password=sys.argv[2] 9 | channel=sys.argv[3] -------------------------------------------------------------------------------- /Chapter04/6996_04_07_49.txt: -------------------------------------------------------------------------------- 1 | r = StrictRedis(host=hostname,port=6379,password=password,db=0) 2 | publisher = r.pubsub() -------------------------------------------------------------------------------- /Chapter04/6996_04_07_50.txt: -------------------------------------------------------------------------------- 1 | while True: 2 | message=raw_input("Describe play, or press [Enter] to quit: ") 3 | if not message: 4 | break 5 | else: 6 | r.publish(channel,message) 7 | print "Publish program ended. " -------------------------------------------------------------------------------- /Chapter04/6996_04_07_51.txt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from redis import StrictRedis 3 | import sys 4 | if len(sys.argv) < 4: 5 | print "Please enter a valid hostname, password, and channel." 6 | exit(len(sys.argv)) 7 | hostname=sys.argv[1] 8 | password=sys.argv[2] 9 | channel=sys.argv[3] -------------------------------------------------------------------------------- /Chapter04/6996_04_07_52.txt: -------------------------------------------------------------------------------- 1 | r = StrictRedis(host=hostname,port=6379,password=password,db=0) 2 | channels = r.pubsub() 3 | channels.subscribe(channel) -------------------------------------------------------------------------------- /Chapter04/6996_04_07_53.txt: -------------------------------------------------------------------------------- 1 | for message in channels.listen(): 2 | if message['data']=='END': 3 | break 4 | else: 5 | print message['data'] 6 | channels.unsubscribe(channel) 7 | print "Unsubscribed" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_54.txt: -------------------------------------------------------------------------------- 1 | python redisSub.py 127.0.0.1 currentHorseBatteryStaple OMG15UBaseball 2 | 1 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_55.txt: -------------------------------------------------------------------------------- 1 | python redisPub.py 127.0.0.1 currentHorseBatteryStaple OMG15UBaseball 2 | Describe play; [Enter] to quit: Henry strikes out swinging (Out 1). 3 | Describe play; [Enter] to quit: Avery singles to RF. 4 | Describe play; [Enter] to quit: Avery steals 2b. 5 | Describe play; [Enter] to quit: Gareth doubles to LF, Avery scores. 6 | Describe play; [Enter] to quit: Gareth steals 3b. 7 | Describe play; [Enter] to quit: Leighton grounds out to SS, Gareth scores 8 | (Out 2). 9 | Describe play; [Enter] to quit: Aaron grounds out to SS (Out 3). 10 | Describe play; [Enter] to quit: END 11 | Describe play; [Enter] to quit: 12 | Publish program ended. -------------------------------------------------------------------------------- /Chapter04/6996_04_07_56.txt: -------------------------------------------------------------------------------- 1 | 1 2 | Henry strikes out swinging (Out 1). 3 | Avery singles to RF. 4 | Avery steals 2b. 5 | Gareth doubles to LF, Avery scores. 6 | Gareth steals 3b. 7 | Leighton grounds out to SS, Gareth scores (Out 2). 8 | Aaron grounds out to SS (Out 3). 9 | Unsubscribed -------------------------------------------------------------------------------- /Chapter04/6996_04_07_57.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | redis.clients 4 | jedis 5 | 2.9.0 6 | jar 7 | compile 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_58.txt: -------------------------------------------------------------------------------- 1 | import redis.clients.jedis.Jedis; 2 | 3 | 4 | public class RedisConnection { 5 | private Jedis redisConn; 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_59.txt: -------------------------------------------------------------------------------- 1 | public RedisConnection() { 2 | } 3 | 4 | public RedisConnection(String node, String pwd) { 5 | connect(node,pwd); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_60.txt: -------------------------------------------------------------------------------- 1 | public void connect(String node, String pwd) { 2 | redisConn = new Jedis(node); 3 | redisConn.auth(pwd); 4 | } 5 | 6 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_61.txt: -------------------------------------------------------------------------------- 1 | public String get(String strKey) { 2 | return redisConn.get(strKey); 3 | } 4 | 5 | public void set(String strKey, String strValue) { 6 | redisConn.set(strKey, strValue); 7 | } 8 | 9 | public void close() { 10 | redisConn.close(); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_62.txt: -------------------------------------------------------------------------------- 1 | public class RedisHelloWorld { 2 | public static void main(String[] args) { 3 | RedisConnection conn = new RedisConnection("127.0.0.1", 4 | "currentHorseBatteryStaple"); 5 | System.out.println("Connected to Redis"); 6 | 7 | String key = "packt:welcome"; 8 | String newMessage = "Hello world from Java!"; 9 | 10 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_63.txt: -------------------------------------------------------------------------------- 1 | //GET value stored in packt:welcome System.out.println( 2 | "Displaying current welcome message..."); 3 | String message = conn.get("packt:welcome"); 4 | System.out.println(message); 5 | 6 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_64.txt: -------------------------------------------------------------------------------- 1 | //SET new value packt:welcome System.out.println( 2 | "Writing \"" + newMessage + "\" to Redis..."); 3 | conn.set(key,newMessage); 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_65.txt: -------------------------------------------------------------------------------- 1 | //GET value stored in packt:welcome System.out.println( 2 | "Displaying the new welcome message..."); 3 | message = conn.get("packt:welcome"); 4 | System.out.println(message); 5 | conn.close(); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_66.txt: -------------------------------------------------------------------------------- 1 | Connected to Redis 2 | 3 | Displaying current welcome message... 4 | 5 | Hello world from Python! 6 | 7 | Writing "Hello world from Java!" to Redis... 8 | 9 | Displaying the new welcome message... 10 | 11 | Hello world from Java! 12 | 13 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_67.txt: -------------------------------------------------------------------------------- 1 | public String getSet(String strKey, String strValue) { 2 | return redisConn.getSet(strKey, strValue); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_68.txt: -------------------------------------------------------------------------------- 1 | public List getList(String strKey) { 2 | return redisConn.lrange(strKey, 0, -1); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_69.txt: -------------------------------------------------------------------------------- 1 | public void pushToList(String strKey, String strValue) { 2 | redisConn.lpush(strKey, strValue); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_70.txt: -------------------------------------------------------------------------------- 1 | public void capList(String strKey, int intLen) { 2 | redisConn.ltrim(strKey, 0, intLen - 1); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_71.txt: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.text.SimpleDateFormat; 3 | import java.util.Date; 4 | 5 | public class RedisQueryUser { 6 | 7 | public static void main(String[] args) { 8 | RedisConnection conn = new RedisConnection( 9 | "127.0.0.1","currentHorseBatteryStaple"); 10 | System.out.println("Connected to Redis"); 11 | 12 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_72.txt: -------------------------------------------------------------------------------- 1 | String key = "packt:logins"; 2 | String userid = System.getProperty("user.name"); 3 | //get ip address as the lone command line argument String ip = args[0]; 4 | String strTime = new SimpleDateFormat( 5 | "yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); 6 | String value = userid + " " + ip + " " + strTime; 7 | 8 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_73.txt: -------------------------------------------------------------------------------- 1 | //log user 2 | conn.pushToList(key, value); 3 | 4 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_74.txt: -------------------------------------------------------------------------------- 1 | //keep list to a max of 3 2 | conn.capList(key, 3); 3 | 4 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_75.txt: -------------------------------------------------------------------------------- 1 | //read login list 2 | List logins = conn.getList(key); 3 | ; 4 | //output login list 5 | 6 | for (String user : logins) { 7 | System.out.println(user); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_76.txt: -------------------------------------------------------------------------------- 1 | conn.close(); 2 | } 3 | } 4 | 5 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_77.txt: -------------------------------------------------------------------------------- 1 | Connected to Redis 2 | 3 | aploetz 10.0.0.4 2017-07-01 10:21:43.196 4 | 5 | aploetz 10.0.0.9 2017-06-26 23:00:19.104434 6 | 7 | aploetz 10.0.0.9 2017-06-24 16:43:49.958260 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/6996_04_07_78.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> lastsave 2 | (integer) 1501703515 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_79.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> bgsave 2 | Background saving started -------------------------------------------------------------------------------- /Chapter04/6996_04_07_80.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> lastsave 2 | (integer) 1501703515 3 | 127.0.0.1:6379> lastsave 4 | (integer) 1501703515 5 | 127.0.0.1:6379> lastsave 6 | (integer) 1501790543 -------------------------------------------------------------------------------- /Chapter04/6996_04_07_81.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> config get dir 2 | 1) "dir" 3 | 2) "/var/lib/redis/6379" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_82.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> exit 2 | mkdir /local/redis/backup -------------------------------------------------------------------------------- /Chapter04/6996_04_07_83.txt: -------------------------------------------------------------------------------- 1 | ls -al /var/lib/redis/6379/ 2 | total 12 3 | drwxr-xr-x 2 root root 4096 Aug 3 15:02 . 4 | drwxr-xr-x 3 root root 4096 Jun 18 19:38 .. 5 | -rw-r--r-- 1 root root 394 Aug 3 15:02 dump.rdb -------------------------------------------------------------------------------- /Chapter04/6996_04_07_84.txt: -------------------------------------------------------------------------------- 1 | cp /var/lib/redis/6379/dump.rdb /local/redis/backup/dump_20170803.rdb -------------------------------------------------------------------------------- /Chapter04/6996_04_07_85.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:6379> set packt:welcome blahblahblahblah 2 | OK 3 | 127.0.0.1:6379> get packt:welcome 4 | "blahblahblahblah" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_86.txt: -------------------------------------------------------------------------------- 1 | sudo service redis_6379 stop -------------------------------------------------------------------------------- /Chapter04/6996_04_07_87.txt: -------------------------------------------------------------------------------- 1 | sudo mv /var/lib/redis/6379/dump.rdb /var/lib/redis/6379/dump_bad.rdb -------------------------------------------------------------------------------- /Chapter04/6996_04_07_88.txt: -------------------------------------------------------------------------------- 1 | grep appendonly /etc/redis/6379.conf 2 | appendonly no 3 | # The name of the append only file (default: "appendonly.aof") 4 | appendfilename "appendonly.aof" -------------------------------------------------------------------------------- /Chapter04/6996_04_07_89.txt: -------------------------------------------------------------------------------- 1 | sudo cp /local/redis/backup/dump_20170803.rdb /var/lib/redis/6379/dump.rdb -------------------------------------------------------------------------------- /Chapter04/6996_04_07_90.txt: -------------------------------------------------------------------------------- 1 | ls -al /var/lib/redis/6379/ 2 | total 16 3 | drwxr-xr-x 2 root root 4096 Sep 2 15:50 . 4 | drwxr-xr-x 3 root root 4096 Jun 18 19:38 .. 5 | -rw-r--r-- 1 root root 388 Aug 3 15:02 dump_bad.rdb 6 | -rw-r--r-- 1 root root 394 Aug 3 15:49 dump.rdb -------------------------------------------------------------------------------- /Chapter04/6996_04_07_91.txt: -------------------------------------------------------------------------------- 1 | sudo mv /var/lib/redis/6379/dump.rdb /var/lib/redis/6379/dump_bad.rdb -------------------------------------------------------------------------------- /Chapter05/6996_05_04_01.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE packt.logins_by_user ( 2 | user_id text, 3 | login_datetime timestamp, 4 | origin_ip textlogin_datetime, 5 | PRIMARY KEY ((user_id), login_datetime) 6 | ) WITH CLUSTERING ORDER BY (login_datetime DESC); 7 | 8 | -------------------------------------------------------------------------------- /Chapter05/6996_05_04_02.txt: -------------------------------------------------------------------------------- 1 | INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ('aploetz','2017-06-01 12:36:01','192.168.0.101'); 2 | INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ('aploetz','2017-06-01 12:53:28','192.168.0.101'); 3 | INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ('aploetz','2017-06-02 13:23:11','192.168.0.105'); 4 | INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ('aploetz','2017-06-03 09:04:55','192.168.0.101'); 5 | 6 | -------------------------------------------------------------------------------- /Chapter05/6996_05_04_03.txt: -------------------------------------------------------------------------------- 1 | aploetz@cqlsh:packt> SELECT * FROM logins_by_user 2 | WHERE user_id='aploetz'; 3 | 4 | user_id | login_datetime | origin_ip 5 | ---------+---------------------------------+--------------- 6 | aploetz | 2017-06-03 14:04:55.000000+0000 | 192.168.0.101 7 | aploetz | 2017-06-02 18:23:11.000000+0000 | 192.168.0.105 8 | aploetz | 2017-06-01 17:53:28.000000+0000 | 192.168.0.101 9 | aploetz | 2017-06-01 17:36:01.000000+0000 | 192.168.0.101 10 | 11 | (4 rows) 12 | 13 | -------------------------------------------------------------------------------- /Chapter05/6996_05_04_04.txt: -------------------------------------------------------------------------------- 1 | aploetz@cqlsh:packt> SELECT token(user_id), user_id, login_datetime 2 | FROM logins_by_user 3 | WHERE user_id='aploetz'; 4 | 5 | system.token(user_id) | user_id | login_datetime 6 | -----------------------+---------+--------------------------------- 7 | -1472930629430174260 | aploetz | 2017-06-03 14:04:55.000000+0000 8 | -1472930629430174260 | aploetz | 2017-06-02 18:23:11.000000+0000 9 | -1472930629430174260 | aploetz | 2017-06-01 17:53:28.000000+0000 10 | -1472930629430174260 | aploetz | 2017-06-01 17:36:01.000000+0000 11 | 12 | (4 rows) 13 | 14 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_01.txt: -------------------------------------------------------------------------------- 1 | * - memlock unlimited 2 | * - nofile 100000 3 | * - nproc 32768 4 | * - as unlimited -------------------------------------------------------------------------------- /Chapter05/6996_05_06_02.txt: -------------------------------------------------------------------------------- 1 | echo "deb http://www.apache.org/dist/cassandra/debian 310x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_03.txt: -------------------------------------------------------------------------------- 1 | curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add - 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_04.txt: -------------------------------------------------------------------------------- 1 | sudo apt-get update 2 | sudo apt-get install cassandra 3 | 4 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_05.txt: -------------------------------------------------------------------------------- 1 | sudo service cassandra stop 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_06.txt: -------------------------------------------------------------------------------- 1 | sudo mkdir /local 2 | sudo chown $USER:$USER /local 3 | cd /local 4 | mv ~/Downloads/apache-cassandra-3.10-bin.tar.gz . 5 | 6 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_07.txt: -------------------------------------------------------------------------------- 1 | curl -O https://archive.apache.org/dist/cassandra/3.10/apache-cassandra-3.10-bin.tar.gz 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_08.txt: -------------------------------------------------------------------------------- 1 | tar -zxvf apache-cassandra-3.10-bin.tar.gz 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_06_09.txt: -------------------------------------------------------------------------------- 1 | mv apache-cassandra-3.10/ cassandra 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_07_01.txt: -------------------------------------------------------------------------------- 1 | +UseG1GC 2 | -Xms=20GB 3 | -Xmx=20GB 4 | G1RSetUpdatingPauseTimePercent=5 5 | InitiatingHeapOccupancyPercent=25 6 | G1HeapRegionSize=32m 7 | MaxGCPauseMillis=500 -------------------------------------------------------------------------------- /Chapter05/6996_05_07_02.txt: -------------------------------------------------------------------------------- 1 | cluster_name: “PermanentWaves” 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_07_03.txt: -------------------------------------------------------------------------------- 1 | seeds: “192.168.0.100” 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_07_04.txt: -------------------------------------------------------------------------------- 1 | listen_address: 192.168.0.100 2 | rpc_address: 192.168.0.100 -------------------------------------------------------------------------------- /Chapter05/6996_05_07_05.txt: -------------------------------------------------------------------------------- 1 | endpoint_snitch: GossipingPropertyFileSnitch 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_07_06.txt: -------------------------------------------------------------------------------- 1 | authenticator: PasswordAuthenticator 2 | authorizer: CassandraAuthorizer -------------------------------------------------------------------------------- /Chapter05/6996_05_07_07.txt: -------------------------------------------------------------------------------- 1 | dc=LakesidePark 2 | rack=r40 -------------------------------------------------------------------------------- /Chapter05/6996_05_08_01.txt: -------------------------------------------------------------------------------- 1 | bin/cassandra -p cassandra.pid 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_08_02.txt: -------------------------------------------------------------------------------- 1 | sudo service cassandra start 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_08_03.txt: -------------------------------------------------------------------------------- 1 | nodetool status 2 | 3 | Datacenter: LakesidePark 4 | =============== 5 | Status=Up/Down 6 | |/ State=Normal/Leaving/Joining/Moving 7 | -- Address Load Tokens Owns (effective) Host ID Rack 8 | UN 192.168.0.100 1.33 MiB 256 100.0% 954d394b-f96f-473f-ad23-cbe4fd0672c8 R40 -------------------------------------------------------------------------------- /Chapter05/6996_05_08_04.txt: -------------------------------------------------------------------------------- 1 | ps -ef | grep cassandra 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_08_05.txt: -------------------------------------------------------------------------------- 1 | nodetool disablegossip 2 | nodetool drain -------------------------------------------------------------------------------- /Chapter05/6996_05_08_06.txt: -------------------------------------------------------------------------------- 1 | kill cat cassandra.pid -------------------------------------------------------------------------------- /Chapter05/6996_05_08_07.txt: -------------------------------------------------------------------------------- 1 | sudo service cassandra stop -------------------------------------------------------------------------------- /Chapter05/6996_05_08_08.txt: -------------------------------------------------------------------------------- 1 | listen_address: 192.168.0.101 2 | rpc_address: 192.168.0.101 -------------------------------------------------------------------------------- /Chapter05/6996_05_08_09.txt: -------------------------------------------------------------------------------- 1 | tail -f /var/log/cassandra/system.log -------------------------------------------------------------------------------- /Chapter05/6996_05_08_10.txt: -------------------------------------------------------------------------------- 1 | seeds: "192.168.0.100" -------------------------------------------------------------------------------- /Chapter05/6996_05_08_11.txt: -------------------------------------------------------------------------------- 1 | $ nodetool status 2 | Datacenter: LakesidePark 3 | ======================== 4 | Status=Up/Down 5 | |/ State=Normal/Leaving/Joining/Moving 6 | -- Address Load Tokens Owns Host ID Rack 7 | UJ 192.168.0.101 83.99 MiB 16 100.0% fd352577-6be5-4d93-8251-15a74... r40 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_01.txt: -------------------------------------------------------------------------------- 1 | $ nodetool status 2 | Datacenter: LakesidePark 3 | ======================== 4 | Status=Up/Down 5 | |/ State=Normal/Leaving/Joining/Moving 6 | -- Address Load Tokens Owns Host ID Rack 7 | UN 192.168.0.100 84.15 MiB 16 100.0% 71700e62-2e28-4974-93e1-a2ad3f... r40 8 | UN 192.168.0.102 83.27 MiB 16 100.0% c3e61934-5fc1-4795-a05a-28443e... r40 9 | UN 192.168.0.101 83.99 MiB 16 100.0% fd352577-6be5-4d93-8251-15a74f... r40 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_02.txt: -------------------------------------------------------------------------------- 1 | $ nodetool info 2 | 3 | ID :71700e62-2e28-4974-93e1-a2ad3f8a38c1 4 | Gossip active : true 5 | Thrift active : false 6 | Native Transport active: true 7 | Load :84.15MiB 8 | Generation No : 1505483850 9 | Uptime (seconds) : 40776 10 | Heap Memory (MB) : 422.87 / 4016.00 11 | Off Heap Memory (MB) : 0.00 12 | Data Center :LakesidePark 13 | Rack :r40 14 | Exceptions : 0 15 | Key Cache : entries 24, size 2.02 KiB, capacity 100 MiB, 210 hits, 239 requests, 0.879 recent hit rate, 14400 save period in seconds 16 | Row Cache : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds 17 | Counter Cache : entries 0, size 0 bytes, capacity 50 MiB, 0 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_03.txt: -------------------------------------------------------------------------------- 1 | hits, 0 requests, NaN recent hit rate, 7200 save period in seconds 2 | Chunk Cache : entries 19, size 1.19 MiB, capacity 480 MiB, 85 misses, 343 requests, 0.752 recent hit rate, 583.139 microseconds miss latency 3 | Percent Repaired : 100.0% 4 | Token : (invoke with -T/--tokens to see all 16 tokens) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_04.txt: -------------------------------------------------------------------------------- 1 | Name: PermanentWaves 2 | Snitch: org.apache.cassandra.locator.DynamicEndpointSnitch 3 | Partitioner: org.apache.cassandra.dht.Murmur3Partitioner 4 | Schema versions: 22a8db59-e998-3848-bfee-a07feedae0d8: [192.168.0.100,192.168.0.101,192.168.0.102] -------------------------------------------------------------------------------- /Chapter05/6996_05_09_05.txt: -------------------------------------------------------------------------------- 1 | nodetool -h 192.168.0.102 decommission -------------------------------------------------------------------------------- /Chapter05/6996_05_09_06.txt: -------------------------------------------------------------------------------- 1 | Datacenter: LakesidePark 2 | ======================== 3 | Status=Up/Down 4 | |/ State=Normal/Leaving/Joining/Moving 5 | -- Address Load Tokens Owns Host ID Rack 6 | UN 192.168.0.100 84.15 MiB 16 100.0% 71700e62-2e28-4974-93e1-a2ad3f... r40 7 | UL 192.168.0.102 83.27 MiB 16 100.0% c3e61934-5fc1-4795-a05a-28443e... r40 8 | UN 192.168.0.101 83.99 MiB 16 100.0% fd352577-6be5-4d93-8251-15a74f... r40 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_07.txt: -------------------------------------------------------------------------------- 1 | Datacenter: LakesidePark 2 | ======================== 3 | Status=Up/Down 4 | |/ State=Normal/Leaving/Joining/Moving 5 | -- Address Load Tokens Owns Host ID Rack 6 | UN 192.168.0.100 84.15 MiB 16 100.0% 71700e62-2e28-4974-93e1-a2ad3f... r40 7 | DN 192.168.0.102 83.27 MiB 16 100.0% c3e61934-5fc1-4795-a05a-28443e... r40 8 | UN 192.168.0.101 83.99 MiB 16 100.0% fd352577-6be5-4d93-8251-15a74f... r40 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_08.txt: -------------------------------------------------------------------------------- 1 | nodetool removenode c3e61934-5fc1-4795-a05a-28443e2d51da -------------------------------------------------------------------------------- /Chapter05/6996_05_09_09.txt: -------------------------------------------------------------------------------- 1 | nodetool assassinate 192.168.0.102 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_10.txt: -------------------------------------------------------------------------------- 1 | cqlsh 192.168.0.100 -u cassandra -p cassandra 2 | 3 | -------------------------------------------------------------------------------- /Chapter05/6996_05_09_11.txt: -------------------------------------------------------------------------------- 1 | Connected to PermanentWaves at 192.168.0.100:9042. 2 | [cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4] 3 | Use HELP for help. 4 | cassandra@cqlsh> -------------------------------------------------------------------------------- /Chapter05/6996_05_09_12.txt: -------------------------------------------------------------------------------- 1 | cassandra@cqlsh> CREATE ROLE cassdba 2 | WITH PASSWORD='flynnLives' AND SUPERUSER=true AND LOGIN=true; 3 | cassandra@cqlsh> ALTER ROLE cassandra 4 | WITH PASSWORD='2f394084e98a4bec92405f73e2e634ea'; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_13.txt: -------------------------------------------------------------------------------- 1 | cqlsh 192.168.0.100 -u cassdba -p flynnLives 2 | Connected to PermanentWaves at 192.168.0.100:9042. 3 | [cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4] 4 | Use HELP for help. 5 | cassdba@cqlsh> -------------------------------------------------------------------------------- /Chapter05/6996_05_09_14.txt: -------------------------------------------------------------------------------- 1 | CREATE KEYSPACE packt WITH replication = { 2 | 'class':'NetworkTopologyStrategy', 'LakesidePark':'1'} 3 | AND durable_writes = true; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_15.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE packt.astronauts_by_group ( 2 | name text, year int, group int, status text, dob text, 3 | birthplace text, gender text, alma_mater text, spaceflights int, 4 | spaceflight_hours int, spacewalks int, spacewalk_hours int, 5 | missions text, 6 | PRIMARY KEY (group,name)) 7 | WITH CLUSTERING ORDER BY (name asc); -------------------------------------------------------------------------------- /Chapter05/6996_05_09_16.txt: -------------------------------------------------------------------------------- 1 | COPY packt.astronauts_by_group (name, year, group, status, dob, birthplace, 2 | gender, alma_mater, spaceflights, spaceflight_hours, spacewalks, 3 | spacewalk_hours, missions) 4 | FROM '~/Documents/Packt/astronauts.csv' WITH HEADER=true; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_17.txt: -------------------------------------------------------------------------------- 1 | cassdba@cqlsh:packt> SELECT name, alma_mater, birthplace FROM astronauts_by_group WHERE group=1; 2 | 3 | name | alma_mater | birthplace 4 | ------------------------+-----------------------------------+---------------- 5 | Alan B. Shepard Jr. | US Naval Academy | East Derry, NH 6 | Donald K. Slayton | University of Minnesota | Sparta, WI 7 | John H. Glenn Jr. | Muskingum College | Cambridge, OH 8 | L. Gordon Cooper Jr. | Air Force Institute of Technology | Shawnee, OK 9 | M. Scott Carpenter | University of Colorado | Boulder, CO 10 | Virgil I. Grissom | Purdue University | Mitchell, IN 11 | Walter M. Schirra Jr. | US Naval Academy | Hackensack, NJ 12 | 13 | (7 rows) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_18.txt: -------------------------------------------------------------------------------- 1 | cassdba@cqlsh:packt> exit 2 | -------------------------------------------------------------------------------- /Chapter05/6996_05_09_19.txt: -------------------------------------------------------------------------------- 1 | pip install cassandra-driver -------------------------------------------------------------------------------- /Chapter05/6996_05_09_20.txt: -------------------------------------------------------------------------------- 1 | from cassandra.cluster import Cluster 2 | from cassandra.auth import PlainTextAuthProvider 3 | import sys -------------------------------------------------------------------------------- /Chapter05/6996_05_09_21.txt: -------------------------------------------------------------------------------- 1 | hostname=sys.argv[1] 2 | username=sys.argv[2] 3 | password=sys.argv[3] 4 | nodes = [] 5 | nodes.append(hostname) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_22.txt: -------------------------------------------------------------------------------- 1 | auth = PlainTextAuthProvider(username=username, password=password) 2 | cluster = Cluster(nodes,auth_provider=auth) 3 | session = cluster.connect("system") -------------------------------------------------------------------------------- /Chapter05/6996_05_09_23.txt: -------------------------------------------------------------------------------- 1 | strCQL = """ SELECT cluster_name,data_center,listen_address,release_version 2 | FROM local WHERE key='local' 3 | """ -------------------------------------------------------------------------------- /Chapter05/6996_05_09_24.txt: -------------------------------------------------------------------------------- 1 | rows = session.execute(strCQL) 2 | print("Hello world from:") 3 | for row in rows: 4 | print(row[0] + " " + row[1] + " " + row[2] + " " + row[3]) 5 | 6 | #closing Cassandra connection 7 | session.shutdown() -------------------------------------------------------------------------------- /Chapter05/6996_05_09_25.txt: -------------------------------------------------------------------------------- 1 | python cassHelloWorld.py 192.168.0.100 cassdba flynnLives 2 | Hello world from: 3 | PermanentWaves 'LakesidePark' 192.168.0.100 3.10 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_26.txt: -------------------------------------------------------------------------------- 1 | from cassandra.cluster import Cluster 2 | from cassandra.auth import PlainTextAuthProvider 3 | import sys 4 | hostname = sys.argv[1] 5 | username = sys.argv[2] 6 | password = sys.argv[3] 7 | userid = sys.argv[4] 8 | nodes = [] 9 | nodes.append(hostname) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_27.txt: -------------------------------------------------------------------------------- 1 | auth = PlainTextAuthProvider(username=username, password=password) 2 | cluster = Cluster(nodes,auth_provider=auth) 3 | session = cluster.connect(keyspace) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_28.txt: -------------------------------------------------------------------------------- 1 | strINSERT = """ 2 | INSERT INTO logins_by_user (user_id,login_datetime,origin_ip) 3 | VALUES (?,dateof(now()),?) 4 | """ 5 | pINSERTStatement = session.prepare(strINSERT); 6 | session.execute(pINSERTStatement,['aploetz','192.168.0.114']) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_29.txt: -------------------------------------------------------------------------------- 1 | strSELECT = """ 2 | SELECT * FROM logins_by_user WHERE user_id=? LIMIT 3; 3 | """ 4 | pSELECTStatement = session.prepare(strSELECT); -------------------------------------------------------------------------------- /Chapter05/6996_05_09_30.txt: -------------------------------------------------------------------------------- 1 | rows = session.execute(pSELECTStatement,[userid]) 2 | print("Data for user %s:" % userid) 3 | for row in rows: 4 | #only one row in system.local 5 | print(row[0] + " " + 6 | str(row[1]) + " " + 7 | row[2]) 8 | 9 | #closing Cassandra connection 10 | session.shutdown() -------------------------------------------------------------------------------- /Chapter05/6996_05_09_31.txt: -------------------------------------------------------------------------------- 1 | python queryUser.py 192.168.0.100 cassdba flynnLives aploetz 2 | aploetz 2017-06-10 15:26:23.329000 192.168.0.114 3 | aploetz 2017-06-03 14:04:55 192.168.0.101 4 | aploetz 2017-06-02 18:23:11 192.168.0.105 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_32.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.datastax.cassandra 4 | cassandra-driver-core 5 | 3.3.0 6 | 7 | -------------------------------------------------------------------------------- /Chapter05/6996_05_09_33.txt: -------------------------------------------------------------------------------- 1 | import com.datastax.driver.core.Cluster; 2 | import com.datastax.driver.core.Session; 3 | import com.datastax.driver.core.ResultSet; 4 | 5 | public class CassandraConnection { 6 | private Cluster cluster; 7 | private Session session; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_34.txt: -------------------------------------------------------------------------------- 1 | public CassandraConnection() { 2 | } 3 | 4 | public CassandraConnection(String node, String user, String pwd) { 5 | connect(node,user,pwd); 6 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_35.txt: -------------------------------------------------------------------------------- 1 | public void connect(String node, String user, String pwd) { 2 | cluster = Cluster.builder() 3 | .addContactPoint(node) 4 | .withCredentials(user,pwd) 5 | .build(); 6 | session = cluster.connect(); 7 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_36.txt: -------------------------------------------------------------------------------- 1 | public ResultSet query(String strQuery) { 2 | return session.execute(strQuery); 3 | } 4 | 5 | public void close() { 6 | cluster.close(); 7 | } 8 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_37.txt: -------------------------------------------------------------------------------- 1 | import com.datastax.driver.core.ResultSet; 2 | import com.datastax.driver.core.Row; 3 | 4 | public class CassHelloWorld { 5 | public static void main(String[] args) { 6 | CassandraConnection conn = new CassandraConnection(); 7 | conn.connect("192.168.0.100", "cassdba", "flynnLives"); 8 | 9 | String strSELECT ="SELECT cluster_name,data_center," 10 | + "listen_address,release_version " 11 | + "FROM system.local WHERE key='local'"; 12 | 13 | ResultSet rows = conn.query(strSELECT); 14 | for (Row row : rows) { 15 | System.out.print( 16 | row.getString("cluster_name") + " " + 17 | row.getString("data_center") + " " + 18 | row.getString("release_version")); 19 | } 20 | conn.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_38.txt: -------------------------------------------------------------------------------- 1 | PermanentWaves LakesidePark 3.10 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_39.txt: -------------------------------------------------------------------------------- 1 | public ResultSet query(BoundStatement bStatement) { 2 | return session.execute(bStatement); 3 | } 4 | 5 | public void insert(BoundStatement bStatement) { 6 | session.execute(bStatement); 7 | } 8 | 9 | public Session getSession() { 10 | return session; 11 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_40.txt: -------------------------------------------------------------------------------- 1 | import com.datastax.driver.core.BoundStatement; 2 | import com.datastax.driver.core.PreparedStatement; 3 | import com.datastax.driver.core.ResultSet; 4 | import com.datastax.driver.core.Row; 5 | import com.datastax.driver.core.Session; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_41.txt: -------------------------------------------------------------------------------- 1 | public static void main(String[] args) { 2 | CassandraConnection conn = new CassandraConnection(); 3 | conn.connect("192.168.0.100", "cassdba", "flynnLives"); 4 | Session session = conn.getSession(); -------------------------------------------------------------------------------- /Chapter05/6996_05_09_42.txt: -------------------------------------------------------------------------------- 1 | String userID = System.getProperty("user.name"); -------------------------------------------------------------------------------- /Chapter05/6996_05_09_43.txt: -------------------------------------------------------------------------------- 1 | String strINSERT = "INSERT INTO packt.logins_by_user " 2 | + "(user_id,login_datetime,origin_ip) " 3 | + "VALUES (?,dateof(now()),?)"; 4 | PreparedStatement pIStatement = session.prepare(strINSERT); 5 | BoundStatement bIStatement = new BoundStatement(pIStatement); 6 | bIStatement.bind(userID, "192.168.0.119"); 7 | conn.insert(bIStatement); -------------------------------------------------------------------------------- /Chapter05/6996_05_09_44.txt: -------------------------------------------------------------------------------- 1 | String strSELECT = "SELECT * " 2 | + "FROM packt.logins_by_user WHERE user_id=? " 3 | + "LIMIT 3"; 4 | PreparedStatement pSStatement = session.prepare(strSELECT); 5 | BoundStatement bSStatement = new BoundStatement(pSStatement); 6 | bSStatement.bind(userID); 7 | 8 | ResultSet rows = conn.query(bSStatement); 9 | for (Row row : rows) { 10 | System.out.println(row.getString("user_id") + " " + 11 | row.getTimestamp("login_datetime") + " " + 12 | row.getString("origin_ip")); 13 | } 14 | conn.close(); 15 | } -------------------------------------------------------------------------------- /Chapter05/6996_05_09_45.txt: -------------------------------------------------------------------------------- 1 | aploetz Sun Jun 11 08:49:58 CDT 2017 192.168.0.119 2 | aploetz Sat Jun 10 15:26:23 CDT 2017 192.168.0.114 3 | aploetz Sat Jun 03 14:04:55 CDT 2017 192.168.0.101 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_46.txt: -------------------------------------------------------------------------------- 1 | incremental_backups: true -------------------------------------------------------------------------------- /Chapter05/6996_05_09_47.txt: -------------------------------------------------------------------------------- 1 | nodetool snapshot packt.logins_by_user 2 | Requested creating snapshot(s) for [packt.logins_by_user] with snapshot name [1504986577085] and options {skipFlush=false} 3 | Snapshot directory: 1504986577085 -------------------------------------------------------------------------------- /Chapter05/6996_05_09_48.txt: -------------------------------------------------------------------------------- 1 | cassdba@cqlsh> use packt ; 2 | cassdba@cqlsh:packt> SELECT * FROM logins_by_user WHERE user_id='avery' LIMIT 1; 3 | 4 | user_id | login_datetime | origin_ip 5 | ---------+---------------------------------+----------- 6 | avery | 1970-01-01 19:48:33.945000+0000 | 10.0.15.2 7 | 8 | (1 rows) -------------------------------------------------------------------------------- /Chapter05/6996_05_09_49.txt: -------------------------------------------------------------------------------- 1 | cassdba@cqlsh:packt> truncate table packt.logins_by_user; -------------------------------------------------------------------------------- /Chapter05/6996_05_09_50.txt: -------------------------------------------------------------------------------- 1 | cd /var/lib/cassandra/data/packt 2 | ls -al 3 | total 20 4 | drwxrwxr-x 5 aploetz aploetz 4096 Jul 18 09:23 . 5 | drwxr-xr-x 18 aploetz aploetz 4096 Jun 10 09:06 .. 6 | drwxrwxr-x 3 aploetz aploetz 4096 Jul 18 14:05 astronauts-b27b5a406bc411e7b609c123c0f29bf4 7 | drwxrwxr-x 3 aploetz aploetz 4096 Jul 18 14:05 astronauts_by_group-b2c163f06bc411e7b609c123c0f29bf4 8 | drwxrwxr-x 4 aploetz aploetz 4096 Sep 9 14:51 logins_by_user-fdd9fa204de511e7a2e6f3d179351473 9 | -------------------------------------------------------------------------------- /Chapter05/6996_05_09_51.txt: -------------------------------------------------------------------------------- 1 | cd logins_by_user-fdd9fa204de511e7a2e6f3d179351473/snapshots 2 | ls -al 3 | total 16 4 | drwxrwxr-x 4 aploetz aploetz 4096 Sep 9 14:58 . 5 | drwxrwxr-x 4 aploetz aploetz 4096 Sep 9 14:58 .. 6 | drwxrwxr-x 2 aploetz aploetz 4096 Sep 9 14:55 1504986577085 7 | drwxrwxr-x 2 aploetz aploetz 4096 Sep 9 14:58 truncated-1504987099599-logins_by_user -------------------------------------------------------------------------------- /Chapter05/6996_05_09_52.txt: -------------------------------------------------------------------------------- 1 | ls -al 2 | total 52 3 | drwxrwxr-x 2 aploetz aploetz 4096 Sep 9 14:49 . 4 | drwxrwxr-x 3 aploetz aploetz 4096 Sep 9 14:49 .. 5 | -rw-rw-r-- 1 aploetz aploetz 31 Sep 9 14:49 manifest.json 6 | -rw-rw-r-- 2 aploetz aploetz 43 Jun 10 10:53 mc-1-big-CompressionInfo.db 7 | -rw-rw-r-- 2 aploetz aploetz 264 Jun 10 10:53 mc-1-big-Data.db 8 | -rw-rw-r-- 2 aploetz aploetz 9 Jun 10 10:53 mc-1-big-Digest.crc32 9 | -rw-rw-r-- 2 aploetz aploetz 16 Jun 10 10:53 mc-1-big-Filter.db 10 | -rw-rw-r-- 2 aploetz aploetz 11 Jun 10 10:53 mc-1-big-Index.db 11 | -rw-rw-r-- 2 aploetz aploetz 4722 Jun 10 10:53 mc-1-big-Statistics.db 12 | -rw-rw-r-- 2 aploetz aploetz 65 Jun 10 10:53 mc-1-big-Summary.db 13 | -rw-rw-r-- 2 aploetz aploetz 92 Jun 10 10:53 mc-1-big-TOC.txt 14 | -rw-rw-r-- 1 aploetz aploetz 947 Sep 9 14:49 schema.cql -------------------------------------------------------------------------------- /Chapter05/6996_05_09_53.txt: -------------------------------------------------------------------------------- 1 | cp * ../../ -------------------------------------------------------------------------------- /Chapter05/6996_05_09_54.txt: -------------------------------------------------------------------------------- 1 | cassdba@cqlsh> use packt ; 2 | cassdba@cqlsh:packt> SELECT * FROM logins_by_user WHERE user_id='avery' LIMIT 1; 3 | 4 | user_id | login_datetime | origin_ip 5 | ---------+---------------------------------+----------- 6 | avery | 2017-09-09 19:48:33.945000+0000 | 10.0.15.2 7 | 8 | (1 rows) -------------------------------------------------------------------------------- /Chapter06/README.txt: -------------------------------------------------------------------------------- 1 | This chapter doesnot contain any code files -------------------------------------------------------------------------------- /Chapter07/local-query-request: -------------------------------------------------------------------------------- 1 | // list tables 2 | var params = { 3 | Limit: 100, 4 | }; 5 | dynamodb.listTables(params, function(err, data) { 6 | if (err) ppJson(err); 7 | else ppJson(data); 8 | }); 9 | 10 | 11 | var params = { 12 | TableName: 'person', 13 | KeySchema: [ 14 | { 15 | AttributeName: 'PersonID', 16 | KeyType: 'HASH' 17 | }, 18 | ], 19 | AttributeDefinitions: [ 20 | { 21 | AttributeName: 'PersonID', 22 | AttributeType: 'N', 23 | } 24 | ], 25 | ProvisionedThroughput: { 26 | ReadCapacityUnits: 10, 27 | WriteCapacityUnits: 10, 28 | }, 29 | }; 30 | dynamodb.createTable(params, function(err, data) { 31 | if (err) ppJson(err); 32 | else ppJson(data); 33 | }); 34 | 35 | // put item 36 | var params = { 37 | TableName: 'person', 38 | Item: { 39 | PersonID: 101, 40 | FirstName : "John", 41 | LastName : "Smith", 42 | Age : 27, 43 | Email : "john.smith@co.in" 44 | } 45 | }; 46 | docClient.put(params, function(err, data) { 47 | if (err) ppJson(err); 48 | else ppJson(data); 49 | }); 50 | 51 | // get item 52 | 53 | var params = { 54 | TableName: 'person', 55 | Key: { 56 | PersonID: 101 57 | }, 58 | }; 59 | docClient.get(params, function(err, data) { 60 | if (err) ppJson(err); 61 | else ppJson(data); 62 | }); 63 | 64 | // scan 65 | var params = { 66 | TableName: 'person', 67 | Select: 'ALL_ATTRIBUTES' 68 | }; 69 | dynamodb.scan(params, function(err, data) { 70 | if (err) ppJson(err); 71 | else ppJson(data); 72 | }); 73 | 74 | // update 75 | 76 | var params = { 77 | TableName: 'person', 78 | Key: { 79 | PersonID: 101, 80 | }, 81 | UpdateExpression: 'SET Age= :age', 82 | ExpressionAttributeValues:{ 83 | ":age":32, 84 | }, 85 | }; 86 | docClient.update(params, function(err, data) { 87 | if (err) ppJson(err); 88 | else ppJson(data); 89 | }); 90 | 91 | // delete 92 | var params = { 93 | TableName: 'person', 94 | Key: { 95 | PersonID: 101, 96 | }, 97 | }; 98 | docClient.delete(params, function(err, data) { 99 | if (err) ppJson(err); 100 | else ppJson(data); 101 | }); 102 | -------------------------------------------------------------------------------- /Chapter08/data/cpu_alert.tick: -------------------------------------------------------------------------------- 1 | stream 2 | |from() 3 | .measurement('cpu') 4 | |alert() 5 | .crit(lambda: "usage_idle" < 100) 6 | .log('/home/bwu/examples/alerts.log') 7 | -------------------------------------------------------------------------------- /Chapter08/goclientInfluxDBtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | "github.com/influxdata/influxdb/client/v2" 7 | ) 8 | 9 | const ( 10 | database = "testdb" 11 | username = "root" 12 | password = "root" 13 | ) 14 | 15 | func main() { 16 | c, err := client.NewHTTPClient(client.HTTPConfig{ 17 | Addr: "http://localhost:8086", 18 | Username: username, 19 | Password: password, 20 | }) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | 25 | // Create a new point batch 26 | bp, err := client.NewBatchPoints(client.BatchPointsConfig{ 27 | Database: database, 28 | Precision: "s", 29 | }) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | // Create a point and add to batch 34 | tags := map[string]string{} 35 | fields1 := map[string]interface{}{ 36 | "http": "GET /cgi-bin/try/ HTTP/1.0", 37 | "status": 200, 38 | "duration": 3395, 39 | "ip": "192.168.2.20", 40 | } 41 | 42 | pt1, err := client.NewPoint("apachelog_go", tags, fields1, time.Unix(0, 1511361120000000000)) 43 | if err != nil { 44 | log.Fatal(err) 45 | } 46 | bp.AddPoint(pt1) 47 | fields2 := map[string]interface{}{ 48 | "http": "GET / HTTP/1.0", 49 | "status": 200, 50 | "duration": 2216, 51 | "ip": "127.0.0.1", 52 | } 53 | pt2, err := client.NewPoint("apachelog_go", tags, fields2, time.Unix(0, 1511361180000000000)) 54 | bp.AddPoint(pt2) 55 | // Write the batch 56 | if err := c.Write(bp); err != nil { 57 | log.Fatal(err) 58 | } 59 | } -------------------------------------------------------------------------------- /Chapter08/influxdb-test/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.test 5 | influxdb-test 6 | 0.0.1-SNAPSHOT 7 | influxdb-test 8 | 9 | 10 | org.influxdb 11 | influxdb-java 12 | 2.7 13 | 14 | 15 | com.squareup.okhttp3 16 | okhttp 17 | 3.9.1 18 | 19 | 20 | com.squareup.retrofit2 21 | retrofit 22 | 2.3.0 23 | 24 | 25 | com.squareup.retrofit2 26 | converter-moshi 27 | 2.3.0 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-compiler-plugin 35 | 2.3.2 36 | 37 | 1.8 38 | 1.8 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Chapter08/influxdb-test/src/main/java/com/sample/influxdb/InfluxDBApiTest.java: -------------------------------------------------------------------------------- 1 | package com.sample.influxdb; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.influxdb.InfluxDB; 6 | import org.influxdb.InfluxDBFactory; 7 | import org.influxdb.dto.Point; 8 | import org.influxdb.dto.Query; 9 | 10 | public class InfluxDBApiTest { 11 | 12 | public static void main(String[] args) throws Exception { 13 | InfluxDB influxDB = InfluxDBFactory.connect("http://192.168.1.173:8086", "root", "root"); 14 | String dbName = "testdb"; 15 | influxDB.createDatabase(dbName); 16 | influxDB.setDatabase(dbName); 17 | Point point1 = Point.measurement("apachelog_java").time(1511361120000000000L, TimeUnit.NANOSECONDS) 18 | .addField("http", "GET /cgi-bin/try/ HTTP/1.0").addField("status", 200).addField("duration", 3395) 19 | .addField("ip", "192.168.2.20").build(); 20 | Point point2 = Point.measurement("apachelog_java").time(1511361180000000000L, TimeUnit.NANOSECONDS) 21 | .addField("http", "GET / HTTP/1.0").addField("status", 200).addField("duration", 2216) 22 | .addField("ip", "127.0.0.1").build(); 23 | influxDB.write(point1); 24 | influxDB.write(point2); 25 | Query query = new Query("SELECT * FROM apachelog_java", dbName); 26 | influxDB.query(query, 20, queryResult -> System.out.println(queryResult)); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Seven-NoSQL-Databases-in-a-Week 5 | This is the code repository for [Seven NoSQL Databases in a Week](https://www.packtpub.com/big-data-and-business-intelligence/seven-nosql-databases-week), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish. 6 | ## About the Book 7 | This is the golden age of open source NoSQL databases. With enterprises having to work with large amounts of unstructured data and moving away from expensive monolithic architecture, the adoption of NoSQL databases is rapidly increasing. Being familiar with the popular NoSQL databases and knowing how to use them is a must for budding DBAs and developers. 8 | 9 | This book introduces you to the different types of NoSQL databases and gets you started with seven of the most popular NoSQL databases used by enterprises today. We start off with a brief overview of what NoSQL databases are, followed by an explanation of why and when to use them. The book then covers the seven most popular databases in each of these categories: MongoDB, Amazon DynamoDB, Redis, HBase, Cassandra, InfluxDB, and Neo4j. The book doesn't go into too much detail about each database but teaches you enough to get started with them. 10 | 11 | By the end of this book, you will have a thorough understanding of the different NoSQL databases and their functionalities, empowering you to select and use the right database according to your needs. 12 | ## Instructions and Navigation 13 | All of the code is organized into folders according to the chapter number. For example, Chapter07. 14 | 15 | 16 | 17 | The code will look like the following: 18 | 19 | var params = { 20 | 21 | TableName: 'person', 22 | 23 | Item: { 24 | 25 | PersonID: 101, 26 | 27 | FirstName : "John", 28 | 29 | LastName : "Smith", 30 | 31 | Age : 27, 32 | 33 | Email : "john.smith@co.in" 34 | 35 | } 36 | 37 | }; 38 | 39 | 40 | ## Related Products 41 | * [Mastering MongoDB 3.x](https://www.packtpub.com/big-data-and-business-intelligence/mastering-mongodb-3x) 42 | 43 | * [Redis 4.x Cookbook](https://www.packtpub.com/big-data-and-business-intelligence/redis-4x-cookbook) 44 | 45 | * [Learning Neo4j 3.x - Second Edition](https://www.packtpub.com/big-data-and-business-intelligence/learning-neo4j-3x-second-edition) 46 | 47 | ### Download a free PDF 48 | 49 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
50 |

https://packt.link/free-ebook/9781787288867

--------------------------------------------------------------------------------