Class: Sc4ry::Backends::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/sc4ry/backends/redis.rb

Overview

Redis backend definition

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Sc4ry::Backends::Redis

Constructor



9
10
11
12
13
14
# File 'lib/sc4ry/backends/redis.rb', line 9

def initialize(config)
  @auth = config.slice(:auth)[:auth]
  @config = config.slice(:host, :port, :db)
  @be = ::Redis.new @config
  @be.auth(@auth) if @auth
end

Instance Method Details

#del(options) ⇒ Boolean

delete a specific record

Options Hash (options):

  • :key (Symbol)

    the name of the record



44
45
46
# File 'lib/sc4ry/backends/redis.rb', line 44

def del(options)
  @store.del options[:key]
end

#exist?(options) ⇒ Boolean

verifiy a specific record existance

Options Hash (options):

  • :key (Symbol)

    the name of the record



57
58
59
# File 'lib/sc4ry/backends/redis.rb', line 57

def exist?(options)
  return ( not @store.get(options[:key]).nil?)
end

#flushObject

flush all records in backend



49
50
51
# File 'lib/sc4ry/backends/redis.rb', line 49

def flush
  @store.flushdb
end

#get(options) ⇒ String

return value of queried record

Options Hash (options):

  • :key (Symbol)

    the name of the record



27
28
29
# File 'lib/sc4ry/backends/redis.rb', line 27

def get(options)
  return @store.get(options[:key])
end

#listArray

return the list of find records in backend for a specific pattern



18
19
20
# File 'lib/sc4ry/backends/redis.rb', line 18

def list
   return @store.keys('*')
end

#put(options) ⇒ String

defined and store value for specified key

Options Hash (options):

  • :key (Symbol)

    the name of the record

  • :value (Symbol)

    the content value of the record



36
37
38
# File 'lib/sc4ry/backends/redis.rb', line 36

def put(options)
  @store.set options[:key], options[:value]
end