Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using redis-rb and mapped_mget()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mason Jones  
View profile  
 More options Jan 28 2010, 5:53 pm
From: Mason Jones <masono...@gmail.com>
Date: Thu, 28 Jan 2010 14:53:52 -0800
Local: Thurs, Jan 28 2010 5:53 pm
Subject: Using redis-rb and mapped_mget()
I have a quick question about using the redis-rb client and its
mapped_mget() method... I've looked through the source to see how it
might be used, and I've found what seems like some unexpected
behavior. It may be that there's a different way to do this, but if
not I can look at potentially patching it if it seems like an
improvement.

After getting a bunch of keys from set 'objects' (just for example purposes):

redis.sort('objects', { :limit => [ offset, per_page ])

I then want to turn around and use mget to grab the details of the
items. I also want the keys for each one, and it seems that
mapped_mget() is for this purpose? So I tried:

p = r.mapped_mget(r.sort('objects', { :limit => [0, 5]}))

Unfortunately, it looks as though mapped_mget() will only take a list
of keys, not an array? What I get back is:

p.keys
=> [["object:5459789:data", "object:5893120:data",
"object:7232572:data", "object:7312762:data", "object:5235635:data"],
nil]

The array itself is returned as the first key, followed by nil. But if
I do this:

p = r.mapped_mget("object:5459789:data", "object:5893120:data")
p.keys
=> ["object:5459789:data", "object:5893120:data"]

That works as expected, with each key mapped to its value.

Does it seem reasonable to expect that mapped_mget() could take an
array, and then the results of a set() call can be passed directly in,
as I showed above?

Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Kahn  
View profile  
 More options Mar 25 2010, 11:07 am
From: Alex Kahn <alexanderk...@gmail.com>
Date: Thu, 25 Mar 2010 08:07:43 -0700 (PDT)
Local: Thurs, Mar 25 2010 11:07 am
Subject: Re: Using redis-rb and mapped_mget()
Hi Mason,

You're right: mapped_mget takes a series of key arguments, rather than
an array. But you can convert from an array to a list of arguments
with Ruby's * (splat) operator. So if you have key1 => value1 and key2
=> value2 in Redis, and you have the Ruby array: keys = ['key1',
'key2'], you need to do:

r.mapped_mget(*keys)

Ruby will "expand" the array into a list of arguments. That should get
you the result you desire.

It might be smart for redis-rb to raise an error if mapped_mget
receives an array argument, since it will not behave as expected in
this case. Maybe this is something Ezra, the redis-rb author, would
accept a patch for.

Cheers,
Alex

On Jan 28, 6:53 pm, Mason Jones <masono...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »