{"id":15659366,"url":"https://github.com/bytesleo/redis-jwt","last_synced_at":"2025-05-05T19:28:11.150Z","repository":{"id":57349749,"uuid":"102143523","full_name":"bytesleo/redis-jwt","owner":"bytesleo","description":"Management of sessions by Redis and JWT for horizontal scalability, with the possibility of having one session at a time or multiple for the same user","archived":false,"fork":false,"pushed_at":"2019-05-14T18:13:19.000Z","size":66,"stargazers_count":21,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T10:45:14.645Z","etag":null,"topics":["jwt","node-jwt","node-redis","nodejs-jwt","redis","redis-jwt","redis-jwt-nodejs","redis-session","session","session-jwt"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytesleo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-01T18:50:10.000Z","updated_at":"2023-03-26T05:58:31.000Z","dependencies_parsed_at":"2022-09-16T10:50:21.590Z","dependency_job_id":null,"html_url":"https://github.com/bytesleo/redis-jwt","commit_stats":null,"previous_names":["bytesleo/redis-jwt"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Fredis-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Fredis-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Fredis-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Fredis-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytesleo","download_url":"https://codeload.github.com/bytesleo/redis-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252562319,"owners_count":21768271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jwt","node-jwt","node-redis","nodejs-jwt","redis","redis-jwt","redis-jwt-nodejs","redis-session","session","session-jwt"],"created_at":"2024-10-03T13:16:27.231Z","updated_at":"2025-05-05T19:28:11.124Z","avatar_url":"https://github.com/bytesleo.png","language":"JavaScript","readme":"# redis-jwt\n\n[![NPM version](https://badge.fury.io/js/redis-jwt.svg)](https://npmjs.org/package/redis-jwt) [![Build Status](https://travis-ci.org/kevoj/redis-jwt.svg?branch=master)](https://travis-ci.org/kevoj/redis-jwt) [![dependencies Status](https://david-dm.org/kevoj/redis-jwt/status.svg)](https://david-dm.org/kevoj/redis-jwt) [![devDependencies Status](https://david-dm.org/kevoj/redis-jwt/dev-status.svg)](https://david-dm.org/kevoj/redis-jwt?type=dev)\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://raw.githubusercontent.com/kevoj/redis-jwt/master/LICENSE)\n\n\u003e Management of sessions by Redis and JWT for horizontal scalability, with the possibility of having one session at a time or multiple for the same user\n\n\u003ca\u003e\u003cimg src=\"https://chris.lu/upload/images/redis.png\" width=\"80\"\u003e\u003c/a\u003e\n\u003ca\u003e\u003cimg src=\"https://cdn.auth0.com/blog/jwtalgos/logo.png\" width=\"80\"\u003e\u003c/a\u003e\n\n## Requirements\n\n- [Nodejs](https://nodejs.org) **\u003e= 6.x.x** (**Recommended 8.x.x**)\n- [Redis](https://redis.io)  **\u003e= 3.x.x** (**Recommended 4.x.x**)\n\n## Installation\n\nNpm\n\n```bash\nnpm install redis-jwt --save\n```\n\nYarn\n\n```bash\nyarn add redis-jwt\n```\n\n## Usage\n\n```javascript\n\nimport RedisJwt from 'redis-jwt';\n\nconst r = new RedisJwt({\n    //host: '/tmp/redis.sock', //unix domain\n    host: '127.0.0.1', //can be IP or hostname\n    port: 6379, // port\n    maxretries: 10, //reconnect retries, default 10\n    //auth: '123', //optional password, if needed\n    db: 0, //optional db selection\n    secret: 'secret_key', // secret key for Tokens!\n    multiple: false, // single or multiple sessions by user\n    kea: false // Enable notify-keyspace-events KEA\n});\n\nr.sign('507f191e810c19729de860ea').then(token =\u003e {\n    r.verify(token).then(decode =\u003e {\n    // [Object]\n    }).catch(err =\u003e {\n    // Wrong token\n    });\n});\n\n```\n\n### Example Redis-jwt with Express\n\n```javascript\n\nimport RedisJwt from 'redis-jwt';\nimport express from 'express';\nconst r = new RedisJwt();\nconst app = express();\n\n// Login\napp.get('/login', (req, res) =\u003e {\n    r.sign('507f191e810c19729de860ea', {\n          ttl: '15 minutes',\n          dataToken: { // Public\n              hello: 'world'\n          },\n          dataSession: { // Private\n              hello: 'world',\n              headers : req.headers\n          }\n        }\n    }).then(token =\u003e {\n        res.json({token});\n    });\n});\n\n// Me\napp.get('/me', mw(), (req, res) =\u003e {\n    res.json(req.user);\n});\n\n// Middleware\nfunction mw() {\n  return (req, res, next) =\u003e {\n     const token = req.headers['authorization'];\n     r.verify(token).then(decode =\u003e\n         // here you can get user from DB by id (decode.id)\n         req.user = decode;\n         next();\n     }).catch(err =\u003e {\n        res.status(401).json({err})\n     })\n  }\n}\n\napp.listen(3000, () =\u003e console.log('Server listening on port 3000!'));\n\n```\n\n## Options\n\n### Sign\n\n```javascript\n\n// Basic\nr.sign('507f191e810c19729de860ea').then..\n\n// TTL : 50 seconds, 10 minutes, 5 hours, 3 days, 1 year ...\nr.sign('507f191e810c19729de860ea', {\n      ttl: '15 minutes'\n}).then...\n\n// Save data in token : Object are saved in token\nr.sign('507f191e810c19729de860ea', {\n      dataToken: {world: 'hello'}\n}).then...\n\n// Save data in redis : Object are saved in redis-jwt\nr.sign('507f191e810c19729de860ea', {\n      dataSession: {hello: 'world'}\n}).then...\n\n// Example TTL + dataToken + dataSession\nr.sign('507f191e810c19729de860ea', {\n      ttl: '15 minutes',\n      dataToken: {world: 'hello'},\n      dataSession: {hello: 'world'}\n}).then...\n\n```\n\n### Verify\n\n```javascript\n\n// Basic\nr.verify(token).then(decode =\u003e {\n/*\n{\n \"rjwt\": \"507f191e810c19729de860ea:ZYYlwOGqTmx\",\n \"dataToken\": [Object]\n \"iat\": 1504334208,\n \"id\": \"507f191e810c19729de860ea\",\n \"ttl\": 60\n}\n*/\n}).catch(err =\u003e {\n    // Wrong token\n})\n\n// Get data from redis\nr.verify(token, true).then(decode =\u003e {\n/*\n{\n \"rjwt\": \"507f191e810c19729de860ea:ZYYlwOGqTmx\",\n \"dataToken\": [Object]\n \"dataSession\": [Object]  ----\u003e get data session\n \"iat\": 1504334208,\n \"id\": \"507f191e810c19729de860ea\",\n \"ttl\": 60\n}\n*/\n}).catch(err =\u003e {\n    // Wrong token\n})\n\n```\n\n### Exec\n\n```javascript\n\n// Execute Redis comands\nconst exec = r.exec();\n\nexec.rawCall(['keys', `507f191e810c19729de860ea:*`], (err, result) =\u003e {\n/*\n [\n  \"507f191e810c19729de860ea:ZYYlwOGqTmx\",\n  \"507f191e810c19729de860ea:d39K8J249Hd\",\n ]\n*/\n});\n\n```\n\n### Call\n\n```javascript\n\n// Method's redis-jwt\nconst call = r.call();\n\n// Test Ping\ncall.ping().then..\n\n// Create\ncall.create(key, value, ttl).then..\n\n// exits by key\ncall.exists(key).then..\n\n// Get ttl by Key\ncall.ttl(key).then..\n\n// Get values by key\ncall.getValueByKey(key).then..\n\n// Get values by Pattern\ncall.getValuesByPattern(pattern).then..\n\n// Get count by Pattern\ncall.getCountByPattern(pattern).then..\n\n// Get info\ncall.getInfo(section).then..\n\n// Destroy by key\ncall.destroy(key).then..\n\n// Destroy multiple by key\ncall.destroyMultiple(key).then..\n\n\n```\n\n## Events\n\n```javascript\n\n// Ready\nr.on('ready', () =\u003e {\n    console.log('redis-jwt-\u003e ready!');\n});\n\n// connected\nr.on('connected', () =\u003e {\n    console.log('redis-jwt-\u003e connected!');\n});\n\n// disconnected\nr.on('disconnected', () =\u003e {\n    console.log('redis-jwt-\u003e disconnected!');\n});\n\n// error\nr.on('error', (err) =\u003e {\n    console.log('redis-jwt-\u003e error!', err);\n});\n\n```\n\n## Development\n\n### Start\n\n`npm start`\n\n### Compile\n\n`npm run compile`\n\n### Test\n\n`npm test`\n\n## License\n\nMIT © [Leonardo Rico](https://github.com/kevoj/redis-jwt/blob/master/LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytesleo%2Fredis-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytesleo%2Fredis-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytesleo%2Fredis-jwt/lists"}