back to mc 

memcache.Client

generated from ../src/mod_memcache/client.cpp

This is a client for memcached. You can set variables (only primitive values and strings are allowed) as properties to this class. For example:


   var client = new memcache.Client();
   client.addServer("127.0.0.1", 11211);
   client.user = "Franky"
The code above sets the username into the cache with key 'user'.

Constants

Error Codes

Name Description
OK
NOREPLY
NOTSTORED
NOTFOUND
NOSERVER

Constructor

Client

Client()
 

Creates a new client.

Methods

add

add(Key, 
    Value) : Array
 
Name Type Default Description
Key String
Value Any

Add an item to the cache. This will fail if the item already exists at the server. An array with two elements is returned: first element contains the result, second element contains the number of items with a successful result.

addServer

addServer(Server = localhost) : Boolean
 
Name Type Default Description
Server String localhost The server to be added specified as IP[:PORT]. The port will default to 11211 if not supplied.

Add a server to the client. This method will fail only if the address is not a valid IP address or PORT. It will not fail if the server cannot be contacted but will instead continue to occasionally attempt connections to that server.

append

append(Key, 
       Value) : Array
 
Name Type Default Description
Key String
Value Any

Append data to an existing item in the cache. An array with two elements is returned: first element contains the number of items with a successful result. The second element is another array containing all result codes when an array is passed, or an integer element that contains the result code.

clearServers

clearServers()
 

Disconnect from and remove all servers.

decrement

decrement(Key, 
          Diff, 
          Reply = true) : Array
 
Name Type Default Description
Key String Key to decrement
Diff Integer Positive integer to decrement the value at the server by
Reply Boolean true Should a reply be requested from the server

Decrement a value at the server. When a reply is requested (which is the default), an array with two values is returned: the return code and the new value of the key.

get

get(Key) : String
 
Name Type Default Description
Key String

Gets the value associated to this key in the cache and returns it as a string. 'null' is returned when the key is not found.

increment

increment(Key, 
          Diff, 
          Reply = true) : Array
 
Name Type Default Description
Key String Key to increment
Diff Integer Positive integer to increment the value at the server by
Reply Boolean true Should a reply be requested from the server

Increment a value at the server. When a reply is requested (which is the default), an array with two values is returned: the return code and the new value of the key.

prepend

prepend(Key, 
        Value) : Integer
 
Name Type Default Description
Key String
Value Any

Prepend data to an existing item in the cache.

removeServer

removeServer(Server) : Boolean
 
Name Type Default Description
Server String

Delete a server from the client. The server should be specified as documented in MemCacheClient#addServer.

replace

replace(Key, 
        Value, 
        TimeOut = 0) : Array
 
Name Type Default Description
Key String
Value Any
TimeOut Integer 0 time in seconds for the data to live on the server.
replace(KeyPairValue, 
        TimeOut = 0) : Array
 
Name Type Default Description
KeyPairValue Object
TimeOut Integer 0 time in seconds for the data to live on the server.

Replace an item in the cache. This will fail if the item does not already exist at the server.

set

set(Key, 
    Value, 
    TimeOut = 0) : Array
 
Name Type Default Description
Key String
Value Any
TimeOut Integer 0 time in seconds for the data to live on the server.
set(KeyPairValue, 
    TimeOut = 0) : Array
 
Name Type Default Description
KeyPairValue Object
TimeOut Integer 0 time in seconds for the data to live on the server.

Sets the key in the cache. When you use the second form, each property of the object will be the key and the property value is the value which is cached. When you want to store complex objects, it is recommended to use JSON to generate a String value.


   var client = new memcache.Client();
   client.addServer("127.0.0.1:11211");
   var [n, rc] = client.set({ 
                              FirstName : "Franky", 
                              LastName  : "Braem" 
                            });
   print("Number of keys added: ", n, "\n");
   print("The return code for each key:\n");
   for(i in rc)
   {
     print("Rc: " + rc[i], "\n");
   }
   print("FirstName: ", client.FirstName, "\n");
   print("LastName: ", client.LastName, "\n");




Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.