This will guide you through setting up a replica set in a docker environment using.
- Docker Compose
- MongoDB Replica Sets
- Mongoose
- Mongoose Transactions
Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!
// This was basically ripped straight from http://en.wikipedia.org/wiki/Multiply-with-carry, just javscriptified. | |
var CMWCRand = function(seed) { | |
var i, PHI = 0x9e3779b9; | |
if(!seed) { seed = Date.now(); } | |
var Q = this.Q = new Uint32Array(4096); | |
this.c = 362436; | |
this.i = 4095; | |
Q[0] = seed; |
This will guide you through setting up a replica set in a docker environment using.
Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!
/* | |
this needs replicaSet to work | |
*/ | |
const mongoose = require('mongoose'); | |
async function runTransaction(transactionFunction, ...args) { | |
let session = null; | |
try { | |
session = await mongoose.startSession(); |
const cache = new Map(); | |
/// | |
function memo() { | |
let deleteAfterUse = true; // enable cache deletion after use by default | |
let maxKeys = 32; | |
const memoFunc = function (value=null) { | |
const size = cache.size; | |
if (value) { |
//dont know if this is correct, but leme try, feedback appreciated | |
//blocking: | |
let run = true | |
let count = 0; | |
while(run){ | |
++count; | |
let n = Math.random(); | |
if(n <= 0.01){ | |
run = false; |
PGBouncer is a lightweight connection pooler for PostgreSQL. CockroachDB is a cloud-native SQL database for building global, scalable cloud services that survive disasters.
CockroachDB is PostgreSQL wire compatible database, which means it aims to have tight compatibility with the PG ecosystem. Today, we're going to wire PGBouncer to work with CockroachDB. This article is meant to scratch the surface of possibilities unblocked by PGBouncer with CockroachDB and not meant to be an in-depth overview. We're currently researching this topic and will follow up with official docs on proper architecture and sizing of PGBouncer and CockroachDB.
var GEOLOCATION_ALLOW = true; | |
(() => { | |
try { | |
//geolocate: enable - true, disable - false | |
//get this setting from db | |
const geolocate = localStorage.getItem('geolocate'); | |
if (geolocate !== null) { | |
GEOLOCATION_ALLOW = Boolean(geolocate); | |
} |
'use strict'; | |
const { createClient } = require('redis'); | |
const options = { | |
host: '127.0.0.1', | |
port: 6379, | |
db: 0, | |
enable_offline_queue: false, | |
socket_keepalive: true, |
'use strict'; | |
const crypto = require('crypto'); | |
class RNG { | |
// Define a static method for generating a random float value in the range of 0 to 1 | |
static random() { | |
try { | |
// Use the crypto module's randomBytes method to generate 4 random bytes | |
const randomBytes = crypto.randomBytes(4); |
var crypto = require('crypto') | |
, rrange = 4294967296; | |
/** | |
* Return an integer, pseudo-random number in the range [0, 2^32). | |
*/ | |
var nextInt = function() { | |
return crypto.randomBytes(4).readUInt32BE(0); | |
}; |