<commit_before># RedisField [![Build Status](https://travis-ci.org/konukhov/redis_field.svg?branch=master)](https://travis-ci.org/konukhov/redis_field) [![Code Climate](https://codeclimate.com/github/konukhov/redis_field.png)](https://codeclimate.com/github/konukhov/redis_field)

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+ (oops, gotta test it).

Add this line to your application's Gemfile:

```ruby
  gem 'redis_field'
```

And then execute:

    $ bundle


## Usage

### 1. Specify field names in your model

```ruby
  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

```ruby
  user = User.last
```

```ruby
  user.some_data = "Testing redis_field"
  user.save<commit_msg>updated docs<commit_after># RedisField [![Build Status](https://travis-ci.org/konukhov/redis_field.svg?branch=master)](https://travis-ci.org/konukhov/redis_field) [![Code Climate](https://codeclimate.com/github/konukhov/redis_field.png)](https://codeclimate.com/github/konukhov/redis_field)

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:

```ruby
  gem 'redis_field'
```

And then execute:

    $ bundle


## Usage

### 0. Configuration

##### Path prefix
A custom key prefix in Redis (*ar_redis_field* is default)
```ruby
  RedisField::Base.path_prefix = 'my_custom_prefix'
```

##### Redis
Redis.new is default
```ruby
  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*

```ruby
  RedisField::Base.env = "staging"
```

### 1. Specify field names in your model

```ruby
  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

```ruby
  user = User.last
```

```ruby
  user.some_data = "Testing redis_field"
  user.save
{'fraction_non_alphanumeric': 0.1297037630104083, 'fraction_numerical': 0.008807045636509208, 'mean_word_length': 4.516556291390729, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5762391', 'n_tokens_mistral': 905, 'n_tokens_neox': 835, 'n_words': 233}