GithubHelp home page GithubHelp logo

redistry's Introduction

Getting Started

Rails 3

Add redistry to your Gemfile

gem "redistry"

You can also use your own redis client connection rather than the default Redis.new (in an initializer, for example)

Redistry.client = Redis.new(:host => 'my-redis-host', :port => 6379)

Using has_list

Associate a Redis list with each ActiveRecord item:

class Notification < ActiveRecord::Base

end

...

class User < ActiveRecord::Base
  has_list :recent_notifications, :class => Notification, :size => 10

  ...
end

You can add items to the list with add:

user.recent_notifications.add(notification)

Since you specified :size, Redistry will treat the list as a queue (first in, last out) with a maximum of size elements. If you don't specify :size, the list will not limit the size at all.

You can fetch the items with all:

@notifications = user.recent_notifications.all

And you can clear all the notifications with clear:

user.recent_notifications.clear

Using list

Sometimes, you want to associate a list generically with an entire class (or a module)

class User
  list :popular, :size => 10
  ...
end

Note that since we didn't specify :class, Redistry will assume the objects are of the same type as the outer class (in this case, User).

Use the same interface as has_list to access the items:

User.popular.add(@user)
@popular_users = User.popular.all
User.popular.clear

Known Issues / TODO

  • JSON serializer does not work with strings... not sure how to deal since this technically is not valid json

Copyright (c) 2011 Brian Smith ([email protected])

redistry's People

Contributors

lytol avatar

Stargazers

Max Surkov avatar @rubynerd avatar Will Cosgrove avatar Abdelhak LAKEL avatar Neal Clark avatar Nelson Yee avatar Stéphane Busso avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.