Class: Ook

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, key) ⇒ Ook

Receive a Redis client and a key. There are no restrictions regarding the type of the Redis client, but it must respond to ‘call` and the signature must be identical to that of Redic.



9
10
11
12
# File 'lib/ook.rb', line 9

def initialize(redis, key)
  @ns = key
  @redis = redis
end

Instance Attribute Details

#redisObject

The Redis client can be swapped at any point.



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

def redis
  @redis
end

Instance Method Details

#[](key) ⇒ Object

The passed key will be appended to the previous namespace.



15
16
17
# File 'lib/ook.rb', line 15

def [](key)
  self.class.new(redis, sprintf("%s:%s", @ns, key))
end

#call(cmd, *args) ⇒ Object

Call commands on the Redis client after inserting the key in the second position. Return the result of the command.



27
28
29
# File 'lib/ook.rb', line 27

def call(cmd, *args)
  @redis.call(cmd, @ns, *args)
end

#inspectObject Also known as: to_s



19
20
21
# File 'lib/ook.rb', line 19

def inspect
  @ns
end