Developing a
memcached
Application
1376
Or to retrieve the value:
print memc["key"]
For more explicit actions, you can use the method interface, which mimics the main
memcached
API
functions, as summarized in the following table:
Ruby
MemCache
Method
Equivalent
memcached
API Functions
get()
Generic
get()
.
get_hash(keys)
Get the values of multiple
keys
, returning the
information as a hash of the keys and their values.
set()
Generic
set()
.
set_many(pairs)
Set the values of the keys and values in the hash
pairs
.
add()
Generic
add()
.
replace()
Generic
replace()
.
delete()
Generic
delete()
.
incr()
Generic
incr()
.
decr()
Generic
decr()
.
15.6.3.8. Using MySQL and
memcached
with Java
The
com.danga.MemCached
class within Java provides a native interface to
memcached
instances.
You can obtain the client from
http://whalin.com/memcached/
. The Java class uses hashes that are
compatible with
libmemcached
, so you can mix and match Java and
libmemcached
applications
accessing the same
memcached
instances. The serialization between Java and other interfaces are
not compatible. If this is a problem, use JSON or a similar nonbinary serialization format.
On most systems, you can download the package and use the
jar
directly.
To use the
com.danga.MemCached
interface, you create a
MemCachedClient
instance and then
configure the list of servers by configuring the
SockIOPool
. Through the pool specification you set up
the server list, weighting, and the connection parameters to optimized the connections between your
client and the
memcached
instances that you configure.
Generally, you can configure the
memcached
interface once within a single class, then use this
interface throughout the rest of your application.
For example, to create a basic interface, first configure the
MemCachedClient
and base
SockIOPool
settings:
public class MyClass {
protected static MemCachedClient mcc = new MemCachedClient();
static {
String[] servers =
{
"localhost:11211",
};
Integer[] weights = { 1 };
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( servers );
pool.setWeights( weights );
In the above sample, the list of servers is configured by creating an array of the
memcached
instances
to use. You can then configure individual weights for each server.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...