How to sort the operation by Key

48 views
Skip to first unread message

Andres Arias

unread,
Feb 8, 2015, 4:17:54 PM2/8/15
to redi...@googlegroups.com
--> name:index + key
hset date:20150706 1701 "{id:1, id2:1, id3:1 }"
hset date:20150706 1702 "{id:2, id2:2, id3:2 }"
hset date:20150706 2703 "{id:3, id2:3, id3:3 }"
hset date:20150706 2704 "{id:4, id2:4, id3:4 }"

--> name + key => faster change
hset today 2701 "{id:5, id2:5, id3:5 }"
hset today 2702 "{id:6, id2:6, id3:6 }"

Josiah Carlson

unread,
Feb 9, 2015, 12:37:09 AM2/9/15
to redi...@googlegroups.com
Okay, you basically have 4 options:
1. sort on the client (HKEYS or HGETALL), or with a Lua script (client scales better)
2. have a SET as well as a HASH, add keys to similarly-named sets, use SORT on the sets, cache them if desired/necessary
3. use a sorted set, requires more work, slower to modify, uses more memory, faster to read, can be paginated, requires storing your "value" as the member (maybe with unique prefix), and your "key" as the score
4. hash + sorted set, slow to write, uses worst memory, as fast as #3 to read, can be paginated

I'd go with #1 almost every time, maybe adjusting the max intset size in the Redis config, or #3 if I was okay using more memory (I usually am).

 - 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 http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Andres Arias

unread,
Feb 12, 2015, 12:49:34 PM2/12/15
to redi...@googlegroups.com
My solution was to place a consecutive number at the end To order automatically.

Josiah Carlson

unread,
Feb 12, 2015, 1:08:33 PM2/12/15
to redi...@googlegroups.com
I'm glad you have a solution to your problem, but what did you add a number to?

 - Josiah


On Thu, Feb 12, 2015 at 9:49 AM, Andres Arias <jandr...@gmail.com> wrote:
My solution was to place a consecutive number at the end To order automatically.

--

Andres Arias

unread,
Feb 15, 2015, 10:46:55 AM2/15/15
to redi...@googlegroups.com
No, my solution was in the application, not in redis. Thanks!
Reply all
Reply to author
Forward
0 new messages