Created
December 1, 2016 18:47
-
-
Save kylewelsby/60d3560c00c964f7ee69ccffe70a9a6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sequares | |
module Store | |
class Redis < Base | |
attr_accessor :connection | |
def initialize(connection=::Redis.new) | |
@connection = connection | |
end | |
def filter_events(*klasses) | |
entity_event_pairs = {} | |
connection.keys.each do |key| | |
next unless connection.type(key) == "list" | |
events = connection.lrange(key, 0, -1).to_a.collect do |hist| | |
::Marshal.load(hist) | |
end | |
events.each do |event| | |
next unless klass_in_klasses?(event, klasses) | |
key_split = key.split("|") | |
klass = ActiveSupport::Inflector.classify(key_split.first).constantize.new(key_split.last) | |
entity_event_pairs[klass] = event | |
end | |
end | |
entity_event_pairs | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
describe Sequares::Store::Redis do | |
before :each do | |
Sequares.configure do |config| | |
config.store = Sequares::Store::Redis.new | |
end | |
end | |
it_behaves_like 'store' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment