Node Patterns - Databases: Volume I - LevelDB, Redis and ...

 Database Patterns

Pedro Teixeira

This book is for sale at This version was published on 2015-02-11

* * * * * This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. * * * * * ? 2015 Pedro Teixeira

Table of Contents

1. The source code

2. Introduction

3. An embedded database using LevelDB

3.1 Installing LevelDB 3.2 Using LevelDB 3.3 Encodings 3.4 Using JSON for encoding values 3.5 Batch operations 3.6 Using a readable stream

3.6.1 Using ranges 3.6.2 Limiting the number of results 3.6.3 A consistent snapshot 3.6.4 Using ranges to partition the data

3.7 Using level-sublevel

3.7.1 Batch in different sublevels

3.8 Hooks

4. Redis

4.1 Redis primitives

4.1.1 Strings 4.1.2 Key expiration 4.1.3 Transactions 4.1.4 Command results in Multi 4.1.5 Optimistic locking using WATCH 4.1.6 Transactions using Lua scripts

4.1.6.1 Caching Lua scripts 4.1.6.2 Performance 4.1.7 Integers 4.1.8 Using counters 4.1.9 Dictionaries 4.1.10 Redis dictionary counters 4.1.11 Lists 4.1.11.1 Avoid polling 4.1.11.2 Not losing work 4.1.12 Sets 4.1.12.1 Intersecting sets 4.1.13 Sorted Sets 4.1.14 Pub-sub 4.1.15 Distributed Emitter 4.1.15.1 Beware of race conditions

5. CouchDB

5.1 Starting off 5.2 Ladies and Gentlemen, start your Nodes 5.3 Overriding the HTTP agent socket pool 5.4 The directory structure

5.5 Creating documents with a specific ID 5.6 Forcing a schema 5.7 Unifying errors

5.7.1 How to consume Boom errors

5.8 Updating specific fields while handling conflicts

5.8.1 Delegate conflicts entirely to the client. 5.8.2 Diff doc with last write wins. 5.8.3 Disallowing changes to specific fields

5.9 Views

5.9.1 Inverted indexes 5.9.1.1 Query

5.9.2 Multi-value inverted indexes 5.9.3 Paginating results

5.9.3.1 The wrong way of doing pagination 5.9.3.2 A better way of paginating 5.9.4 Reducing

5.10 Using the Changes Feed

5.10.1 Minimising the chance of repeated jobs 5.10.2 Recording the sequence 5.10.3 Scaling: how to support more than one job in parallel 5.10.4 Balancing work: how to use more than one worker process

1. The source code

You can find the source code for the entire series of books at the following URL: You can browse the code for this particular book here: You are free to download it, try it and tinker with it. If you have any issue with the code, please submit an issue on Github. Also, pull requests with fixes or recommendations are welcome!

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download