T
Tony Garcia
I was wondering if there is a way to handle reading keys when you don't
know what the keys are, using memcache-client...
know what the keys are, using memcache-client...
I was wondering if there is a way to handle reading keys when you don't
know what the keys are, using memcache-client...
turn on debug in memcached pipe it to your ruby process, parse output,Ben said:Do you mean discovering what keys are stored in the cache or reading the
value of MYSTERY KEYS(tm)?
Ben
Ben said:Do you mean discovering what keys are stored in the cache or reading the
value of MYSTERY KEYS(tm)?
Ben
I need to pass information (for example, an email address) based on user
name from a rails application to a disconnected ruby process through the
cache. The external process has no way to know what users are being
passed to it. I had wanted to use the user name as the key, but it seems
that I can't find the values of current keys in the cache - at least not
with memcache-client.
So far, about the best I've found is to set the cache as a hash:
Cache["users"] = { "user1"=>"(e-mail address removed)",
"user2"=>"(e-mail address removed)" }
Ben said:It sounds like you're trying to use the cache as a message queue, when
you should probably be using both in tandem... that is, store user data
in the cache, but send messages along the queue with the user name, so
the disconnected process can look it up in the cache.
Caching in general (and memcache in particular) are intended to speed up
slow data access, not to act as data repositories.
So far, about the best I've found is to set the cache as a hash:
Cache["users"] = { "user1"=>"(e-mail address removed)",
"user2"=>"(e-mail address removed)" }
If you need to iterate over the usernames and the iterator has no way of
knowing what they are, that's your best bet. Not a great idea, though.
Only the username, email address, and a code are being stored - there
are no messages or other items that need to be passed along.
Granted - and I am using memcache as a queue in this case. I've done a
lot of looking and can't find much else that will do what I need - and
Joyent has memcache already installed.
If anyone has a better suggestion, I'd love to hear it. This is the best
I've been able to figure out on my own.
Ben said:Twitter uses a queue that talks the memcache protocol, but I can't
remember what it's called. Geoffrey Grosenbach recently posted a cool
blog post about message queues, too.
http://nubyonrails.com/articles/about-this-blog-beanstalk-messaging-queue
I think the main problem is that memcache just isn't intended for what
you're trying to do. The hash solution you came up with will get the
job done, but it's a bit of a hack (as we both seem to agree). If it
works though, there's not really any reason to change.
I read that. It's what pointed me toward memcache, actually. Again, part
of the problem is that I'm on a shared Joyent server, and I was trying
to work with what they had. Installing a beanstalk server isn't a very
good option for me at the moment.
My biggest concern is scalability. I'm pretty sure I'm going to have to
change things before too long.
Blaine said:FWIW, we (Twitter) were on Joyent and used Starling (our message queue
that speaks the memcache protocol) there with no problems. All you
need to get started is to do a "gem install starling" and run it with
write permissions to /var/spool/starling (you can specify a different
path since it's unlikely you can write to /var on joyent). Once it's
running, you can use the normal memcache library to connect to <server
ip>:22122 and use set() to put things in the queue and get() to take
them out again.
Hope that helps!
b.
I read that. It's what pointed me toward memcache, actually. Again, part
of the problem is that I'm on a shared Joyent server, and I was trying
to work with what they had. Installing a beanstalk server isn't a very
good option for me at the moment.
Only the username, email address, and a code are being stored - there
are no messages or other items that need to be passed along.
Granted - and I am using memcache as a queue in this case. I've done a
lot of looking and can't find much else that will do what I need - and
Joyent has memcache already installed.
If anyone has a better suggestion, I'd love to hear it. This is the
best
I've been able to figure out on my own.
Ben said:Well, blaine made my point. You can easily install stuff on joyent
Good luck, and report back with what you end up doing.
Ben
memcached is the wrong tool for this purpose. It is intended to be a
cache for some other persistent storage service.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.