Skip to content

Latest commit

 

History

History
130 lines (85 loc) · 5.23 KB

README.md

File metadata and controls

130 lines (85 loc) · 5.23 KB

Node.js session management with Redis

Node CI Gitpod Ready-to-Code Build Status GitHub license

Deploy

Deploy on Scalingo

Redis session management with Node.js

Local development

Requires

Setup

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

Running

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

Demo

In a browser view the web UI http://localhost:5000/ and http://localhost:5000/sess/get.

Configuration

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.

Useful Redis commands

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

Redis Data Types

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>

Useful links

Managing sessions with Redis

Redis

node_redis

Heroku