Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:48:57+00:00 2026-05-26T22:48:57+00:00

I need to store IP addresses in a redis hash. Will there be considerable

  • 0

I need to store IP addresses in a redis hash.

Will there be considerable memory savings if the IP is stored as an integer instead of a string?

I would be using Ruby’s IPAddr to convert the IP to an int.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:48:57+00:00Added an answer on May 26, 2026 at 10:48 pm

    It depends on how you do it. In Redis keys and (leaf) values are strings. If you would convert an IP address to an int and send it to Redis like the following code you wouldn’t save much:

    redis.hset("xyz", "ip", IPAddr.new(ip).to_i)
    

    The IP “255.255.255.255”, for example, is 15 bytes in dotted quad form, its integer representation “4294967295” is ten bytes when saved as a string, which is what the code above will do.

    To get down to just four bytes stored in Redis you would have to send the raw bytes “\xFF\xFF\xFF\xFF”.

    In Ruby you would do it this way:

    packed_ip = IPAddr.new(ip).hton
    redis.hset("xyz", "ip", packed_ip)
    

    And then when you read it back

    packed_ip = redis.hget("xyz", "ip")
    ip = IPAddr.ntop(packed_ip)
    

    What IPAddr.hton and IPAddr.ntop do is this:

    packed_ip = ip.split('.').map(&:to_i).pack('C4') # hton
    ip = packed_ip.unpack('C4').join('.') # ntop
    

    Then there’s the whole thing about IPv6 and whatnot, but I think IPAddr has you covered there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application will need to reference addresses. Street info will be stored with my
I need to geocode adresses (get lat/long from addresses) using in .Net, to store
I need to store a large (128-bit) PK. Each int will have some corresponding
Are there any best practices (or even standards) to store addresses in a consistent
To fight vote fraud, I need to store IP addresses in my database but
I need to store a bunch of email addresses each having a label (primary
I am a beginner in C++. I need to store list of addresses that
I need to collect and store mailing addresses in a Rails (2.3) app. Is
I am using C#, .NET 4.0, 64-bit. I need to store in memory 500
I need to store IP address in the most compact way possible, searching is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.