Code Monkey home page Code Monkey logo

red_blocks's Introduction

RedBlocks Build Status

What is this?

This gem provides some set classes based on Redis sorted set. So a set may have scores for each elements.

By using them, it is possible to implement fast ranking system, search system, or filtering system based on coherent cache management of Redis.

Example

Please suppose that there are some tagged documents and we want to provide search system. A user can full-text search, and filter by the tags.

For example, to implement the following query:

  • serach by the word of "cache mangement"
  • And filter by the tag of "new" or "starred"

We construct the follwoing set:

keyword_set = KeywordSet.new("Ruby") # Each elements have score based on full-text serach.
tagged_set_1 = TaggedSet.new(:new)
tagged_set_2 = TaggedSet.new(:starred)

set = IntersectionSet.new([
  keyword_set,
  UnionSet.new([tagged_set_1, tagged_set_2]),
], cache_time: 3.minutes)
set.ids #=> [3, 4, 8, 9, 1]

The result is order by the score of keyword set, because each scores of elements are summed on intersection, or union by default.

This is a simple example, and it is possible to apply this pattern to construct more complex system which has small latency. For example, if you want to personalize the result, you have to prepare a personalized ranking and use it as a base set.

In general, there are some advantages by using RedBlocks.

  • aggregate the result of each service by sorted set operations.
  • flatten the latency of each service(e.g. full-text search service, recommendation service) by Redis cache.
  • get rid of the cost of Redis key management from programmer.
  • get rid of manual checking whether the cache exists or not from programmer.
  • possible to construct such systems in object-oridented style.

Installation

gem 'red_blocks'

Classes

TODO: document

This entry describes the usage of RedBlocks (in japanese).

red_blocks's People

Contributors

ngtk avatar altech avatar

Watchers

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.