{"id":17363059,"url":"https://github.com/jbavari/ionic-socket.io-redis-chat","last_synced_at":"2025-09-10T01:41:56.014Z","repository":{"id":17879426,"uuid":"20821346","full_name":"jbavari/ionic-socket.io-redis-chat","owner":"jbavari","description":"Quick project demonstrating how to use Socket.io / Redis / and Ionic to have a simple chat applications with expiring messages","archived":false,"fork":false,"pushed_at":"2014-07-01T09:41:47.000Z","size":16136,"stargazers_count":67,"open_issues_count":2,"forks_count":29,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-29T13:02:34.089Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbavari.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":"2014-06-14T00:10:08.000Z","updated_at":"2025-02-19T08:54:36.000Z","dependencies_parsed_at":"2022-08-24T08:51:19.276Z","dependency_job_id":null,"html_url":"https://github.com/jbavari/ionic-socket.io-redis-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jbavari/ionic-socket.io-redis-chat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbavari%2Fionic-socket.io-redis-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbavari%2Fionic-socket.io-redis-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbavari%2Fionic-socket.io-redis-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbavari%2Fionic-socket.io-redis-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbavari","download_url":"https://codeload.github.com/jbavari/ionic-socket.io-redis-chat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbavari%2Fionic-socket.io-redis-chat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274396927,"owners_count":25277398,"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","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-15T19:44:28.909Z","updated_at":"2025-09-10T01:41:55.956Z","avatar_url":"https://github.com/jbavari.png","language":"JavaScript","funding_links":[],"categories":["And A Bunch More! (I am in the process of sorting these)"],"sub_categories":[],"readme":"ionic-socket.io-redis-chat\n==========================\n\nQuick project demonstrating how to use Socket.io / Redis / and Ionic to have a simple chat applications with expiring messages\n\n## The idea - Codename VaniChat\n\nI wanted to make a chat application similar to SnapChat where messages are wiped clean after a certain time period.\n\nYou enter a channel. Once in a channel, you send messages. All other clients connected in the channel will see the message. Any messages you send are automatically removed after a time period (default 2 mins).\n\nIn future versions, the channel itself would eventually expire (like a message).\n\n\n## Requirements\n\n* [Redis](http://redis.io) `brew install redis`\n* [Node.js \u0026 npm](https://gist.github.com/isaacs/579814)\n\n## Requirements for Mobile\n\n* [Cordova](http://cordova.apache.org) `npm install -g cordova`\n* [Ionic](http://ionicframework.com) `npm install -g ionic`\n* iOS SDK\n* Android SDK\n\n## Getting started\n\n* Clone the repo and ensure [redis is running](http://redis.io/topics/quickstart)\n* run `npm install` to get all packages required to run the server.\n* run `node server` to run the server\n* visit [VaniChat](http://localhost:8080) in your browser\n\n## Running the iOS Application\n\n* Change directories to client/RedisChat\n* run `cordova run ios`\n\n## Running the Android Application\n\n* Change directories to client/RedisChat\n* run `cordova run android`\n\n## Technology details\n\nDISCLAIMER: I know using Redis as a data store for large scale users is not the best use case for Redis. I wanted to play more with Redis and get some more experience using it and the expires functionality.\n\nThe messages are stored in Redis as a sorted set in the `messages:channel:channelname` key where `channelname` is the channel they are in. The value stored is a simple JSON encoded object with information about the message (message, user, expires time) with its score set as it's UNIX time of posting.\n\nThere is a method in the server.js file - `removeKeys` that will remove messages from channels\nif they exceed the expire time stored in the set.\n\n``` js\n//Channels are populated before this call\nvar channelWatchList = ['Lobby', 'Redis', 'Ionic', 'Socket.io'];\nfunction removeKeys() {\n  console.log('We are removing old messages');\n\n  for(var channelIndex in channelWatchList) {\n    var channel = channelWatchList[channelIndex];\n    var timeToRemove = moment().subtract('m', 2).unix(); //Two minutes ago\n    var messageChannel = 'messages:' + channel;\n\n    redisClient.zrangebyscore(messageChannel, 0, timeToRemove, function(err, result) {\n      if(result \u0026\u0026 result.length \u003e 0) {\n        console.log('Emitting information to client to remove: ', result);\n        for (var resultIndex in result) {\n          var message = JSON.parse(result[resultIndex]);\n          console.log('emitting: ', message);\n          //Signal to all of our connected clients to remove the message.\n          io.emit('message:remove:channel:' + channel, { message: message, channel: channel });\n        }\n      }\n    });\n\n    redisClient.zremrangebyscore(messageChannel, 0, timeToRemove, function(err, result) {\n      console.log('Removed ', result, ' records');\n    });\n  }\n}\n\nvar cleanUpMesssagesInterval = setInterval(removeKeys, 6000);\n\n```\n\n## Interesting tidbits\nAfter failing miserably at trying to make keys that expire, I spoke to Michael Gorsuch and he had found an easier way to manage that using sorted sets and expire times as scores.\n\nThe idea is, you have a sorted set with a key. Then you add a score with a JSON encoded string. The score itself is the unix timestamp. Then, have a timer that passes over and checks for a unix timestamp with some time in the past (2 minutes) and remove using `zremrangebyscore` with 0 to the timestamp - time past.\n\n## NOTES\n\n* All ports / hostnames are hardcoded. In later versions these will be put into a configuration file.\n* Channels need to be expired - and users then removed from channels as well as messages\n\n\n### Contact \n\nI'm available to chat and give insight to this application.\n\nFind me on [twitter](http://twitter.com/jbavari) or by [email](mailto:jbavari@gmail.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbavari%2Fionic-socket.io-redis-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbavari%2Fionic-socket.io-redis-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbavari%2Fionic-socket.io-redis-chat/lists"}