What is redis-messages¶ ↑
A messaging library with outbox/inbox system utilizing the power of both Redis and SQL. Using SQL for the outbox with user_id FK's and Redis for the inbox. A message has one sender, multiple recievers
Install¶ ↑
gem install redis-messages
Rails 3¶ ↑
To use redis-messages with Rails 3 you will need to include it in your Gemfile.
group :development do
gem "redis-messages"
end
Usage¶ ↑
* rails g redis_messages : Will name keys and models as User and Message and the Redis constant to R * rails g redis_messages letter user : Assuming the User model already exist, this will inject code into it and create a Letter model. * rails g redis_messages letter player Red : Creates a Letter and Player model and names the Redis constant to Red * And don't forget to run your migrations since we also utilize SQL here.
Code¶ ↑
Assuming we use standard naming the user model will have two scopes
user.outbox and user.inbox
Where user.outbox will be pure SQL, while user.inbox will call smembers.
Your message will also have a list of receivers
user.outbox.first.receivers
To send a message to a list of people or just a single person (make sure you send in an array for version 0.1)
@message.send_to(a_list_of_usernames)
Copyright © 2011 Seifvan Heifdari af Awesomeness Von Cheeseburger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. By reading this fine print your soul is now the exclusive property of WeDoBDD Productions and its Subsidiaries. Unauthorized use of seivan gems, images, materials, souls, odors and oxygen is strongly discouraged. We know where you sleep. Also, your mum & bring back prop8