Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RethinkDB Introduction
Search
Asad Dhamani
November 06, 2015
Technology
75
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RethinkDB Introduction
Asad Dhamani
November 06, 2015
Other Decks in Technology
See All in Technology
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
110
DGX Spark でどこまでハッキングができるのか?
kash1064
3
1.3k
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
200
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
300
Local CI × GitHub Actions
gogutan
2
220
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
1
190
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
970
How to Design Configuration for Rails Applications
willnet
1
820
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
340
パッチ更新でterraform initが落ちた日
grimoh
1
140
Browser Spec: Testing Hotwire with Ruby
takahashim
1
130
ウォンテッドリーの最近のプロダクトと技術の紹介
stomk
0
110
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
A Modern Web Designer's Workflow
chriscoyier
699
190k
Marketing to machines
jonoalderson
1
5.9k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Site-Speed That Sticks
csswizardry
13
1.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Between Models and Reality
mayunak
4
500
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Ruling the World: When Life Gets Gamed
codingconduct
0
400
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Transcript
The open-source database for the realtime web www.rethinkdb.org
What Is It • Document Database (JSON/Binary) • Realtime •
Relational features • Easily scalable • Durable
The Facts • Initial Release: July 2009 • Current Version:
2.1 • Used widely in production • Open Source
Who’s using it • Jiva Software & Mediafly - reactive
web and mobile apps • pristine.io and Narrative Clip - cloud infrastructure for connected devices • Platzi and workshape.io - realtime analytics • CMUNE and NodeCraft - multiplayer games
Installation brew update && brew install rethinkdb Mac: Linux(Ubuntu): source
/etc/lsb-release echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/ apt/sources.list.d/rethinkdb.list wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - sudo apt-get update sudo apt-get install rethinkdb Windows: :(
Set Up $ rethinkdb
Web UI
Clustering rethinkdb rethinkdb -j localhost:29015 -d rethinkdb_data2 --port-offset 1 rethinkdb
-j localhost:29015 -d rethinkdb_data3 --port-offset 2
None
None
None
Shard 3 Shard 2 Shard 1 Database
None
None
ReQL • Embeds into your programming language • Chainable queries
• Queries execute on the server
Embeds into your language 1 import rethinkdb as r 2
r.connect(host='localhost', db='test').repl() 3 r.table('messages').limit(1).run() 1 require "rethinkdb" 2 include RethinkDB::Shortcuts 3 r.connect(host: 'localhost', database: 'test').repl() 4 r.table('messages').limit(1).run() 1 r = require('rethinkdb'); 2 var connection = null; 3 r.connect( {host: 'localhost', database: 'test'}, function(err, conn) { 4 connection = conn; 5 }) 6 r.table('messages').limit(1).run(connection, function(err, result) { 7 })
Chainable queries 1 r.table('messages').run() 2 3 r.table('messages').pluck('text').distinct().run() 4 5 r.table('messages').pluck('text').distinct().count().run()
Server-side execution 1 query = r.table('messages').pluck('text').distinct().count() 2 query.run()
Code demo
Stack • Database: RethinkDB • Backend: Flask(Python) • Frontend: AngularJS
• Communication: socket.io
1 git clone https://github.com/nagpurtechies/rethinkdb-intro.git 2 git checkout base 3 git
checkout -b develop
1 import eventlet; eventlet.monkey_patch() 2 import rethinkdb as r 3
from flask import Flask, jsonify 4 import threading 5 from flask_socketio import SocketIO 6 7 8 app = Flask(__name__) 9 app.config['SECRET_KEY'] = 'secret!' 10socketio = SocketIO(app) 11conn = r.connect(host='localhost', 12 port=28015, 13 db='chatrethink') main.py
1 def watch_db(): 2 conn = r.connect(host='localhost', 3 port=28015, 4
db='chatrethink') 5 for x in r.table('messages').changes().run(conn): 6 data = {'text': x['new_val']['text'], 'username': x['new_val']['by']} 7 socketio.emit('broadcast event', data, namespace='/broadcast') 8 thread = threading.Thread(target=watch_db) 9 thread.daemon = True 10thread.start()
1 @app.route("/") 2 def hello(): 3 return app.send_static_file('index.html') 4 5
6 @app.route('/_get_messages') 7 def get_messages(): 8 conn = r.connect(host='localhost', 9 port=28015, 10 db='chatrethink') 11 messages = r.table('messages').order_by(r.desc('added')).limit(25).run(conn) 12 messages = [{'text': message['text'], 'username': message['by']} for message in reversed(list(messages))] 13 return jsonify({'messages': messages})
1 @socketio.on('new message', namespace='/broadcast') 2 def handle_json(json): 3 data =
{'text': json['text'], 'added': r.now(), 'by': json['username']} 4 r.table('messages').insert(data).run(conn) 5 6 7 if __name__ == "__main__": 8 socketio.run(app, debug=True)
1 <body ng-app="myApp"> 2 <link rel="stylesheet" href="/static/lib/foundation/css/foundation.css"> 3 <link rel="stylesheet"
href="/static/css/styles.css"> 4 <script src="/static/lib/jquery/dist/jquery.js"></script> 5 <script type="text/javascript" src="/static/lib/socket.io-client/socket.io.js"></script> 6 <div class="grid" ng-controller="ChatController"> 7 <div class="row"> 8 <div class="small-6 columns"> 9 <div ng-repeat="message in messages"> 10 <span style="color: red;">{{message.username}}: </span>{{ message.text }} 11 </div> 12 </div> 13 </div> 14 <form ng-submit="newMessage()" ng-if="username !== undefined"> 15 <div class="row"> 16 <div class="small-6 columns"> 17 <input type="text" ng-model="message.text"> 18 </div> 19 <button class="button small">Send</button> 20 </div> 21 </form> /static/index.html
1 </form> 2 <form ng-submit="setUsername()" ng-if="username === undefined"> 3 <div
class="row"> 4 <div class="small-6 columns"> 5 <input type="text" ng-model="user.name"> 6 </div> 7 <button class="button small">Set Username</button> 8 </div> 9 </form> 10</div> 11<script type="text/javascript" src="/static/lib/angularjs/angular.js"></script> 12<script type="text/javascript" src="/static/lib/angular-socket-io/socket.js"></ script> 13<script type="text/javascript" src="/static/lib/angular-cookies/angular- cookies.js"></script> 14<script type="text/javascript" src="/static/app.js"></script> 15</body>
1 var app = angular.module('myApp', [ 2 'btford.socket-io', 3 'ngCookies'
4 ]); 5 6 app.factory('socket', function (socketFactory) { 7 var myIoSocket = io.connect('http://' + document.domain + ':' + location.port + '/broadcast'); 8 socket = socketFactory({ 9 ioSocket: myIoSocket 10 }); 11 return socket; 12}); /static/app.js
1 app.controller('ChatController', ['$scope', '$http', 'socket', '$cookies', function ($scope, $http, socket,
$cookies) { 2 $scope.messages = []; 3 $scope.user = {name: ""}; 4 $scope.username = $cookies.get('rechat_username'); 5 socket.on('connect', function() { 6 $http({ 7 method: 'GET', 8 url: '/_get_messages' 9 }).then(function success(response) { 10 $scope.messages = response.data.messages; 11 }, function error(response) { 12 13 }); 14 socket.emit('my event', {data: 'I\'m connected!'}); 15 }); 16 $scope.message = {text: ""}; 17 18 $scope.newMessage = function () { 19 socket.emit('new message', {text: $scope.message.text, username: $scope.username}); 20 var messageObj = {text: $scope.message.text}; 21 $scope.message.text = ""; 22 }; 23 24 $scope.setUsername = function () { 25 $scope.username = $scope.user.name; 26 $cookies.put('rechat_username', $scope.username); 27 }; 28 29 socket.on('broadcast event', function(msg) { 30 msg = {text: msg.text, username: msg.username}; 31 if ($scope.messages.length >= 25) { 32 $scope.messages.shift(); 33 } 34 $scope.messages.push(msg); 35 }); 36 }]);
None
Where it excels • Collaborative web and mobile apps •
Streaming analytics apps • Multiplayer games • Realtime marketplaces • Connected devices
Geospatial queries • Distance • Nearest points • Long/Lat