| Trees | Indices | Help |
|
|---|
|
|
object --+
|
thread._local --+
|
Client
Object representing a pool of memcache servers.
See memcache for an overview.
In all cases where a key is used, the key can be either:
(hashvalue, key). This is useful if you want
to avoid making this module calculate a hash value. You may prefer,
for example, to keep all of a given user's objects on the same
memcache server, so you could use the user's unique id as the hash
value.
| Nested Classes | |
| MemcachedKeyError | |
| MemcachedKeyLengthError | |
| MemcachedKeyCharacterError | |
| MemcachedStringEncodingError | |
| Instance Methods | |||
|
|||
|
|||
|
Inherited from Inherited from |
|||
| Setup | |||
|---|---|---|---|
|
|||
|
|||
|
|||
|
|||
|
|||
| Insertion | |||
| int |
|
||
| list |
|
||
| int |
|
||
| int |
|
||
| Retrieval | |||
|
|||
|
|||
| Integers | |||
| int |
|
||
| int |
|
||
| Removal | |||
| int |
|
||
| int |
|
||
| Properties | |
|
Inherited from |
| Method Details |
Create a new Client object with the given list of servers.
|
Set the pool of servers used by this client.
|
Unconditionally sets a key to a given value in the memcache. The
|
Sets multiple keys in the memcache doing just one query. >>> notset_keys = mc.set_multi({'key1' : 'val1', 'key2' : 'val2'}) >>> mc.get_multi(['key1', 'key2']) == {'key1' : 'val1', 'key2' : 'val2'} 1 This method is recommended over regular set as it lowers the number of total packets flying around your network, reducing total latency, since your app doesn't have to wait for each round-trip of set before sending the next one.
|
Add new key with value. Like set, but only stores in memcache if the key doesn't already exist.
|
Replace existing key with value. Like set, but only stores in memcache if the key already exists. The opposite of add.
|
Retrieves a key from the memcache.
|
Retrieves multiple keys from the memcache doing just one query. >>> success = mc.set("foo", "bar") >>> success = mc.set("baz", 42) >>> mc.get_multi(["foo", "baz", "foobar"]) == {"foo": "bar", "baz": 42} 1 >>> mc.set_multi({'k1' : 1, 'k2' : 2}, key_prefix='pfx_') == [] 1 This looks up keys 'pfx_k1', 'pfx_k2', ... . Returned dict will just have unprefixed keys 'k1', 'k2'. >>> mc.get_multi(['k1', 'k2', 'nonexist'], key_prefix='pfx_') == {'k1' : 1, 'k2' : 2} 1 get_mult [ and set_multi ] can take str()-ables like ints / longs as keys too. Such as your db pri key fields. They're rotored through str() before being passed off to memcache, with or without the use of a key_prefix. In this mode, the key_prefix could be a table name, and the key itself a db primary key number. >>> mc.set_multi({42: 'douglass adams', 46 : 'and 2 just ahead of me'}, key_prefix='numkeys_') == [] 1 >>> mc.get_multi([46, 42], key_prefix='numkeys_') == {42: 'douglass adams', 46 : 'and 2 just ahead of me'} 1 This method is recommended over regular get as it lowers the number of total packets flying around your network, reducing total latency, since your app doesn't have to wait for each round-trip of get before sending the next one. See also set_multi.
|
Sends a command to the server to atomically increment the value for
Note that the value for >>> mc.set("counter", "20") # returns 1, indicating success 1 >>> mc.incr("counter") 21 >>> mc.incr("counter") 22 Overflow on server is not checked. Be aware of values approaching 2**32. See decr.
|
Like incr, but decrements. Unlike incr, underflow is checked and new values are capped at 0. If server value is 1, a decrement of 2 returns 0, not -1.
|
Deletes a key from the memcache.
|
Delete multiple keys in the memcache doing just one query. >>> notset_keys = mc.set_multi({'key1' : 'val1', 'key2' : 'val2'}) >>> mc.get_multi(['key1', 'key2']) == {'key1' : 'val1', 'key2' : 'val2'} 1 >>> mc.delete_multi(['key1', 'key2']) 1 >>> mc.get_multi(['key1', 'key2']) == {} 1 This method is recommended over iterated regular deletes as it reduces total latency, since your app doesn't have to wait for each round-trip of delete before sending the next one.
|
Get statistics from each of the servers.
|
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Jun 27 12:35:57 2008 | http://epydoc.sourceforge.net |