Class: Frivol::Backend::RedisDistributed
- Defined in:
- lib/frivol/backend/redis_distributed.rb
Overview
Configuration
While it’s not well known or documented, the Redis gem includes a sharding implementation in Redis::Distributed. This backend makes that available for Frivol.
REDIS_CONFIG = [{
:host => "localhost",
:port => 6379
}, {
:host => "localhost",
:port => 6380
}]
Frivol::Config.backend = Frivol::Backend::RedisDistributed.new(REDIS_CONFIG)
Instance Method Summary collapse
- #connection ⇒ Object
-
#set(key, val, expiry = Frivol::NEVER_EXPIRE) ⇒ Object
(also: #setc)
:nodoc:.
Methods inherited from Redis
#decr, #decrby, #del, #exists, #expire, #flushdb, #get, #incr, #incrby, #initialize, #ttl
Constructor Details
This class inherits a constructor from Frivol::Backend::Redis
Instance Method Details
#connection ⇒ Object
33 34 35 |
# File 'lib/frivol/backend/redis_distributed.rb', line 33 def connection Thread.current[thread_key] ||= ::Redis::Distributed.new(@config) end |
#set(key, val, expiry = Frivol::NEVER_EXPIRE) ⇒ Object Also known as: setc
:nodoc:
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/frivol/backend/redis_distributed.rb', line 21 def set(key, val, expiry = Frivol::NEVER_EXPIRE) if expiry == Frivol::NEVER_EXPIRE connection.set(key, val) else connection.node_for(key).multi do |redis| redis.set(key, val) redis.expire(key, expiry) end end end |