Example #1
0
def ask(subj, predicate="*", obj='*'):
    if '*' not in (subj, predicate, obj):
        return redis.sismember('r:%s:%s' % (subj, predicate), obj)
    
    if subj == predicate == obj == '*':
        raise RuntimeError('ask() cannot query in the form "* * *".')
    if subj == obj == '*':
        raise RuntimeError('ask() cannot query in the form "* <predicate> *".')
    
    if subj == predicate == '*':
        return set(tuple(x.split(':')) for x in redis.smembers('n:%s:obj' % obj))
    if obj == predicate == '*':
        return set(tuple(x.split(':')) for x in redis.smembers('n:%s:subj' % subj))
    
    if subj == '*':
        return redis.smembers("r:%s:%s" % (obj, predicate))
    if predicate == '*':
        return redis.smembers("r:%s::%s" % (obj, subj))
    if obj == '*':
        return redis.smembers('r:%s:%s' % (subj, predicate))
Example #2
0
def get_types():
    result = {
        'type': get_type_type()
    }
    for slug in redis.smembers('types'):
        src = redis.get('n:type:' + slug)
        if src is None:
            redis.srem('types', slug)
        else:
            result[slug] = json.loads(src)
    return result