Class: Taupe::Cache::RedisDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/taupe/cache/redis.rb

Overview

Redis cache driver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dsn) ⇒ RedisDriver

Constructor

Parameters:

  • dsn (Hash)

    The data source name



15
16
17
# File 'lib/taupe/cache/redis.rb', line 15

def initialize(dsn)
  @connection = Redis.new dsn
end

Instance Attribute Details

#connectionObject

Accessors



11
12
13
# File 'lib/taupe/cache/redis.rb', line 11

def connection
  @connection
end

Instance Method Details

#delete(key) ⇒ Object

Delete a key

Parameters:

  • key (String)

    The key to delete



36
37
38
# File 'lib/taupe/cache/redis.rb', line 36

def delete(key)
  @connection.del key
end

#get(key) ⇒ Object

Get a cache entry

Parameters:

  • key (String)

    The key to retrieve

Returns:

  • (Object)


22
23
24
# File 'lib/taupe/cache/redis.rb', line 22

def get(key)
  @connection.hgetall(key).symbolize_keys
end

#set(key, value) ⇒ Object

Set a cache entry

Parameters:

  • key (String)

    The key to set

  • value (Object)

    The value



29
30
31
32
# File 'lib/taupe/cache/redis.rb', line 29

def set(key, value)
  fail 'Only HASH values are supported' unless value.is_a?(Hash)
  @connection.mapped_hmset key, value
end