Class: Wayfarer::Frontiers::RedisFrontier Private

Inherits:
Frontier
  • Object
show all
Defined in:
lib/wayfarer/frontiers/redis_frontier.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A Redis frontier

Instance Attribute Summary

Attributes inherited from Frontier

#config

Instance Method Summary collapse

Methods inherited from Frontier

#cycle

Constructor Details

#initialize(config) ⇒ RedisFrontier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RedisFrontier.


10
11
12
13
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 10

def initialize(config)
  @conn = Redis.new(config.redis_opts)
  super(config)
end

Instance Method Details

#cache(*uris) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


36
37
38
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 36

def cache(*uris)
  @conn.sadd(cached_uris_key, uris.map(&:to_s)) if uris.any?
end

#cached?(uri) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

41
42
43
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 41

def cached?(uri)
  @conn.sismember(cached_uris_key, uri.to_s)
end

#current_urisObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


16
17
18
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 16

def current_uris
  @conn.smembers(current_uris_key).map { |str| URI(str) }
end

#freeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


46
47
48
49
50
51
52
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 46

def free
  [current_uris_key, staged_uris_key, cached_uris_key].each do |key|
    @conn.del(key)
  end

  @conn.disconnect!
end

#stage(*uris) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


26
27
28
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 26

def stage(*uris)
  @conn.sadd(staged_uris_key, uris.map(&:to_s)) if uris.any?
end

#staged?(uri) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

31
32
33
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 31

def staged?(uri)
  @conn.sismember(staged_uris_key, uri.to_s)
end

#staged_urisObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


21
22
23
# File 'lib/wayfarer/frontiers/redis_frontier.rb', line 21

def staged_uris
  @conn.smembers(staged_uris_key).map { |str| URI(str) }
end