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)
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
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
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
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))
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)
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)
def put(self, redisdb): key = keynamehelper.create_key_name("customer", self.id) redisdb.hmset(key, self.__dict__)