Developing a
memcached
Application
1371
Once installed, the
memcache
module provides a class-based interface to your
memcached
servers.
When you store Python data structures as
memcached
items, they are automatically serialized (turned
into string values) using the Python
cPickle
or
pickle
modules.
To create a new
memcache
interface, import the
memcache
module and create a new instance of the
memcache.Client
class. For example, if the
memcached
daemon is running on localhost using the
default port:
import memcache
memc = memcache.Client(['127.0.0.1:11211'])
The first argument is an array of strings containing the server and port number for each
memcached
instance to use. To enable debugging, set the optional
debug
parameter to 1.
By default, the hashing mechanism used to divide the items among multiple servers is
crc32
. To
change the function used, set the value of
memcache.serverHashFunction
to the alternate function
to use. For example:
from zlib import adler32
memcache.serverHashFunction = adler32
Once you have defined the servers to use within the
memcache
instance, the core functions provide
the same functionality as in the generic interface specification. The following table provides a summary
of the supported functions:
Python
memcache
Function
Equivalent Generic Function
get()
Generic
get()
.
get_multi(keys)
Gets multiple values from the supplied array of
keys
. Returns a hash reference of key/value
pairs.
set()
Generic
set()
.
set_multi(dict [, expiry [,
key_prefix]])
Sets multiple key/value pairs from the supplied
dict
.
add()
Generic
add()
.
replace()
Generic
replace()
.
prepend(key, value [, expiry])
Prepends the supplied
value
to the value of the
existing
key
.
append(key, value [, expiry[)
Appends the supplied
value
to the value of the
existing
key
.
delete()
Generic
delete()
.
delete_multi(keys [, expiry [,
key_prefix]] )
Deletes all the keys from the hash matching each
string in the array
keys
.
incr()
Generic
incr()
.
decr()
Generic
decr()
.
Note
Within the Python
memcache
module, all the
*_multi()
functions support an
optional
key_prefix
parameter. If supplied, then the string is used as a prefix
to all key lookups. For example, if you call:
memc.get_multi(['a','b'], key_prefix='users:')
The function retrieves the keys
users:a
and
users:b
from the servers.
Here is an example showing the storage and retrieval of information to a
memcache
instance, loading
the raw data from MySQL:
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...