Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 8cb56713e5
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (69 sloc) 1.915 kB
require 'redis'
require 'nest'
require 'text'
require 'ostruct'
module Ion
VERSION = "0.0.2"
PREFIX = File.join(File.dirname(__FILE__), 'ion')
# How long until search keys expire.
DEFAULT_TTL = 30
autoload :Stringer, "#{PREFIX}/stringer"
autoload :Config, "#{PREFIX}/config"
autoload :Options, "#{PREFIX}/options"
autoload :Search, "#{PREFIX}/search"
autoload :Entity, "#{PREFIX}/entity"
autoload :Index, "#{PREFIX}/index"
autoload :Indices, "#{PREFIX}/indices"
autoload :Scope, "#{PREFIX}/scope"
autoload :Wrapper, "#{PREFIX}/wrapper"
autoload :Helpers, "#{PREFIX}/helpers"
autoload :Client, "#{PREFIX}/client"
InvalidIndexType = Class.new(StandardError)
Error = Class.new(StandardError)
# Returns the Redis instance that is being used by Ion.
def self.config
@config ||= Ion::Config.new
end
def self.version
VERSION
end
def self.redis
@redis || key.redis
end
# Connects to a certain Redis server.
def self.connect(to)
@redis = Redis.connect(to)
end
# Returns the root key.
def self.key
@key ||= if @redis
Nest.new('Ion', @redis)
else
Nest.new('Ion')
end
end
# Returns a new temporary key.
def self.volatile_key
key['~'][rand.to_s]
end
# Makes a certain volatile key expire.
def self.expire(*keys)
keys.each { |k| redis.expire(k, DEFAULT_TTL) if k.include?('~') }
end
# Redis helper stuff
# Probably best to move this somewhere
# Combines multiple set keys.
def self.union(keys, options={})
return keys.first if keys.size == 1
results = Ion.volatile_key
results.zunionstore keys, options
results
end
# Finds the intersection in multiple set keys.
def self.intersect(keys, options={})
return keys.first if keys.size == 1
results = Ion.volatile_key
results.zinterstore keys, options
results
end
end
Jump to Line
Something went wrong with that request. Please try again.