class_docstr: This DataStore sends policies over redis pubsub and get/set.
  
  Deployment
  ==========
  It assumes that a redis server is already available. We make this assumption because during
  multinode training at this time, redis is already used for communicating replay memories.
  
  Communication
  =============
  
  A redis pubsub channel is used by the training worker to signal to the rollout workers that a
  new policy is ready. When this occurs, a new policy is loaded from the redis key/value store
  where key is the same as the pubsub channel. Originally, just the pubsub was used, but that
  could result in a race condition where the master worker publishes the first policy and waits
  for the rollout workers to submit all rollouts, while a delayed rollout worker waits for the
  first policy since it subscribed to the channel after the initial policy was published.
class_docstr_tok: ["This","DataStore","sends","policies","over","redis","pubsub","and","get\/set",".","Deployment","==========","It","assumes","that","a","redis","server","is","already","available",".","We","make","this","assumption","because","during","multinode","training","at","this","time",",","redis","is","already","used","for","communicating","replay","memories",".","Communication","=============","A","redis","pubsub","channel","is","used","by","the","training","worker","to","signal","to","the","rollout","workers","that","a","new","policy","is","ready",".","When","this","occurs",",","a","new","policy","is","loaded","from","the","redis","key\/value","store","where","key","is","the","same","as","the","pubsub","channel",".","Originally",",","just","the","pubsub","was","used",",","but","that","could","result","in","a","race","condition","where","the","master","worker","publishes","the","first","policy","and","waits","for","the","rollout","workers","to","submit","all","rollouts",",","while","a","delayed","rollout","worker","waits","for","the","first","policy","since","it","subscribed","to","the","channel","after","the","initial","policy","was","published","."]
docstr: Serialize the policy in graph_manager, set it as the latest policy and publish a new_policy
  event
docstr_tok: ["Serialize","the","policy","in","graph_manager",",","set","it","as","the","latest","policy","and","publish","a","new_policy","event"]
code: def save_policy(self, graph_manager):
      """
      Serialize the policy in graph_manager, set it as the latest policy and publish a new_policy
      event
      """
      if self.saver is None:
          self.saver = GlobalVariableSaver()
  
          # TODO: only subscribe if this data store is being used to publish policies
          self._connect()
          self.pubsub.unsubscribe(self.params.redis_channel)
  
      policy_string = self.saver.to_string(graph_manager.sess)
      self.redis_connection.set(
          self.params.redis_channel, policy_string
      )
      self.redis_connection.publish(
          self.params.redis_channel, "new_policy"
      )
  
file_path: coach/rl_coach/data_stores/redis_data_store.py
imports: import time
  import uuid
  import redis
  from rl_coach.architectures.tensorflow_components.savers import GlobalVariableSaver
  from rl_coach.data_stores.data_store import DataStore, DataStoreParameters
label_desc: Use image node_id 7 for calling the RedisDataStore obj's underlying member method code with example usage: obj.save_policy(graph_manager) without return types