0

I have a usecase where data transitions from one state to another.

There are Four values which I can use.

  1. Order number - ( An order has multiple transitions)
  2. Current State
  3. Date of Transition
  4. Previous State.

I need to store the data in such a way that the following condition

  1. Fetch all the transitions for a given order number
  2. From the data fetched, the order of transition should be understood.

I thought of two ways to store it.

Map<Integer, Map<String, Date > >

Where Integer is the outer Key and Status is the inner key. Date is used for the getting the order of transition

or

Map<Integer, Map<String, String > >

Where Integer is the outer Key and current Status is the inner key and its value is previous status.

Which would be a better implementation performance wise. Suggest a better implementation if possible.

And I want to store this data in a distributed cache like redis or aerospike.

Is there a way to store any of the above structures in them? For my use case which would be better redis or aerospike ? Is any other better option available.

Thank You.

(I'm new to both aerospike and redis)

Pardha.Saradhi
  • 468
  • 1
  • 10
  • 27
  • Since every state has a date-of-transition (for the first state, it would be the creation date), you have a Map of orders, containing a list of state-date pairs. So perhaps `Map>>`. The `List<>` is ordered, so it satisfies your second requirement directly. – AJNeufeld Mar 31 '16 at 17:04
  • @AJNeufeld Thanks. So the list sorts on the Date field? If so it solves the structural problem. Any suggestion regarding the redis /aerospike storage? – Pardha.Saradhi Mar 31 '16 at 18:30
  • A `List` does not sort its data; it is an **ordered** collection. If you add data to a list in a particular order, it remains in that order (until changed by other operations). If you sort the data in the list according to some criteria, it will remains in that new order (until changed by other operations). It does not sort itself, it merely retains the order it is given (until changed by other operations). So **you** can sort the `List`, using `Collections.sort(list)` or `Collections.sort(list, comparator)`. Once done, the list will retain your ordered date/status pairs. – AJNeufeld Mar 31 '16 at 18:50
  • 1
    Regarding "suggestions regarding the redis /aerospike storage": **_"Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it."_** – AJNeufeld Mar 31 '16 at 18:53
  • @AJNeufeld As I have mentioned, i'm asking for a way to store the above data structure and whether redis or aerospikes supports it. – Pardha.Saradhi Mar 31 '16 at 19:35

0 Answers0