Class: Rudis::Structure

Inherits:
Base show all
Defined in:
lib/rudis/structure.rb

Direct Known Subclasses

Counter, Hash, List, Lock, Set, ZSet

Instance Method Summary collapse

Methods inherited from Base

#initialize, #key, #redis

Methods inherited from Rudis

key

Constructor Details

This class inherits a constructor from Rudis::Base

Instance Method Details

#default_optionsObject



7
8
9
# File 'lib/rudis/structure.rb', line 7

def default_options
  {:type => DefaultType}
end

#delObject Also known as: delete!



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

def del
  redis.del(key)
end

#exists?Boolean Also known as: exist?

Returns:

  • (Boolean)


11
12
13
# File 'lib/rudis/structure.rb', line 11

def exists?
  redis.exists(key)
end

#expire(time) ⇒ Object



30
31
32
# File 'lib/rudis/structure.rb', line 30

def expire(time)
  redis.expire(key, time)
end

#expire_at(time) ⇒ Object



34
35
36
# File 'lib/rudis/structure.rb', line 34

def expire_at(time)
  redis.expire_at(key, time)
end

#redis_typeObject



26
27
28
# File 'lib/rudis/structure.rb', line 26

def redis_type
  redis.type(key)
end

#rename(new_key) ⇒ Object



21
22
23
24
# File 'lib/rudis/structure.rb', line 21

def rename(new_key)
  redis.rename(key, self.class.key(new_key))
  @key = new_key
end

#ttlObject



38
39
40
# File 'lib/rudis/structure.rb', line 38

def ttl
  redis.ttl(key)
end

#typeObject



3
4
5
# File 'lib/rudis/structure.rb', line 3

def type
  @options[:type]
end

#watch(tries = 0) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rudis/structure.rb', line 42

def watch(tries=0)
  return redis.watch(key) unless block_given?

  begin
    redis.watch(key)
    c = 0
    while yield.nil? && (tries==0 || (c+=1) <= tries)
      puts "Optimistic lock failed for #{key}, retrying #{c} time(s)"
    end
  ensure
    redis.unwatch(key)
  end
end