Secondary Indexes : Using numbers in binary form

44 views
Skip to first unread message

Sune Kibsgaard

unread,
Jan 17, 2016, 3:57:56 PM1/17/16
to Redis DB
Hi,

I am planning on using Redis for a fast index using the sorted set datatype, and I have been reading up on the topic, especially using the

I have a question about using the numbers in binary form to save memory, described about halfway down the page. I am new in big endian, and
byte representation of decimal numbers, and have googled myself to insanity :)

I want to store bigdecimals in the sorted set, with the same score, so i can use lexrange features. It mentions that one can use
big endian format for saming memory, but with the cost of easy debugging. Do any of you have an example (ruby or js preferably)
on how to convert numbers (floats) in decimal to this byte format, and back again, or point me to an article that explains this for
a newbie in this area.

Thanks

Josiah Carlson

unread,
Jan 17, 2016, 7:04:50 PM1/17/16
to redi...@googlegroups.com
Arbitrarily large or small decimal floating point numbers are tough. I don't have experience with BigDecimal, but Python's got an arbitrary-precision decimal module that I have packed for similar comparisons outside of Redis:

Long story short: it may be a bit of work.

 - Josiah


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Sune Kibsgaard

unread,
Jan 18, 2016, 9:53:30 AM1/18/16
to Redis DB
Thanks!

I figured i just store the numbers in base10 with fixed padding in both ends, it should be okay for now

Dvir Volk

unread,
Jan 18, 2016, 10:33:09 AM1/18/16
to Redis DB
I've used the method in this library for encoding floating point numbers in secondary indexes for the exact same purpose:

(translated it to go BTW)

I haven't tested it with edge cases but it works just fine for my needs.

jerome

unread,
Jan 18, 2016, 6:16:08 PM1/18/16
to Redis DB
Check out 20.2.3 - Endianness, of "Exploring ES6".
Reply all
Reply to author
Forward
0 new messages