Do hkeys and hvals have a stable iteration order ?

524 views
Skip to first unread message

ccollie

unread,
May 21, 2010, 6:53:06 PM5/21/10
to Redis DB
I'm developing an object mapper using hashes, and id like to save some
bandwidth on fetches.
In other words, id prefer to perform a hkeys at the beginning of the
process, and use hvals in
subsequent calls, rather than using hgetall to map fields to values.

It would help to know whether hvals(key)[i] == hget(key, hkeys(key)
[i])


j

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Konstantin Merenkov

unread,
May 21, 2010, 7:09:48 PM5/21/10
to redi...@googlegroups.com
On Sat, May 22, 2010 at 2:53 AM, ccollie <gbo...@gmail.com> wrote:
> I'm developing an object mapper using hashes, and id like to save some
> bandwidth on fetches.
> In other words, id prefer to perform a hkeys at the beginning of the
> process, and use hvals in
> subsequent calls, rather than using hgetall to map fields to values.
>
> It would help to know whether hvals(key)[i] == hget(key, hkeys(key)
> [i])

Do you really need few bytes saved? Just perform HGETALL when you need
to fetch values for your object.
Come on you are not gaining anything that way.


--
Best Regards,
Konstantin Merenkov

Salvatore Sanfilippo

unread,
May 21, 2010, 7:31:22 PM5/21/10
to redi...@googlegroups.com
On Sat, May 22, 2010 at 12:53 AM, ccollie <gbo...@gmail.com> wrote:
> I'm developing an object mapper using hashes, and id like to save some
> bandwidth on fetches.
> In other words, id prefer to perform a hkeys at the beginning of the
> process, and use hvals in
> subsequent calls, rather than using hgetall to map fields to values.
>
> It would help to know whether hvals(key)[i] == hget(key, hkeys(key)
> [i])

Hello, there is no such a guarantee. Most of the times this will be
true, but you can't depend on that behavior as it's not guaranteed.
Note also that as long as something will with a single TCP packet
there will be no noticeable speed diference in this context...

Cheers,
Salvatore

>
> j
>
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
>
>



--
Salvatore 'antirez' Sanfilippo
http://invece.org

"Once you have something that grows faster than education grows,
you’re always going to get a pop culture.", Alan Kay

ccollie

unread,
May 21, 2010, 10:26:37 PM5/21/10
to Redis DB
Another (somewhat related) question...

At what point is a zipmap converted to a regular hash ? Is it when the
number of keys reach a threshold ?

On May 21, 7:31 pm, Salvatore Sanfilippo <anti...@gmail.com> wrote:
> On Sat, May 22, 2010 at 12:53 AM, ccollie <gbo...@gmail.com> wrote:
> > I'm developing an object mapper using hashes, and id like to save some
> > bandwidth on fetches.
> > In other words, id prefer to perform a hkeys at the beginning of the
> > process, and use hvals in
> > subsequent calls, rather than using hgetall to map fields to values.
>
> > It would help to know whether hvals(key)[i] == hget(key, hkeys(key)
> > [i])
>
> Hello, there is no such a guarantee. Most of the times this will be
> true, but you can't depend on that behavior as it's not guaranteed.
> Note also that as long as something will with a single TCP packet
> there will be no noticeable speed diference in this context...
>
> Cheers,
> Salvatore
>
>
>
> > j
>
> > --
> > You received this message because you are subscribed to the Google Groups "Redis DB" group.
> > To post to this group, send email to redi...@googlegroups.com.
> > To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/redis-db?hl=en.
>
> --
> Salvatore 'antirez' Sanfilippohttp://invece.org
>
> "Once you have something that grows faster than education grows,
> you’re always going to get a pop culture.", Alan Kay
>
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/redis-db?hl=en.

Konstantin Merenkov

unread,
May 22, 2010, 1:19:22 AM5/22/10
to redi...@googlegroups.com
On Sat, May 22, 2010 at 6:26 AM, ccollie <gbo...@gmail.com> wrote:
> Another (somewhat related) question...
>
> At what point is a zipmap converted to a regular hash ? Is it when the
> number of keys reach a threshold ?

Yes it is a configurable threshold named "hash_max_zipmap_entries".
If some value's length is longer than "hash_max_zipmap_value", then
conversion takes place as well.
--
Best Regards,
Konstantin Merenkov

Reply all
Reply to author
Forward
0 new messages