Class: Xunch::Cache

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

Instance Method Summary collapse

Constructor Details

#initialize(options, shard_infos) ⇒ Cache

Returns a new instance of Cache.



4
5
6
7
# File 'lib/xunch/cache/cache.rb', line 4

def initialize(options, shard_infos)
  @options = initialize_options(options)
  @shard_redis = ShardRedis.new(@options[:regex],shard_infos)
end

Instance Method Details

#batch_evict(keys) ⇒ Object

从缓存中删除指定的一组key



15
16
17
18
19
20
21
# File 'lib/xunch/cache/cache.rb', line 15

def batch_evict(keys)
  new_keys = []
  keys.each { |key|
    new_keys.push assembleKey(key)
  }
  @shard_redis.batch_del(new_keys)
end

#destroyObject



29
30
31
# File 'lib/xunch/cache/cache.rb', line 29

def destroy
  @shard_redis.destroy
end

#evict(key) ⇒ Object

从缓存中删除指定的key



10
11
12
# File 'lib/xunch/cache/cache.rb', line 10

def evict(key)
  @shard_redis.del(assembleKey(key))
end

#ttl(key) ⇒ Object

获取某个key的过期时间,单位秒



24
25
26
27
# File 'lib/xunch/cache/cache.rb', line 24

def ttl(key)
  new_key = assembleKey(key)
  @shard_redis.ttl(new_key)
end