structures Package

base Module

class stream_framework.storage.redis.structures.base.RedisCache(key, redis=None)[source]

Bases: object

The base for all redis data structures

delete()[source]
get_key()[source]
get_redis()[source]

Only load the redis connection if we use it

key_format = 'redis:cache:%s'
redis

Only load the redis connection if we use it

set_redis(value)[source]

Sets the redis connection

hash Module

class stream_framework.storage.redis.structures.hash.BaseRedisHashCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.base.RedisCache

key_format = 'redis:base_hash_cache:%s'
class stream_framework.storage.redis.structures.hash.FallbackHashCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.hash.RedisHashCache

Redis structure with fallback to the database

get_many(fields, database_fallback=True)[source]
get_many_from_fallback(missing_keys)[source]

Return a dictionary with the serialized values for the missing keys

key_format = 'redis:db_hash_cache:%s'
class stream_framework.storage.redis.structures.hash.RedisHashCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.hash.BaseRedisHashCache

contains(field)[source]

Uses hexists to see if the given field is present

count()[source]

Returns the number of elements in the sorted set

delete_many(fields)[source]
get(field)[source]
get_key(*args, **kwargs)[source]
get_many(fields)[source]
key_format = 'redis:hash_cache:%s'
keys()[source]
set(key, value)[source]
set_many(key_value_pairs)[source]
class stream_framework.storage.redis.structures.hash.ShardedDatabaseFallbackHashCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.hash.ShardedHashCache, stream_framework.storage.redis.structures.hash.FallbackHashCache

class stream_framework.storage.redis.structures.hash.ShardedHashCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.hash.RedisHashCache

Use multiple keys instead of one so its easier to shard across redis machines

contains(field)[source]
count()[source]

Returns the number of elements in the sorted set

delete()[source]

Delete all the base variations of the key

delete_many(fields)[source]
get_key(field)[source]

Takes something like field=”3,79159750” and returns 7 as the index

get_keys()[source]

Returns all possible keys

get_many(fields)[source]
keys()[source]

list all the keys, very slow, don’t use too often

number_of_keys = 10

list Module

class stream_framework.storage.redis.structures.list.BaseRedisListCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.base.RedisCache

Generic list functionality used for both the sorted set and list implementations

Retrieve the sorted list/sorted set by using python slicing

get_results(start, stop)[source]
key_format = 'redis:base_list_cache:%s'
max_length = 100
class stream_framework.storage.redis.structures.list.FallbackRedisListCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.list.RedisListCache

Redis list cache which after retrieving all items from redis falls back to a main data source (like the database)

cache(fallback_results)[source]

Hook to write the results from the fallback to redis

get_fallback_results(start, stop)[source]
get_redis_results(start, stop)[source]

Returns the results from redis

Parameters:
  • start – the beginning
  • stop – the end
get_results(start, stop)[source]

Retrieves results from redis and the fallback datasource

key_format = 'redis:db_list_cache:%s'
overwrite(fallback_results)[source]

Clear the cache and write the results from the fallback

class stream_framework.storage.redis.structures.list.RedisListCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.list.BaseRedisListCache

append(value)[source]
append_many(values)[source]
count()[source]
get_results(start, stop)[source]
key_format = 'redis:list_cache:%s'
max_items = 1000

the maximum number of items the list stores

remove(value)[source]
remove_many(values)[source]
trim()[source]

Removes the old items in the list

sorted_set Module

class stream_framework.storage.redis.structures.sorted_set.RedisSortedSetCache(key, redis=None)[source]

Bases: stream_framework.storage.redis.structures.list.BaseRedisListCache, stream_framework.storage.redis.structures.hash.BaseRedisHashCache

add(score, key)[source]
add_many(score_value_pairs)[source]

StrictRedis so it expects score1, name1

contains(value)[source]

Uses zscore to see if the given activity is present in our sorted set

count()[source]

Returns the number of elements in the sorted set

get_results(start=None, stop=None, min_score=None, max_score=None)[source]

Retrieve results from redis using zrevrange O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.

index_of(value)[source]

Returns the index of the given value

remove_by_scores(scores)[source]
remove_many(values)[source]

values

sort_asc = False
trim(max_length=None)[source]

Trim the sorted set to max length zremrangebyscore