Knowing how you plan to use this data later would help in recommending
the exact approach, since of course putting data in is only half the
problem!
> --
> 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.
>
>
You are probably better off using the native Redis list rather than
using Ruby's marshalling, as your entire function could be replaced
with a single LPUSH. To get your list of logins for a user, along
with the user data would require 2 commands, but you can do that with
a pipeline.
- Josiah
LRANGE key 0 -1
> are ou recommending that I put the person's name in a "hash" inside of
> the list, so something like
> user_hits is the redis list. Then each item is {:login =>
> 'foo', :time > Time.now}
You can do that by marshalling your hashes into a list item (because
Redis doesn't support nested structures), but there would be a lot of
wasted space with all of the 'login' and 'time' and actual login
names. No, what I'm suggesting is you use...
LPUSH login_times:<user> <current time>
If you want to get the most recent 10 login times for one user:
LRANGE login_times:<user> 0 9
You can't see system-wide who has logged in the latest with this
simple method, but if you add a single zset...
ZADD login_times <current time> <user>
Then you can fetch the most recent login times for all users with:
ZRANGE login_times 0 -1 WITHSCORES
Or you can find out the most recent 10 logged-in users with:
ZREVRANGE login_times 0 9 WITHSCORES
> How would I query for a login name?
See the above use of LRANGE.
> I was also thinking about trying to store a list inside a hash in
> native redis commands, but I didn't see how I could do that.
You can't, Redis currently only supports non-nested structures.
- Josiah