- Heroku
- redis server (installed and listening on the default local port)
- git
- Node.js 10.x
In your shell terminal, clone this repo to become the working directory:
git clone https://github.com/velizarn/redis-demo
cd redis-demo
Install Node packages:
npm install
Copy the local dev environment variables template (.env.sample), and then open .env
in your editor:
cp .env.sample .env
The app runs one web process, declared in the Procfile
. It may be start using the follow commands:
# Simply run the web & stream processes
# as declared in Procfile (like Heroku uses for deployment):
heroku local
In a browser view the web UI http://localhost:5000/ and http://localhost:5000/sess/get.
Configured via environment variables.
For local development, set these values in .env
file.
REDIS_URL - The URL of the Redis server
REDIS_PASSWORD - If set, client will run Redis auth command on connect
For Heroku deployment, set these values via Config Vars.
Some commands that may help you while you are debugging and testing your new external session storage. Note that all of these must be executed at the redis-cli
prompt, which you can initialize by typing redis-cli
into your terminal.
monitor will show real-time output as any activity occurs
KEYS * will show a numbered list of all existing data keys
GET [put the key here] will show you the contents of a specific key
ttl [put the key here] will show the remaining time till expiration
flushdb removes all keys from the currently selected database
Comprehensive list of Redis commands
You need to know what type of value that key maps to, as for each data type, the command to retrieve it is different.
Here are the commands to retrieve key value:
- if value is of type string -> GET <key>
- if value is of type hash -> HGETALL <key>
- if value is of type lists -> LRANGE <key> <start> <end>
- if value is of type sets -> SMEMBERS <key>
- if value is of type sorted sets -> ZRANGE <key> <min> <max>
command to check the type of value a key mapping to:
TYPE <key>
- https://medium.com/mtholla/managing-node-js-express-sessions-with-redis-94cd099d6f2f
- https://expressjs.com/en/resources/middleware/cookie-session.html
- https://www.npmjs.com/package/express-session
- https://www.npmjs.com/package/connect-redis
- https://stackoverflow.com/questions/16209145/how-to-set-cookie-in-node-js-using-express-framework
- https://codeforgeek.com/2015/07/using-redis-to-handle-session-in-node-js/