Project

red_blocks

0.01
Low commit activity in last 3 years
No release in over a year
This module provides classes of redis sorted set to implement fast ranking, search, filtering with coherent cache management policy.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 0.17
>= 0
~> 13.0
~> 3.0

Runtime

>= 3.3, < 6.0
 Project Readme

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'

This entry and this slide describe the usage of RedBlocks (in japanese).