0.0
No commit activity in last 3 years
No release in over 3 years
Wrapper Gem for redis to make us easy operate cache with Redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.2.3

Runtime

>= 0
 Project Readme

Simple Redis

Gem Version

Use Simple Redis just like you use Rails cache

Installation

Add this line to your application's Gemfile:

gem 'simple_redis', '~> 0.3.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_redis

Usage

fetch

You can use key and value parameter to cache the data

SimpleRedis.fetch(key: 'department-list', value: Department.all)
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

Please note every cached object will be converted to json format using to_json

OR You can use key and block to cache it

SimpleRedis.fetch(key: 'department-list') do
  Department.all
end
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

As default we will cache data under simple-redis-cache collection/database, but if you need to define it yourself, simply use db parameter, see the example

SimpleRedis.fetch(db: 'important-db', key: 'department-list') do
  Department.all
end
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

set

You can simply just set value to a key, with this:

SimpleRedis.set('department-list', Department.all)
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

get

Or you can just get value of a key with this

SimpleRedis.get('department-list')
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

total_matches

Total matches used to see how many key matched with our keyword, e.g:

SimpleRedis.total_matches('department/*')
# => 3

delete_matched

This method remove a data based on key such as:

SimpleRedis.delete_matched('department/fashion')
# => 1

OR you can use regex

SimpleRedis.delete_matched('department/*')
# => 3

Configuration

Create simple_redis.rb in config/initializers folder

SimpleRedis.configuration do |config|
  config.host = "redis_host" # Default 'localhost'
  config.port = "redis_port" # Default 6379
  config.default_db = "redis_db" # Default '0'
end

And you can change those 3 configurations on the fly, example:

SimpleRedis.fetch(db: 'important-db', key: 'department-list', host: 'redis_host', port: 'redis_port') do
  Department.all
end
# => [{name: 'Car'}, {name: 'Fashion'}, {name: 'Gadget'}]

Development

Contributing

  1. Fork it ( https://github.com/aditiamahdar/simple_redis/fork )
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin new-feature)
  5. Create a new Pull Request

This project rocks and uses MIT-LICENSE.