0.01
No commit activity in last 3 years
No release in over 3 years
Put MaxMind GeoIP2 database to Redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 0.10
~> 10.0
~> 3.4

Runtime

~> 3.2
 Project Readme

Build Status

GeoipRedis

Puts MaxMind GeoIP2 database to Redis and allows to resolve country/city by ip. The main idea described here.

Restrictions

  • legacy version of GeoIP database isn't supported
  • working only with IPv4 database

Installation

Add this line to your application's Gemfile:

gem "geoip_redis"

And then execute:

$ bundle

Or install it yourself as:

$ gem install redis_geoip

Usage

Working with GeoIP2 Country database:

  • load:
require "redis"
require "geoip_redis/country_loader"

redis = Redis.new(url: "redis://localhost:6379/4")
loader = GeoipRedis::CountryLoader.new(redis)

loader.load_blocks("path/to/blocks_ipv4.csv")
loader.load_locations("path/to/locations.csv")
  • resolve country by ip:
require "redis"
require "geoip_redis/resolver"

redis = Redis.new(url: "redis://localhost:6379/4")
resolver = GeoipRedis::Resolver.new(redis)

country = resolver.resolve("123.234.23.12")

Working with GeoIP2 City database:

  • load:
require "redis"
require "geoip_redis/city_loader"

redis = Redis.new(url: "redis://localhost:6379/5")
loader = GeoipRedis::CityLoader.new(redis)

loader.load_blocks("path/to/blocks_ipv4.csv")
loader.load_locations("path/to/locations.csv")
  • resolve city by ip:
require "redis"
require "geoip_redis/resolver"

redis = Redis.new(url: "redis://localhost:6379/5")
resolver = GeoipRedis::Resolver.new(redis)

city = resolver.resolve("123.234.23.12")

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/zabolotnov87/geoip_redis. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Licence

The gem is available as open source under the terms of the MIT License.