Exemplo n.º 1
0
    def search(self, redisdb, *keys):
        facets = []
        for k, v in keys:
            fs_key = keynamehelper.create_key_name('fs', k, str(v))
            facets.append(fs_key)

        return redisdb.sinter(facets)
Exemplo n.º 2
0
 def get(self, redisdb, *keys):
     results = []
     for k in keys:
         key = keynamehelper.create_key_name("customer", k)
         for tk in redisdb.scan_iter(key):
             cs = redisdb.hgetall(tk)
             if cs:
                 results.append(customer(cs[b'id'].decode('UTF-8'), 
                                         cs[b'name'].decode('UTF-8')))
             
     return results   
Exemplo n.º 3
0
    def get(cls, sku, redisdb, is_key=False):
        '''
        Get the event from redis db
        '''
        ev = cls(None, None, None, None)
        if is_key:
            key = sku
        else:
            key = keynamehelper.create_key_name('event', sku)

        try:
            ev.__dict__ = json.loads(redisdb.get(key))
            return ev
        except Exception as err:
            logging.error("Failed to load event %s" % sku, err)
            return None
Exemplo n.º 4
0
    def search_greedy(cls, redisdb, *keys):
        '''
        Find all matching keys, retreive value and exeamine
        '''
        matches = []
        key = keynamehelper.create_key_name('event', '*')
        for k in redisdb.scan_iter(key):
            ev = cls.get(k, redisdb, True)
            match = False
            for tk, tv in keys:
                if hasattr(ev, tk) and getattr(ev, tk) == tv:
                    match = True
                else:
                    match = False
                    break

            if match:
                matches.append(ev.sku)

        return matches
Exemplo n.º 5
0
 def put(self, redisdb):
     '''
     Save the event to redis db as json
     '''
     key = keynamehelper.create_key_name('event', self.sku)
     redisdb.set(key, repr(self))
Exemplo n.º 6
0
 def _get_hash_key(self, attr, val):
     hfs = (attr, str(val))
     hashed_val = hashlib.sha256(str(hfs).encode('utf-8')).hexdigest()
     return keynamehelper.create_key_name("hfs", hashed_val)
Exemplo n.º 7
0
 def put(self, entity_id, entity, redisdb):
     for attr in self.lookup_attrs:
         if hasattr(entity, attr):
             fs_key = keynamehelper.create_key_name(
                 'fs', attr, str(getattr(entity, attr)))
             redisdb.sadd(fs_key, entity_id)
Exemplo n.º 8
0
 def put(self, redisdb):
     key = keynamehelper.create_key_name("customer", self.id)
     redisdb.hmset(key, self.__dict__)