List of dictations in Redis

How to save a list of dicts in Redis against a key using Python-redis. The following is the data structure I'm aiming for:

'browsing_history' : { 'session_key_1' : [{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}, {''image': 'image-url2', 'url' : 'url2', 'title' : 'test_title2', 'description' : 'test_description2'}], 'session_key_2' : [{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}, {''image': 'image-url2', 'url' : 'url2', 'title' : 'test_title2', 'description' : 'test_description2'}], } 

I would like to add to the lists of sessions, as well as add new sessions, as well as extract them. How can I do this using Python-redis?

+4
source share
1 answer

Serialize the dictionary {'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'} using pickle or json . Use the redis list to save them as strings. Use keys such as browsing_history:SESSION_KEY_1 to access these lists. If you need to get a list of all session keys, you probably need to maintain a rowset for browsing_history:* keys.

+7
source

Source: https://habr.com/ru/post/1388413/


All Articles