Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ActiveRecord injectable version of the Redis-backed friendship system
Ruby JavaScript
Tree: 68aa5f33e1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rvmrc
CHANGELOG.md
Gemfile
LICENSE.txt
README.md
Rakefile
amico.gemspec

README.md

amico

Relationships (e.g. friendships) backed by Redis.

Installation

gem install amico

or in your Gemfile

gem 'amico'

Make sure your redis server is running! Redis configuration is outside the scope of this README, but check out the Redis documentation, http://redis.io/documentation.

Usage

Configure amico:

Amico.configure do |configuration|
  configuration.redis = Redis.new
  configuration.namespace = 'amico'
  configuration.following_key = 'following'
  configuration.followers_key = 'followers'
  configuration.blocked_key = 'blocked'
  configuration.reciprocated_key = 'reciprocated'
  configuration.page_size = 25
end

Use amico:

require 'amico'
 => true 

Amico.configure do |configuration|
  configuration.redis = Redis.new
  configuration.namespace = 'amico'
  configuration.following_key = 'following'
  configuration.followers_key = 'followers'
  configuration.blocked_key = 'blocked'
  configuration.reciprocated_key = 'reciprocated'
  configuration.page_size = 25
end

Amico.follow(1, 11)
=> [1, 1] 

Amico.following?(1, 11)
 => true 

Amico.following?(11, 1)
 => false 

Amico.follow(11, 1)
 => [1, 1] 

Amico.following?(11, 1)
 => true 

Amico.following_count(1)
 => 1 

Amico.followers_count(1)
 => 1 

Amico.unfollow(11, 1)
 => [1, 1] 

Amico.following_count(11)
 => 0 

Amico.following_count(1)
 => 1 

Amico.follower?(1, 11)
 => false

Amico.following(1)
 => ["11"]

Amico.block(1, 11)
 => [1, 1, 1, 1, 1] 

Amico.following?(11, 1)
 => false 

Amico.blocked?(1, 11)
 => true 

Amico.unblock(1, 11)
 => true

Amico.blocked?(1, 11)
 => false

Amico.follow(11, 1)
 => nil

Amico.follow(1, 11)
 => [1, 1]

Amico.reciprocated?(1, 11)
 => true

Amico.reciprocated(1)
 => ["11"]

Documentation

The source for the relationships module is well-documented. There are some simple examples in the method documentation. You can also refer to the online documentation.

FAQ?

Why use Redis sorted sets and not Redis sets?

Based on the work I did in developing leaderboard, leaderboards backed by Redis, I know I wanted to be able to page through the various relationships. This does not seem to be possible given the current set of commands for Redis sets.

Also, by using the "score" in Redis sorted sets that is based on the time of when a relationship is established, we can get our "recent friends". It is possible that the scoring function may be user-defined in the future to allow for some specific ordering.

Contributing to amico

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 David Czarnecki. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.