0

I have a collection of films, about 150 thousand, and I have several playlists where several films appear several times.

I want to cache movies and playlists on the Redis.

What I needed would be for the playlists to save only references to the movies, so when I retrieve a playlist it will bring the referenced films, but that if I change a movie it will be changed in all playlists.

I didn't want to retrieve the playlist with only ids and then have to retrieve each movie by id again, is there a way to do this directly in one query? as if it were a pointer ...

Thanks!

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
Wilson Neto
  • 353
  • 1
  • 3
  • 6

1 Answers1

2

As I see it you have 2 options:

  1. Writing a lua script that will give you, for a given playlist, all the movies in this playlist. The main disadvantage in this approach is that it will not work on cluster cause the movies might located on different shard then the playlist.
  2. Use RedisGears (https://github.com/RedisGears/RedisGears). In a single python line you can do exactly what you need and it will work perfectly on cluster. It will look something like this (assuming playlist is a redis list of movies located in redis hashes):

    GB().flatmap(lambda r: r).repartition(lambda r:r).map(lambda r: execute('hgetall', r)).run('< playlist_key_name >')

    • flatmap - to have a record per movie
    • repartition - so each movie record will go to the shard where it located
    • map - to perform hgetall and get the movie data
    • run - run will automatically collect all the data from all the shards and return them.
Meir Shpilraien
  • 506
  • 2
  • 4