Home > redis-friendships

redis-friendships

Redis-friendships is a project mainly written in Ruby, based on the View license.

A friendship library with a certain follower/following system utilizing the power of both Redis and SQL.

== What is redis-friendship A friendship library with a certain follower/following system utilizing the power of both Redis and SQL. Using SQL for the users and Redis for the followers and the followings. Redis uses sets of usernames for both your followers and followings. And can be used to retrieve more information about your e.g. followers from SQL with those unique usernames.

== Install

gem install redis-friendships

== Rails 3

To use redis-friendships with Rails 3 you will need to include it in your Gemfile.

group :development do gem "redis-friendships" end

== Usage

  • rails g redis_friendships : Will name the models User and Friendship and the Redis constant to R

  • rails g redis_friendships fellowship user : Assuming the User model already exist, this will inject code into it and create a Fellowship model

  • rails g redis_friendships fellowship hobbit Red : Creates the models Fellowship and Hobbit and name the Redis constant to Red

  • And don't forget to run your migrations since we also utilize SQL here, the user model will be SQL - anything else would be stupid, right?

== Code == READ Assuming we use standard naming the user model will have two lookup scopes The first two are user.followers and user.followings Where we do a SQL lookup with the list of usernames from the SET to get a list of user objects

If you don't want the user objects but just their (unique) usernames Friendship.followings_for(username) Friendship.followers_for(username)

== WRITE To follow someone you just need to call user.follow!(other_user) This will just push the username into a SET. It will also make that user a following to the otheruser other_user.followings.include? user

To unfollow someone (or have someone unfollowed, just edit it to your hearts desire) user.unfollow!(other_user) This will remove it from user's SET. There are no limits to what you can do. Will also remove the user as a following from other_user other_user.followings.include?(user) == false

PS You can also alter the methods to auto follow new followers or have requests before being stalked DS

Copyright (c) 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

Previous:codebench