Skip to content

Instantly share code, notes, and snippets.

Avatar

Haim Raitsev haimrait

  • Epsagon
  • Israel, Tel Aviv
View GitHub Profile
View index.ts
import { combineReducers } from 'redux';
export const reducers = combineReducers({
dummy: () => 'dummy reducer',
});
View App.tsx
import React from 'react';
export class App extends React.Component {
render() {
return <div>Hello World</div>;
}
}
View index.tsx
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 Dec 5, 2019
node-redis-mongo - final book routes
View bookRoutes.js
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 Oct 3, 2021
node-redis-mongo - final cache
View cache.js
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 Jan 4, 2020
node-redis-mongo - A first cahce file implementation with hook for every query
View cache.js
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 Jan 4, 2020
node-redis-mongo - Connection between our application to redis client
View cache.js
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 Dec 4, 2019
node-redis-mongo - Moongose model that represents a book.
View Book.js
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 Dec 6, 2019
node-redis-mongo - book routes version before cache layer added.
View bookRoutesBeforeCache.js
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()