Skip to content

how to initialize a express/redis project on gitpod

Notifications You must be signed in to change notification settings

antonykariu/redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Initialize

  1. create a gitpod environment variable to store your redis password

gp env REDISPASS=<yourpassword>

Start

After loading workspace you can launch redis-cli

$redis-cli -a "yourpassword"
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping
PONG

Redis Store

import connectRedis from "connect-redis";

const RedisStore = connectRedis(session);
const client = redis.createClient({
  host: "127.0.0.1",
  port: 6379,
  password: process.env.REDISPASS,
});

Using Redis on request

app.get("/", async(req,res, next) => {
  // Store sessionId on redis
  await client.connect()
    .catch((error) => {
      // forward to error handling
      next(error)
      // should break process
    })
  await client.set("key-name",req.sessionID)
    .catch((error) =>{
      next(error)
    })
})

About

how to initialize a express/redis project on gitpod

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published