Permalink
Browse files

+ redis/sqlite option is now called realtime

  • Loading branch information...
1 parent a86bb10 commit 8590da8abf907fc241be533b0b5bbacfcded0bdf @floere committed Dec 13, 2011
@@ -7,15 +7,15 @@ module Backends
class Redis < Backend
attr_reader :client,
- :immediate
+ :realtime
def initialize options = {}
maybe_load_hiredis
check_hiredis_gem
check_redis_gem
@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
- @immediate = options[:immediate]
+ @realtime = options[:realtime]
end
def maybe_load_hiredis
require 'hiredis'
@@ -37,31 +37,31 @@ def check_redis_gem
# [:token] # => [id, id, id, id, id] (an array of ids)
#
def create_inverted bundle
- List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:inverted", immediate: immediate
+ List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:inverted", realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
- Float.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:weights", immediate: immediate
+ Float.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:weights", realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_similarity bundle
- List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:similarity", immediate: immediate
+ List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:similarity", realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:key] # => value (a value for this config key)
#
def create_configuration bundle
- String.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:configuration", immediate: immediate
+ String.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:configuration", realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [id] # => [:sym1, :sym2]
#
def create_realtime bundle
- List.new client, "#{bundle.identifier}:realtime", immediate: immediate
+ List.new client, "#{bundle.identifier}:realtime", realtime: realtime
end
# Does the Redis version already include
@@ -160,7 +160,7 @@ def ids combinations, amount, offset
# the Redis backend calculation method.
# So loaded? would be more appropriate.
#
- if immediate
+ if realtime
# Just checked once on the first call.
#
if redis_with_scripting?
@@ -24,14 +24,14 @@ def initialize client, namespace, options = {}
@empty = options[:empty]
@initial = options[:initial]
- @immediate = options[:immediate]
+ @realtime = options[:realtime]
end
# The empty index that is used for putting the index
# together.
#
def empty
- @empty && @empty.clone || (@immediate ? self.reset : {})
+ @empty && @empty.clone || (@realtime ? self.reset : {})
end
# The initial content before loading.
@@ -40,7 +40,7 @@ def empty
# this just returns the same thing as #load.
#
def initial
- @initial && @initial.clone || (@immediate ? self.reset : {})
+ @initial && @initial.clone || (@realtime ? self.reset : {})
end
# Returns itself.
@@ -27,7 +27,7 @@ def delete key
# Writes the hash into Redis.
#
def dump hash
- unless @immediate
+ unless @realtime
clear
# client.pipelined do
hash.each_pair do |key, values|
@@ -23,7 +23,7 @@ def delete key
# Note: We could use multi, but it did not help.
#
def dump hash
- unless @immediate
+ unless @realtime
clear
hash.each_pair do |key, value|
client.hset namespace, key, value
@@ -4,10 +4,10 @@ module Backends
class SQLite < Backend
- attr_reader :self_indexed
+ attr_reader :realtime
def initialize options = {}
- @self_indexed = options[:self_indexed]
+ @realtime = options[:realtime]
require 'sqlite3'
rescue LoadError => e
@@ -18,31 +18,31 @@ def initialize options = {}
# [:token] # => [id, id, id, id, id] (an array of ids)
#
def create_inverted bundle
- StringKeyArray.new bundle.index_path(:inverted), self_indexed: self_indexed
+ StringKeyArray.new bundle.index_path(:inverted), realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
- Value.new bundle.index_path(:weights), self_indexed: self_indexed
+ Value.new bundle.index_path(:weights), realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_similarity bundle
- StringKeyArray.new bundle.index_path(:similarity), self_indexed: self_indexed
+ StringKeyArray.new bundle.index_path(:similarity), realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [:key] # => value (a value for this config key)
#
def create_configuration bundle
- Value.new bundle.index_path(:configuration), self_indexed: self_indexed
+ Value.new bundle.index_path(:configuration), realtime: realtime
end
# Returns an object that on #initial, #load returns an object that responds to:
# [id] # => [:sym1, :sym2]
#
def create_realtime bundle
- IntegerKeyArray.new bundle.index_path(:realtime), self_indexed: self_indexed
+ IntegerKeyArray.new bundle.index_path(:realtime), realtime: realtime
end
end
@@ -14,21 +14,21 @@ def initialize cache_path, options = {}
@cache_path = "#{cache_path}.sqlite3"
@empty = options[:empty]
@initial = options[:initial]
- @self_indexed = options[:self_indexed]
+ @realtime = options[:realtime]
lazily_initialize_client
end
def initial
- @initial && @initial.clone || (@self_indexed ? self.reset : {})
+ @initial && @initial.clone || (@realtime ? self.reset : {})
end
def empty
- @empty && @empty.clone || (@self_indexed ? self.reset.asynchronous : {})
+ @empty && @empty.clone || (@realtime ? self.reset.asynchronous : {})
end
def dump internal
- dump_sqlite internal unless @self_indexed
+ dump_sqlite internal unless @realtime
self
end
@@ -48,8 +48,8 @@ def each up_to = nil, &block
include Picky
backends = [
- ["immediate Redis", Backends::Redis.new(immediate: true), 100],
- ["immediate SQLite", Backends::SQLite.new(self_indexed: true), 100],
+ ["realtime Redis", Backends::Redis.new(realtime: true), 100],
+ ["realtime SQLite", Backends::SQLite.new(realtime: true), 100],
["standard Redis", Backends::Redis.new, 200],
["standard SQLite", Backends::SQLite.new, 200],
["standard File", Backends::File.new, 300],
@@ -102,8 +102,8 @@ def prepare
Backends::File.new,
Backends::SQLite.new,
Backends::Redis.new,
- Backends::SQLite.new(self_indexed: true),
- Backends::Redis.new(immediate: true),
+ Backends::SQLite.new(realtime: true),
+ Backends::Redis.new(realtime: true),
]
definitions = []
@@ -14,7 +14,7 @@
@weights,
@partial,
@similarity,
- backend: Picky::Backends::Redis.new(immediate: true)
+ backend: Picky::Backends::Redis.new(realtime: true)
end
it 'is by default an SQLite Array' do
@@ -14,7 +14,7 @@
@weights,
@partial,
@similarity,
- backend: Picky::Backends::SQLite.new(self_indexed: true)
+ backend: Picky::Backends::SQLite.new(realtime: true)
end
it 'is by default an SQLite Array' do
@@ -92,7 +92,7 @@ def initialize id, title, author
context 'immediately indexing backend (no dump needed)' do
before(:each) do
- data.backend described_class.new(self_indexed: true)
+ data.backend described_class.new(realtime: true)
data.clear
data.add Book.new(1, 'title', 'author')
@@ -73,7 +73,7 @@
end
context 'hash-based indexes' do
- let(:db) { described_class.new 'some/cache/path/to/file', self_indexed: true }
+ let(:db) { described_class.new 'some/cache/path/to/file', realtime: true }
describe 'dump' do
it 'delegates to the given hash' do

0 comments on commit 8590da8

Please sign in to comment.