frankcollins3 / Next-Water-App

Happy, Healthy Water Cycling App that tracks user/human fluid intake.
https://next-water-app.vercel.app
1 stars 0 forks source link

redis? [1:09am] #50

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: learned that connection pooling is caching. (I though it was just an in file way of configging psql instead of connection string) decided to look into caching and redis.

error: (not really error just confusion and overarching question of whether redis makes sense)

asking what caching is and what benefits it has in react/next Screen Shot 2023-07-16 at 12 59 18 AM

actual example Screen Shot 2023-07-16 at 12 58 53 AM

Screen Shot 2023-07-16 at 1 03 25 AM

current app use case: useEffect -> graphQL query & return data -> dispatch( reduxState(returndata) )

chatGPT provided use case: useEffec -> redis -> graphQL query & return data -> dispatch ( reduxState(returndata) )

// kind of confused how adding an extra step can improve latency

// note I can already see how GraphQL is kind of overkill for this very simple water app (that might be wrong) but i dont mind can say the same for redux, as a global {useContext} state could probably do well to

this commit is bookmark of closer consideration of caching and sparing the load for data routes and thinking globally with app

frankcollins3 commented 1 year ago

unless I'm wrong, think I understand caching a bit more: useEffect -> graphQL query & return data -> dispatch( reduxState(returndata) ) // the current example without caching will execute graphQL queries over and over

the redis example will defer to redis.get() in the event of there being data within the cache, hence deterring graphQL

[1:15am]

frankcollins3 commented 1 year ago

curious:

[1:16am]

wondering if one would do caching page by page? this is a simple app and actually doesn't hit too many routes anyways. 1) username routes for handling login is a one and done thing that sets localStorage(user) 2) main page user clicks gear for settings. side panel displays. sets settings with graphql. main displays schedule settings 3) /dashboard-calendar retrieves all the data for logged in user. state set with data for react-calendar

not too many queries over and over. [1:21am]

frankcollins3 commented 1 year ago

setup issues. cant find module 'net' path: main-root/redis/redis.js

clientside use: import redisClient from "redis/redis"

Screen Shot 2023-07-16 at 1 35 29 AM [1:36am]

frankcollins3 commented 1 year ago

.net problem from both packages.

considering that the problem could be that this is done in component rather than top level? import Redis from 'ioredis';

const redisClient = new Redis({
  host: 'localhost', // Redis server host
  port: 6379, // Redis server port
});

export default redisClient;
import Redis from 'ioredis';
const redisClient = new Redis();
export default redisClient;

considering jumping into the docs since chatGPT was not too useful with setting up connection_limit with query

[1:53pm]

frankcollins3 commented 1 year ago

stack overflow https://stackoverflow.com/questions/54275069/module-not-found-error-cant-resolve-net-in-node-modules-stompjs-lib/73226905#73226905

// note anticipation of extra care needed given I installed webpack for the react-express version couldn't really uninstall node_modules with --force or anything to get the app to not run webpack during dev server. // [1:54am]

frankcollins3 commented 1 year ago

dated july 21, 2022 I believe this version of nextJS came out in Dec 10 2022 so could be close https://blog.logrocket.com/add-redis-cache-nestjs-app/ [1:55am]

frankcollins3 commented 1 year ago

LOL it's a mirage. swearing it was nextJS it's nestJS [1:56am]

frankcollins3 commented 1 year ago

https://prachi-tech.vercel.app/caching-redis-next

completely forgot about getServerProps but before, with using fetch() it needed the absolute path which was executed with .pwd() in serversideProps

if I"m not mistaken graphQL is working right now with relative path so useEffect can be done regarding performance, it might make more sense to do serverside functions and put these query-data into props

to have at the ready for build stage (SDLC)

// 1: tbh this step may remove the need for caching but still want to iterate caching. 2: considering redux-persist as well because once the state is set there is no need for subsequent queries

the only reason to query would be to set state so redux-persist would be anticipative of where the data would be going

[2:01am]

frankcollins3 commented 1 year ago

apparently can't' use redis in front end? similar to prisma ? this was my problem with storing the ENV_KEY in a graphQL query in react-express dog chasing tail now to store redis in graphql to avoid overquerying but then have to use graphql initially to use it

https://github.com/redis/ioredis/issues/1196

another foul ball for chat over brainstorming '.dns' and '.nev'

find in a github issue right away: "dns" is native to node and you can't do this in front end ? late. might be interpreting it wrong.

[3:23am]

frankcollins3 commented 1 year ago

think this needs to be at the page level so doing it in pages/index.js [10:42pm]

frankcollins3 commented 1 year ago

apparently the IP address would be used in the "redis endpoint" so that means it will probably be an ENV variable down the line [10:43pm]

frankcollins3 commented 1 year ago

redis survives the import. [10:48am]