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.



5
6
7
8
9
10
# File 'lib/xunch/cache/cache.rb', line 5

def initialize(options, shard_infos)
  @options = initialize_options(options)
  @shard_redis = ShardRedis.new(@options[:regex],shard_infos)
  @host = Socket.gethostname
  @pid = Process.pid
end

Instance Method Details

#batch_evict(keys) ⇒ Object

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



18
19
20
21
22
23
24
# File 'lib/xunch/cache/cache.rb', line 18

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

#destroyObject



32
33
34
# File 'lib/xunch/cache/cache.rb', line 32

def destroy
  @shard_redis.destroy
end

#evict(key) ⇒ Object

从缓存中删除指定的key



13
14
15
# File 'lib/xunch/cache/cache.rb', line 13

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

#ttl(key) ⇒ Object

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



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

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