Skip to content

Instantly share code, notes, and snippets.

View haimrait's full-sized avatar

Haim Raitsev haimrait

View GitHub Profile
import { combineReducers } from 'redux';
export const reducers = combineReducers({
dummy: () => 'dummy reducer',
});
import React from 'react';
export class App extends React.Component {
render() {
return <div>Hello World</div>;
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { App } from './components/App';
import { reducers } from './reducers';
const store = createStore(reducers, applyMiddleware(thunk));
@haimrait
haimrait / bookRoutes.js
Created December 5, 2019 18:09
node-redis-mongo - final book routes
const mongoose = require("mongoose");
const { clearKey } = require("../services/cache");
const Book = mongoose.model("Book");
module.exports = app => {
app.get("/api/books", async (req, res) => {
let books;
if (req.query.author) {
books = await Book.find({ author: req.query.author }).cache();
} else {
@haimrait
haimrait / cache.js
Last active January 10, 2023 15:49
node-redis-mongo - final cache
const mongoose = require("mongoose");
const redis = require("redis");
const util = require("util");
const keys = require("../config/keys");
const client = redis.createClient({
host: keys.redisHost,
port: keys.redisPort,
retry_strategy: () => 1000
});
@haimrait
haimrait / cache.js
Last active January 4, 2020 16:12
node-redis-mongo - A first cahce file implementation with hook for every query
const mongoose = require("mongoose");
const redis = require("redis");
const util = require("util");
const keys = require("../config/keys");
const client = redis.createClient({
host: keys.redisHost,
port: keys.redisPort,
retry_strategy: () => 1000
});
@haimrait
haimrait / cache.js
Last active January 4, 2020 16:11
node-redis-mongo - Connection between our application to redis client
const mongoose = require("mongoose");
const redis = require("redis");
const keys = require("../config/keys");
const client = redis.createClient({
host: keys.redisHost,
port: keys.redisPort,
retry_strategy: () => 1000
});
@haimrait
haimrait / Book.js
Created December 4, 2019 09:29
node-redis-mongo - Moongose model that represents a book.
const mongoose = require("mongoose");
const { Schema } = mongoose;
const bookSchema = new Schema({
title: String,
content: String,
createdAt: { type: Date, default: Date.now },
author: String
});
@haimrait
haimrait / bookRoutesBeforeCache.js
Last active December 6, 2019 09:38
node-redis-mongo - book routes version before cache layer added.
const mongoose = require("mongoose");
const Book = mongoose.model("Book");
module.exports = app => {
app.get("/api/books", async (req, res) => {
let books;
if (req.query.author) {
books = await Book.find({ author: req.query.author })
} else {
books = await Book.find()