Tomasz Rybarczyk avatar Tomasz Rybarczyk committed 5adae0e

Cosmetics

Comments (0)

Files changed (1)

 
 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 an atomic operation - prefered way to do it is to use `execute_update` method which uses 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.execute_update('a', lambda curr_value: dict(curr_value, key='new value'))
-        >>> print rd['a']['key']
-        new value
+* 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 `execute_update` method which uses 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.execute_update('a', lambda curr_value: dict(curr_value, key='new value'))
+    >>> print rd['a']['key']
+    new value
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.