Class: GeoipRedis::Store
- Inherits:
-
Object
- Object
- GeoipRedis::Store
- Defined in:
- lib/geoip_redis/store.rb
Constant Summary collapse
- IP_RANGES_KEY =
"geoip:ipranges"
- LOCATIONS_KEY =
"geoip:locations"
Instance Method Summary collapse
- #find_ip_range(ip_num) ⇒ Object
- #find_location(location_id) ⇒ Object
-
#initialize(redis) ⇒ Store
constructor
A new instance of Store.
- #put_ip_ranges(ip_ranges) ⇒ Object
- #put_locations(locations) ⇒ Object
Constructor Details
#initialize(redis) ⇒ Store
Returns a new instance of Store.
10 11 12 |
# File 'lib/geoip_redis/store.rb', line 10 def initialize(redis) @redis = redis end |
Instance Method Details
#find_ip_range(ip_num) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/geoip_redis/store.rb', line 20 def find_ip_range(ip_num) encoded_ip_range = @redis.zrangebyscore( IP_RANGES_KEY, ip_num, "+inf", limit: [0, 1]).first IpRange.decode(encoded_ip_range) if encoded_ip_range end |
#find_location(location_id) ⇒ Object
33 34 35 |
# File 'lib/geoip_redis/store.rb', line 33 def find_location(location_id) @redis.hgetall location_key(location_id) end |
#put_ip_ranges(ip_ranges) ⇒ Object
14 15 16 17 18 |
# File 'lib/geoip_redis/store.rb', line 14 def put_ip_ranges(ip_ranges) @redis.pipelined do ip_ranges.each { |ip_range| put_ip_range(ip_range) } end end |
#put_locations(locations) ⇒ Object
27 28 29 30 31 |
# File 'lib/geoip_redis/store.rb', line 27 def put_locations(locations) @redis.pipelined do locations.each { |location| put_location(location) } end end |