Module: RedisStore::Cache::Rails2

Defined in:
lib/active_support/cache/redis_store.rb

Instance Method Summary collapse

Instance Method Details

#delete(key, options = nil) ⇒ Object



41
42
43
44
# File 'lib/active_support/cache/redis_store.rb', line 41

def delete(key, options = nil)
  super
  @data.del key
end

#delete_matched(matcher, options = nil) ⇒ Object

Delete objects for matched keys.

Example:

cache.del_matched "rab*"


55
56
57
58
59
# File 'lib/active_support/cache/redis_store.rb', line 55

def delete_matched(matcher, options = nil)
  instrument(:delete_matched, matcher, options) do
    @data.keys(matcher).each { |key| @data.del key }
  end
end

#exist?(key, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/active_support/cache/redis_store.rb', line 46

def exist?(key, options = nil)
  super
  @data.exists key
end

#initialize(*addresses) ⇒ Object

Instantiate the store.

Example:

RedisStore.new
  # => host: localhost,   port: 6379,  db: 0

RedisStore.new "example.com"
  # => host: example.com, port: 6379,  db: 0

RedisStore.new "example.com:23682"
  # => host: example.com, port: 23682, db: 0

RedisStore.new "example.com:23682/1"
  # => host: example.com, port: 23682, db: 1

RedisStore.new "example.com:23682/1/theplaylist"
  # => host: example.com, port: 23682, db: 1, namespace: theplaylist

RedisStore.new "localhost:6379/0", "localhost:6380/0"
  # => instantiate a cluster


26
27
28
# File 'lib/active_support/cache/redis_store.rb', line 26

def initialize(*addresses)
  @data = ::Redis::Factory.create(addresses)
end

#read(key, options = nil) ⇒ Object



36
37
38
39
# File 'lib/active_support/cache/redis_store.rb', line 36

def read(key, options = nil)
  super
  @data.get key, options
end

#write(key, value, options = nil) ⇒ Object



30
31
32
33
34
# File 'lib/active_support/cache/redis_store.rb', line 30

def write(key, value, options = nil)
  super
  method = options && options[:unless_exist] ? :setnx : :set
  @data.send method, key, value, options
end