Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

redis-dict

Really tiny wrapper around redis hash which serializes values (by default it uses pickle).

USAGE

KEYS

RedisDict accepts only str instances as keys - it is impossible relly on Python __hash__ function as its value can differ on different machines (for example hash(None) is derived from None object id).

UPDATING VALUES

RedisDict.update_value and RedisDict.update

If you store mutable objects and want to update them you have to be careful:

  • you have to explicite overwrite value in RedisDict instance:

        >>> import redis_dict, redis
        >>> connection = redis.Redis()
        >>> rd = redis_dict.RedisDict('new-dict', connection)
        >>> rd['a'] = {'key': 'value'}
        >>> a = rd['a']
        >>> # this call doesn't affects redis state
        >>> a['key'] = 'new value'
        >>> print rd['a']['key']
        value
        >>> # you have to explicite override
        >>> rd['a'] = a
        >>> print rd['a']['key']
        new value
    
  • such an update is not atomic operation - prefered way to do it is to use update_value or update - both methods use redis transactions (WATCH and MULTI) to ensure atomicity of operation:

        >>> import redis_dict, redis
        >>> connection = redis.Redis()
        >>> rd = redis_dict.RedisDict('new-dict', connection)
        >>> rd['a'] = {'key': 'value'}
        >>> # updater receives current value and should return new value
        >>> rd.update_value('a', lambda curr_value: dict(curr_value, key='new value'))
        >>> print rd['a']['key']
        new value
    

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.