Rethinkdb build and use

First of all, surprise rethinkdb open source, praise for the spirit of open source (no matter what the reason behind) … In this case, let’s introduce the black technology of Nosql world - rethinkdb. I met rethibkdb in the summer of the 16th, because of the needs of a project, at the time between mongodb and rethinkdb, but eventually chose rethinkdb, the good and the bad between the two, no matter, I just use a little fur, here Combine your own use with the official introduction to make a simple record.
Rethinkdb belongs to Nosql database, it has the advantages of visual management and support for multiple platforms. If we need real-time data, it is the most suitable. Of course, in the process of using, I also found a little flaw in it, does not support multi-threaded storage (probably because I did not use it well, time is tight, and I have not had time to solve it. If there is a solution, I hope to inform one. two).
For details, please refer to: [https://rethinkdb.com/faq/] (https://rethinkdb.com/faq/)

Rethinkdb is divided into server and client, server is also built rethinkdb database for storage and service; clinet is used to connect to the operation of database content, support a variety of programming languages.

Server-side installation and use

Server installation support platform: linux, windows, mac

ubuntu installation

Install directly using apt-get:

1
2
3
4
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- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install rethinkdb

Run the rethinkdb service:

1
2
3
4
5
6
$ rethinkdb
info: Creating directory /home/user/rethinkdb_data
info: Listening for intracluster connections on port 29015
info: Listening for client driver connections on port 28015
info: Listening for administrative HTTP connections on port 8080
info: Server ready

For other installation methods, please refer to: [https://rethinkdb.com/docs/install/ubuntu/] (https://rethinkdb.com/docs/install/ubuntu/)

windows installation

Download the installation package:
https://download.rethinkdb.com/windows/rethinkdb-2.3.5.zip
Run the rethinkdb program:

1
2
3
C:\Users\Slava\>cd RethinkDB
C:\Users\Slava\RethinkDB\>
C:\Users\Slava\RethinkDB\>rethinkdb.exe

Note: After running the rethinkdb database, port 8080 is enabled by default. The web page displayed by localhost:8080 is used to manage the database. By default, port 29015 is opened to connect to the client to exchange data.
Web management page:

Client installation and use

The client side supports programming languages: javascript, ruby, python, java, here python example.

python

Install
1
sudo pip install rethinkdb
Usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import rethinkdb as r
class dbOperation():
def __init__(self,dbname,tablename):
self.conn = r.connect(host="localhost",port=29015)
self.table = r.db(dbname).table(tablename)
def Insert(self,document):
'''
Insert records into the database
'''
return self.table.insert(document, conflict="update").run(self.conn)
def query(self,**kwargs):
'''
Custom query
'''
f=self.table.run(self.conn) ##Select a record with a website name that is empty.
content=[]
for i in f:
content.append(i)
return content

For details, please refer to: [https://rethinkdb.com/docs/cookbook/python/] (https://rethinkdb.com/docs/cookbook/python/)

Data Explorer Tools

This is a tool that comes with rethinkdb. It can be used to execute database statements and query the contents of the database.

Common statements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
r.db("").table("").count()
r.db("").table("").filter({"":""})
r.table('movies').filter({rank: 1})
Eq is equal
Ne neq does not equal
gt >
lt <
the <=
ge> =
Not non
Mod model
R.table('movies').without('id').distinct().count() Remove duplicates
R.table('moviesUnique').orderBy('rank').limit(10) shows the top ten movies
r.table('moviesUnique').orderBy(r.desc('rank')).limit(10)
R.db("ALJC").table("MALINK_0301").withFields("Date") shows only the Date field
R.db("IP").table("Domain_Location").without("Date") Remove the Date field
R.db("IP").table("Domain_Location").hasFields('city') Display the record with the city field
R.db("IP").table("Domain_Location").filter(function(user){return user.hasFields("city").not()}) Displaying records where the city field does not exist

For details, please refer to: [https://rethinkdb.com/docs/reql-data-exploration/] (https://rethinkdb.com/docs/reql-data-exploration/)

本文标题:Rethinkdb build and use

文章作者:nmask

发布时间:2017年02月07日 - 15:02

最后更新:2019年07月11日 - 15:07

原始链接:https://thief.one/2017/02/07/Rethinkdb build and use/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

nmask wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!

热门文章推荐: