Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

kfyodor/redis_field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RedisField Build Status Code Climate

RedisField is a simple Ruby gem that stores model-specific data to Redis just like normal ActiveRecord attributes.

Great for caches, API responses etc.

Installation

You will need ActiveRecord (>= 3.2).

Add this line to your application's Gemfile:

  gem 'redis_field'

And then execute:

$ bundle

Usage

0. Configuration

Path prefix

A custom key prefix in Redis (ar_redis_field is default)

  RedisField::Base.path_prefix = 'my_custom_prefix'
Redis

Redis.new is default

  RedisField::Base.redis = Redis.new(:url => "redis://:p4ssw0rd@10.0.1.1:6380/15")
Env

Your app's environment. It checks ENV['RAILS_ENV'] by default. If Rails env is not specified, default env is development

  RedisField::Base.env = "staging"

1. Specify field names in your model

  class User < ActiveRecord::Base
    redis_field :some_data

    # redis_fields is just an alias to redis_field
    redis_fields :facebook_friend_ids, :last_logged_in
  end

2. Use these fields just like normal AR attributes

  user = User.last
  user.some_data = "Testing redis_field"
  user.save
  user.reload.some_data # -> "Testing redis_field"
  user.update_attributes(last_logged_in: Time.now)
  user.reload.last_logged_in # -> 2014-04-05 01:00:00 +0000

NB This library is not an ORM for Redis, so it simply marshalls data before storing to Redis. There's no types coercion or anything like that.

More docs and features soon. ❤️

Testing

Just run

$ rake spec

See Appraisal for testing against different ActiveRecord versions.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Redis attributes for ActiveRecord

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages