### Home Classes Methods

### In Files

- lib/ramaze/cache/redis.rb

### Parent

Object

### Methods

- ::new
- ::using
- #cache_clear
- #cache_delete
- #cache_fetch
- #cache_setup
- #cache_store

### Included Modules

- Cache::API
- Innate::Traited

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::Cache::Redis

The Redis cache is a cache driver for Redis (redis.io/). Redis is a key/value store similar to Memcached but with the ability to flush data to a file among various other features.

The usage of this cache is very similar to the Memcache driver. You load it by simply specifying the class:

    Ramaze::Cache.options.session = Ramaze::Cache::Redis

If you want to specify custom options you can do so by calling {.using} on the class:

    Ramaze::Cache.options.session = Ramaze::Cache::Redis.using(...)

@example Using a custom Redis host

    Ramaze::Cache.options.names.push(:redis)
    Ramaze::Cache.options.redis = Ramaze::Cache::Redis.using(
      :host => '123.124.125.126',
      :port => 6478
    )

@author Michael Fellinger @since 09-10-2011

### Attributes

options[RW]
options[RW]

Hash containing all the default options merged with the user specified ones.

### Public Class Methods

new(options = {}) click to toggle source

Creates a new instance of the cache and merges the options if they haven't already been set.

@author Michael Fellinger @param [Hash] options A hash with custom options. See

    Ramaze::Cache::Redis.using() and the trait :default for more
    information.

    # File lib/ramaze/cache/redis.rb, line 83
    def initialize(options = {})
      self.class.options ||= Ramaze::Cache::Redis.trait[:default].merge(
        options
      )

      @options = options.merge(self.class.options)
    end

using(options = {}) click to toggle source

Creates a new instance of the cache class and merges the default options with the custom ones.

Using this method you can specify custom options for various caches. For example, the Redis cache for your sessions could be located at server #1 while a custom cache is located on server #2.

@author Yorick Peterse @since 09-10-2011 @param [Hash] options A hash containing custom options. @option options [Fixnum] :expires_in The default time after which a

    key should expire.

@option options [String] :host The hostname of the machine on which

    Redis is running.

@option options [Fixnum] :port The port number to connect to.

    # File lib/ramaze/cache/redis.rb, line 68
    def using(options = {})
      merged = Ramaze::Cache::Redis.trait[:default].merge(options)
      Class.new(self) { @options = merged }
    end

### Public Instance Methods

cache_clear() click to toggle source

Clears the entire cache.

@author Michael Fellinger @since 09-10-2011

    # File lib/ramaze/cache/redis.rb, line 118
    def cache_clear
      @client.flushall
    end

cache_delete(*keys) click to toggle source

Removes a number of keys from the cache.

@author Michael Fellinger @param [Array] *keys An array of key names to remove.

    # File lib/ramaze/cache/redis.rb, line 128
    def cache_delete(*keys)
      @client.del(*keys)
    end

cache_fetch(key, default = nil) click to toggle source

Retrieves the value of the given key. If no value could be retrieved the default value (set to nil by default) will be returned instead.

@author Michael Fellinger @param [String] key The name of the key to retrieve. @param [Mixed] default The default value. @return [Mixed]

    # File lib/ramaze/cache/redis.rb, line 141
    def cache_fetch(key, default = nil)
      value = @client.get(key)
      value.nil? ? default : value
    end

cache_setup(hostname, username, appname, cachename) click to toggle source

Prepares the cache by setting up the namespace and loading Redis.

@author Michael Fellinger @since 09-10-2011 @param [String] hostname The host of the machine that's running the

    Ramaze application.

@param [String] username The name of the user that's running the

    application.

@param [String] appname The name of the application (:pristine by

    default).

@param [String] cachename The namespace to use for this cache instance.

    # File lib/ramaze/cache/redis.rb, line 104
    def cache_setup(hostname, username, appname, cachename)
      options[:namespace] = [
        hostname, username, appname, cachename
      ].compact.join('-')

      @client = ::Redis.new(options)
    end

cache_store(key, value, ttl = nil, options = {}) click to toggle source

Stores a new value under the given key.

@author Michael Fellinger @param [String] key The name of the key to store. @param [Mixed] value The value of the key. @param [Fixnum] ttl The Time To Live of the key. @param [Hash] options A hash containing key specific options. @option options :expires_in The time after which the key should expire.

    # File lib/ramaze/cache/redis.rb, line 156
    def cache_store(key, value, ttl = nil, options = {})
      ttl = options[:ttl] || @options[:expires_in]
      @client.setex(key, ttl, value)

      return value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.