Class: IncludedInRedis
- Inherits:
-
Object
- Object
- IncludedInRedis
- Defined in:
- lib/spider/included_in_redis.rb
Overview
A specialized class using Redis to track items stored. It supports three operations: new, <<, and include? . Together these can be used to add items to Redis, then determine whether the item has been added.
To use it with Spider use the check_already_seen_with method:
Spider.start_at('http://example.com/') do |s|
s.check_already_seen_with IncludedInRedis.new(host: '127.0.0.1', port: 6379)
end
Instance Method Summary collapse
-
#<<(v) ⇒ Object
Add an item to Redis.
-
#include?(v) ⇒ Boolean
True if the item is in Redis.
-
#initialize(*a) ⇒ IncludedInRedis
constructor
Construct a new IncludedInRedis instance.
Constructor Details
#initialize(*a) ⇒ IncludedInRedis
Construct a new IncludedInRedis instance. All arguments here are passed to Redis (part of the redis gem).
18 19 20 |
# File 'lib/spider/included_in_redis.rb', line 18 def initialize(*a) @c = Redis.new(*a) end |
Instance Method Details
#<<(v) ⇒ Object
Add an item to Redis
23 24 25 |
# File 'lib/spider/included_in_redis.rb', line 23 def <<(v) @c.set(v.to_s, v.to_json) end |
#include?(v) ⇒ Boolean
True if the item is in Redis
28 29 30 |
# File 'lib/spider/included_in_redis.rb', line 28 def include?(v) @c.get(v.to_s) == v.to_json end |