Class: Reddish

Inherits:
Object
  • Object
show all
Defined in:
lib/reddish.rb

Instance Method Summary collapse

Constructor Details

#initialize(port = 6379) ⇒ Reddish

Returns a new instance of Reddish.



4
5
6
# File 'lib/reddish.rb', line 4

def initialize port=6379
  @redis = Redis.new port: port
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reddish.rb', line 24

def method_missing m, *args, &block
  m = m.to_s

  if @redis.public_methods.include? m
    @redis.send m, *args, &block
  elsif m.end_with? '='
    @redis.set m.chomp('='), *args.first
  else
    @redis.get m
  end
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/reddish.rb', line 16

def [] key
  @redis.get key.to_s
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/reddish.rb', line 20

def []= key, value
  @redis.set key.to_s, value
end

#get(key) ⇒ Object



8
9
10
# File 'lib/reddish.rb', line 8

def get key
  @redis.get key.to_s
end

#set(key, value) ⇒ Object



12
13
14
# File 'lib/reddish.rb', line 12

def set key, value
  @redis.set key.to_s, value
end