I'm at a point where I could store a resource in Redis as either hash or RedisJSON. My particular data in this instance is are temporary data objects consisting of several string and numeric fields each. A user will invoke a process which creates a structure like:
{
'item_id': 'k0f8h3n5m6n1w9d0k0k1m1n4b6c8f8r7'
'amount': 3.00042
'timestamp': 1590440708,
'user1_status': 'pending',
'user_2_status': 'completed'
}
This is effectively a client-user-processed queue (The queuing is handled by a separate Redis stream) wherein each object will remain used (As a hash or RedisJSON object) for an average of about 1 hour. At any given time, there will be tens of thousands of these objects in the queue. While in the queue, the object's fields (Such as user1_status
and user2_status
) will be updated several times.
Once each object is done being processed, I could either leave it in Redis or move each object to a cold storage database for log-keeping and delete from Redis. I'm not sure if I should do that or just leave it.
Which Redis data type (Hash or RedisJSON) would be more appropriate for my task? What are some of the general considerations in deciding between these two types?
Note: I realize that if I want to do something like this:
{
'item_id': 'k0f8h3n5m6n1w9d0k0k1m1n4b6c8f8r7'
'amount': 3.00042
'timestamp': 1590440708,
'user1_status': 'pending',
'user_2_status': 'completed'
'parent': {
'item1': 1,
'item2': [1, 2, 3, 4]
'item3': {
'one': 1,
'two': 2
}
}
}
RedisJSON would probably be the right choice because you have to flatten any object before storing it as a hash. For the sake of this question, assume I don't need to do that since I already know about it.