Module: Relix

Defined in:
lib/relix/core.rb,
lib/relix/index.rb,
lib/relix/keyer.rb,
lib/relix/query.rb,
lib/relix/redis.rb,
lib/relix/version.rb,
lib/relix/index_set.rb,
lib/relix/indexes/multi.rb,
lib/relix/indexes/unique.rb,
lib/relix/indexes/ordered.rb,
lib/relix/indexes/primary_key.rb

Defined Under Namespace

Modules: ClassMethods, Keyer Classes: DeprecationError, Error, ExceededRetriesForConcurrentWritesError, Index, IndexSet, InvalidIndexError, InvalidQueryOption, MissingIndexError, MissingIndexValueError, MissingPrimaryKeyError, MultiIndex, NotUniqueError, OrderedIndex, PrimaryKeyIndex, Query, RedisIndexingError, UniqueIndex, UnorderableValueError, UnsupportedRedisVersion, ValuesNotIndexedError, Version

Constant Summary collapse

VERSION =
"2.3.1"
REDIS_VERSION =
"2.6"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.db=(value) ⇒ Object



34
35
36
# File 'lib/relix/redis.rb', line 34

def self.db=(value)
  @redis_db = value
end

.default_keyer(keyer = nil, options = {}) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/relix/keyer.rb', line 2

def self.default_keyer(keyer=nil, options={})
  if keyer
    @default_keyer ||= [keyer, options]
  else
    @default_keyer
  end
end

.deprecate(message, as_of_version) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/relix/version.rb', line 31

def self.deprecate(message, as_of_version)
  as_of_version = Version.new(as_of_version)

  if Version.new(VERSION).major > as_of_version.major
    raise DeprecationError.new(message)
  else
    $stderr.puts(message)
  end
end

.host=(value) ⇒ Object



26
27
28
# File 'lib/relix/redis.rb', line 26

def self.host=(value)
  @redis_host = value
end

.included(klass) ⇒ Object



2
3
4
5
# File 'lib/relix/core.rb', line 2

def self.included(klass)
  super
  klass.extend ClassMethods
end

.index_typesObject



7
8
9
# File 'lib/relix/core.rb', line 7

def self.index_types
  @index_types ||= {}
end

.new_redis_clientObject



16
17
18
19
20
21
22
23
24
# File 'lib/relix/redis.rb', line 16

def self.new_redis_client
  ::Redis.new(host: @redis_host, port: @redis_port).tap do |client|
    version = client.info["redis_version"]
    if(Relix::Version.new(version) < Relix::REDIS_VERSION)
      raise UnsupportedRedisVersion.new("Relix requires Redis >= #{Relix::REDIS_VERSION}; you have #{version}.")
    end
    client.select @redis_db if @redis_db
  end
end

.port=(value) ⇒ Object



30
31
32
# File 'lib/relix/redis.rb', line 30

def self.port=(value)
  @redis_port = value
end

.redisObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/relix/redis.rb', line 5

def self.redis
  unless @redis
    @redis = new_redis_client
  end
  if block_given?
    yield(@redis)
  else
    @redis
  end
end

.register_index(index) ⇒ Object



11
12
13
# File 'lib/relix/core.rb', line 11

def self.register_index(index)
  index_types[index.kind.to_sym] = index
end

Instance Method Details

#deindex!Object



46
47
48
# File 'lib/relix/core.rb', line 46

def deindex!
  relix.deindex!(self)
end

#index!Object



42
43
44
# File 'lib/relix/core.rb', line 42

def index!
  relix.index!(self)
end

#relixObject



38
39
40
# File 'lib/relix/core.rb', line 38

def relix
  self.class.relix
end