Beispiel #1
0
 def set_tf(self, term, doc_id, frequency):
     """
     Set tf data for (term, doc_id) pair
     :param term: term to set tf data for
     :param doc_id: document to set tf data for
     :param frequency: data to put in the hash for the (term, doc_id) pair
     """
     key = self._tf_key(term)
     term_data = RedisHash(key)
     term_data.set(doc_id, frequency)
Beispiel #2
0
 def get_tf(self, term, doc_id=None):
     """
     Get term frequency data for term
     :param term: term to get tf data for
     :param doc_id: (optional) provide doc_id to only get tf data for the associated document
     :return: dict containing tf_data
     """
     key = self._tf_key(term)
     if doc_id is None:
         return RedisHash(key).to_dict()
     return RedisHash(key).get(doc_id)
Beispiel #3
0
 def create_user(self, email):
     session_id = self.redis.get_value("usersession: {}".format(email))
     user_data = RedisHash(email).to_dict()
     if session_id and user_data:
         return User(user_data['school'], email, user_data['displayName'],
                     session_id)
     return None
Beispiel #4
0
 def get_content(content_id):
     """
     Get content data for content with given ID
     :param content_id: ID of content
     :return: dict containing content data
     """
     return RedisHash(content_id).to_dict()
Beispiel #5
0
 def content_exists(identifier):
     """
     Checks if content with specified ID exists.
     :param identifier: ID of content to check for
     :return: boolean indicating if content exists or not
     """
     return RedisHash(identifier).exists()
Beispiel #6
0
 def delete(self, ip_address, key_to_delete):
     """
     Removes (key, value) pair from IP address hash
     :param ip_address: IP address of cached data
     :param key_to_delete: key to delete
     """
     ip_address_key = self._get_key_for(ip_address)
     return RedisHash(ip_address_key).delete(key_to_delete)
Beispiel #7
0
 def set(self, ip_address, data):
     """
     Sets cached data for given IP address
     :param ip_address: IP address to set cached data for
     :param data: data to set in cache
     """
     key = self._get_key_for(ip_address)
     return RedisHash(key).update(data)
Beispiel #8
0
 def get(self, ip_address):
     """
     Returns cached data for IP address
     :param ip_address: IP address to get cached data for
     :return: dict containing cached data
     """
     key = self._get_key_for(ip_address)
     return RedisHash(key).to_dict()
Beispiel #9
0
 def get_request(self, request_id):
     """
     Retrieves request with ID request_id.
     :param request_id: ID of request to find
     :return: dict containing request data
     """
     app.logger.debug("fetching request with id: {}".format(request_id))
     request_data = RedisHash(request_id).to_dict()
     app.logger.debug("request id {} has data {}".format(
         request_id, request_data))
     return request_data
Beispiel #10
0
 def request_content(self, identifier, data):
     """
     Creates new redis hash with specified data representing a user request to create content.
     :param identifier: string identifier for hash in redis
     :param data: request data
     :return: string identifier if operation is successful, otherwise None
     """
     user_manager.created_content(data["email"], identifier)
     data.update({"requestType": self.type, "time": get_time()})
     app.logger.debug("Storing {} in {}".format(data, identifier))
     if RedisHash(identifier).update(data) is not None:
         return identifier
Beispiel #11
0
 def make_content(self, identifier, data):
     """
     Creates new redis hash with specified data representing some type of user-created content.
     :param identifier: string identifier for hash in redis
     :param data: content data
     :return: string identifier if operation is successful, otherwise None
     """
     user_manager.created_content(data["email"], identifier)
     data.update({"postType": self.type})
     app.logger.debug("Storing {} in {}".format(data, identifier))
     if RedisHash(identifier).update(data) is not None:
         return identifier
Beispiel #12
0
 def store_user_in_redis(self, email, password_hash, school, display_name):
     self.emails.add(email)
     self.displayNames.add(display_name)
     user_data = {'school': school, 'displayName': display_name}
     RedisHash(email).update(user_data)
     self.redis.set("hash: {}".format(email), password_hash)