Class: Moneta::Adapters::Redis

### Home Classes Methods

### In Files

- lib/moneta/adapters/redis.rb

### Parent

Object

### Methods

- ::new
- #clear
- #close
- #create
- #delete
- #increment
- #key?
- #load
- #store
- #update_expires

### Included Modules

- Moneta::Defaults
- Moneta::ExpiresSupport

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Moneta
- Moneta::Adapters
- Moneta::Adapters::ActiveRecord
- Moneta::Adapters::Cassandra
- Moneta::Adapters::Client
- Moneta::Adapters::Cookie
- Moneta::Adapters::Couch
- Moneta::Adapters::DBM
- Moneta::Adapters::DataMapper
- Moneta::Adapters::DataMapper::Store
- Moneta::Adapters::Daybreak
- Moneta::Adapters::File
- Moneta::Adapters::Fog
- Moneta::Adapters::GDBM
- Moneta::Adapters::HBase
- Moneta::Adapters::KyotoCabinet
- Moneta::Adapters::LMDB
- Moneta::Adapters::LRUHash
- Moneta::Adapters::LRUHash::Entry
- Moneta::Adapters::LevelDB
- Moneta::Adapters::LocalMemCache
- Moneta::Adapters::MemcachedDalli
- Moneta::Adapters::MemcachedNative
- Moneta::Adapters::Memory
- Moneta::Adapters::Mongo
- Moneta::Adapters::Null
- Moneta::Adapters::PStore
- Moneta::Adapters::Redis
- Moneta::Adapters::RestClient
- Moneta::Adapters::Riak
- Moneta::Adapters::SDBM
- Moneta::Adapters::Sequel
- Moneta::Adapters::Sqlite
- Moneta::Adapters::TDB
- Moneta::Adapters::TokyoCabinet
- Moneta::Adapters::TokyoTyrant
- Moneta::Adapters::YAML
- Moneta::Builder
- Moneta::Cache
- Moneta::Cache::DSL
- Moneta::CreateSupport
- Moneta::Defaults
- Moneta::Defaults::ClassMethods
- Moneta::Expires
- Moneta::ExpiresSupport
- Moneta::HashAdapter
- Moneta::IncrementSupport
- Moneta::Lock
- Moneta::Logger
- Moneta::Logger::Format
- Moneta::Mutex
- Moneta::OptionMerger
- Moneta::OptionSupport
- Moneta::Pool
- Moneta::Proxy
- Moneta::Semaphore
- Moneta::Server
- Moneta::Shared
- Moneta::Stack
- Moneta::Stack::DSL
- Moneta::SynchronizePrimitive
- Moneta::Transformer
- Moneta::Transformer::Helper
- Moneta::Utils
- Moneta::WeakCreate
- Moneta::WeakIncrement
- Moneta::Wrapper
- Rack
- Rack::Cache
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::MONETA
- Rack::Cache::EntityStore::Moneta
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::MONETA
- Rack::Cache::MetaStore::Moneta
- Rack::Cache::MonetaResolver
- Rack::MonetaCookies
- Rack::MonetaRest
- Rack::MonetaStore
- Rack::Session
- Rack::Session::Moneta
- ActionDispatch
- ActionDispatch::Session
- ActionDispatch::Session::MonetaStore
- ActiveSupport
- ActiveSupport::Cache
- ActiveSupport::Cache::MonetaStore

No matching classes.

# Moneta::Adapters::Redis

Redis backend @api public

### Attributes

backend[R]

### Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Integer] :expires Default expiration time @option options [::Redis] :backend Use existing backend instance @option options Other options passed to `Redis#new`

    # File lib/moneta/adapters/redis.rb, line 18
    def initialize(options = {})
      self.default_expires = options.delete(:expires)
      @backend = options[:backend] || ::Redis.new(options)
    end

### Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

    # File lib/moneta/adapters/redis.rb, line 69
    def clear(options = {})
      @backend.flushdb
      self
    end

close() click to toggle source

(see Proxy#close)

    # File lib/moneta/adapters/redis.rb, line 85
    def close
      @backend.quit
      nil
    end

create(key, value, options = {}) click to toggle source

(see Defaults#create)

    # File lib/moneta/adapters/redis.rb, line 75
    def create(key, value, options = {})
      if @backend.setnx(key, value)
        update_expires(key, options)
        true
      else
        false
      end
    end

delete(key, options = {}) click to toggle source

(see Proxy#delete)

    # File lib/moneta/adapters/redis.rb, line 54
    def delete(key, options = {})
      if value = load(key, options)
        @backend.del(key)
        value
      end
    end

increment(key, amount = 1, options = {}) click to toggle source

(see Proxy#increment)

    # File lib/moneta/adapters/redis.rb, line 62
    def increment(key, amount = 1, options = {})
      value = @backend.incrby(key, amount)
      update_expires(key, options)
      value
    end

key?(key, options = {}) click to toggle source

(see Proxy#key?)

This method considers false and 0 as "no-expire" and every positive number as a time to live in seconds.

    # File lib/moneta/adapters/redis.rb, line 27
    def key?(key, options = {})
      if @backend.exists(key)
        update_expires(key, options, nil)
        true
      else
        false
      end
    end

load(key, options = {}) click to toggle source

(see Proxy#load)

    # File lib/moneta/adapters/redis.rb, line 37
    def load(key, options = {})
      value = @backend.get(key)
      update_expires(key, options, nil)
      value
    end

store(key, value, options = {}) click to toggle source

(see Proxy#store)

    # File lib/moneta/adapters/redis.rb, line 44
    def store(key, value, options = {})
      if expires = expires_value(options)
        @backend.setex(key, expires, value)
      else
        @backend.set(key, value)
      end
      value
    end

### Protected Instance Methods

update_expires(key, options, default = @default_expires) click to toggle source

    # File lib/moneta/adapters/redis.rb, line 92
    def update_expires(key, options, default = @default_expires)
      case expires = expires_value(options, default)
      when false
        @backend.persist(key)
      when Numeric
        @backend.expire(key, expires)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.