Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis_rejson_models

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis_rejson_models

  • 0.9.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RedisRejsonModels

Document-like ORM based on Redis key value store - uses Redis Re-JSON for full json manipulation

Install

Add to your gemfile:

gem 'redis_rejson_models', '~> 0.9.5'

Or without bundler, run in your shell:

gem i redis_rejson_models

Requirements

  • Redis (v4+)
  • Re-JSON module installed

DB API

Model.get 1 #=> returns an object instance (gets it from redis)

Model.all #=> returns an array of Model object instances

Model.create({}) #=> creates an entry in redis

Model.update(1, {}) #=> updates a record in redis

Model Definition and Instance API by the shallow_attributes gem

Definition:
class Document
  extend  RedisRejsonModelLib
  include RedisRejsonModelMixin
  include ShallowAttributes

  attribute :id,        Integer
  attribute :name,      String
  attribute :contents,  String

  def antani
    # "..."
  end
end

Instance API:

doc = Document.new name: "Foo", contents: "Bar123"
puts doc.name      #=> "foo"
puts doc.antani    #=> "..."
doc.save # saves the record, gives an auto increment id (example: 1)

doc = Document.get doc.id
puts doc.name      #=> "foo"
puts doc.antani    #=> "..."

Run local Redis (+ Re-JSON module) locally via Docker:

in this repo run:

docker-compose up

Which use the docker-compose.yml to start your redis.

Set up your Redis and RJSON

# sample environment setup
require 'bundler'
Bundler.require :default

# setup redis
R = Redis.new

# load and configure redis with rejson models
include RedisRejsonModels
RJ.configure redis: R

class Document
  # ...
end

Run specs

(you need to run a local redis + rejson service - explained above)

Run:

rake spec

Enjoy!

@makevoid

FAQs

Package last updated on 23 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc