Proper NoSQL data schema for web photo gallery

后端 未结 3 1213
感动是毒
感动是毒 2021-02-01 19:57

I\'m looking to build an appropriate data structure for NoSQL storage of a photo gallery. In my web application, a photo can be part of 1 or more albums. I have experience with

3条回答
  •  无人及你
    2021-02-01 20:29

    Redis can handle this. For the RMDBS table you mentioned above:

    SET photos:photo_id:title "some photos title words"
    SET photos:photo_id:date_uploaded "some uploaded time (2011-02-09 HH:MM:SS for example)"
    SET photos:photo_id:filename "some filename words"

    SET albums:album_id:title "some album title words"

    SADD album_photo_map:photo_id album_id

    Use a List(Redis suports list) to store last uploaded photos and update the list when a new photo is uploaded:

    ret = r.lpush("upload:last_upload_times", photo_id) // update list
    ret = r.ltrim("upload:last_upload_times", 0, N-1) // control list length

    then, if we want to get the last uploaded N photos with album data:

    last_uploaded_photo_list = r.lrange("upload:last_upload_times", 0, N-1) last_uploaded_photo_with_album_list = [(photo_id, album_id) for photo_id in last_uploaded_photo_list for album_id in r.smembers(photo_id)]

提交回复
热议问题