Class: Cinch::Plugins::LastSeen::RedisStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugins/last_seen/storage/redis_storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRedisStorage

Returns a new instance of RedisStorage.



13
14
15
# File 'lib/cinch/plugins/last_seen/storage/redis_storage.rb', line 13

def initialize
  @redis = ::Redis::Namespace.new("cinch-seen_last", :redis => ::Redis.new(:thread_safe => true))
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



11
12
13
# File 'lib/cinch/plugins/last_seen/storage/redis_storage.rb', line 11

def redis
  @redis
end

Instance Method Details

#get_time(set, key) ⇒ Object



21
22
23
24
# File 'lib/cinch/plugins/last_seen/storage/redis_storage.rb', line 21

def get_time(set, key)
  time = redis.zscore(set, key)
  Time.at(time.to_i) if time
end

#record_time(set, key) ⇒ Object



17
18
19
# File 'lib/cinch/plugins/last_seen/storage/redis_storage.rb', line 17

def record_time(set, key)
  redis.zadd(set.to_s, Time.now.to_i, key.to_s)
end