C# Class MemcachedClientLibrary.MemcachedClient

Memcached client main class. Use the static methods Setup and GetInstance to setup and get an instance of the client for use.
Afficher le fichier Open project: noear/Weed3 Class Usage Examples

Méthodes publiques

Свойство Type Description
Name string

Méthodes publiques

Méthode Description
Add ( string key, object value ) : bool

This method corresponds to the "add" command in the memcached protocol. It will set the given key to the given value only if the key does not already exist. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully added.

Add ( string key, object value, System.DateTime expiry ) : bool
Add ( string key, object value, System.TimeSpan expiry ) : bool
Add ( string key, object value, uint hash ) : bool
Add ( string key, object value, uint hash, System.DateTime expiry ) : bool
Add ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
Append ( string key, object value ) : bool

This method corresponds to the "append" command in the memcached protocol. It will append the given value to the given key, if the key already exists. Modifying a key with this command will not change its expiry time. Using the overload it is possible to specify a custom hash to override server selection.

Append ( string key, object value, uint hash ) : bool
CheckAndSet ( string key, object value, System.DateTime expiry, ulong unique ) : CasResult
CheckAndSet ( string key, object value, System.TimeSpan expiry, ulong unique ) : CasResult
CheckAndSet ( string key, object value, uint hash, System.DateTime expiry, ulong unique ) : CasResult
CheckAndSet ( string key, object value, uint hash, System.TimeSpan expiry, ulong unique ) : CasResult
CheckAndSet ( string key, object value, uint hash, ulong unique ) : CasResult
CheckAndSet ( string key, object value, ulong unique ) : CasResult
Decrement ( string key, ulong value ) : ulong?

This method corresponds to the "decr" command in the memcached protocol. It will decrease the item with the given value and return the new value. If the new value would be less than 0, it will be set to 0, and the method will return 0. It will return null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.

Decrement ( string key, ulong value, uint hash ) : ulong?
Delete ( string key ) : bool

This method corresponds to the "delete" command in the memcache protocol. It will immediately delete the given key and corresponding value. Use the overloads to specify an amount of time the item should be in the delete queue on the server, or to specify a custom hash to override server selection.

Delete ( string key, System.DateTime delay ) : bool
Delete ( string key, System.TimeSpan delay ) : bool
Delete ( string key, uint hash ) : bool
Delete ( string key, uint hash, System.DateTime delay ) : bool
Delete ( string key, uint hash, System.TimeSpan delay ) : bool
Exists ( string name ) : bool

Static method which checks if a given named MemcachedClient instance exists.

FlushAll ( ) : bool

This method corresponds to the "flush_all" command in the memcached protocol. When this method is called, it will send the flush command to all servers, thereby deleting all items on all servers. Use the overloads to set a delay for the flushing. If the parameter staggered is set to true, the client will increase the delay for each server, i.e. the first will flush after delay*0, the second after delay*1, the third after delay*2, etc. If set to false, all servers will flush after the same delay. It returns true if the command was successful on all servers.

FlushAll ( System.TimeSpan delay ) : bool
FlushAll ( System.TimeSpan delay, bool staggered ) : bool
Get ( string key ) : object

This method corresponds to the "get" command in the memcached protocol. It will return the value for the given key. It will return null if the key did not exist, or if it was unable to retrieve the value. If given an array of keys, it will return a same-sized array of objects with the corresponding values. Use the overload to specify a custom hash to override server selection.

Get ( string key, uint hash ) : object
Get ( string keys ) : object[]

This method executes a multi-get. It will group the keys by server and execute a single get for each server, and combine the results. The returned object[] will have the same size as the given key array, and contain either null or a value at each position according to the key on that position.

Get ( string keys, uint hashes ) : object[]
GetCounter ( string key ) : ulong?

This method returns the value for the given key as a ulong?, a nullable 64-bit unsigned integer. It returns null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.

GetCounter ( string key, uint hash ) : ulong?
GetCounter ( string keys ) : ulong?[]
GetCounter ( string keys, uint hashes ) : ulong?[]
GetInstance ( ) : MemcachedClient
GetInstance ( string name ) : MemcachedClient

Static method for getting an instance. This method will first check for named instances that has been set up programmatically. If no such instance exists, it will check the "beitmemcached" section of the standard config file and see if it can find configuration info for it there. If that also fails, an exception is thrown.

Gets ( string key, uint hash, ulong &unique ) : object
Gets ( string key, ulong &unique ) : object

This method corresponds to the "gets" command in the memcached protocol. It works exactly like the Get method, but it will also return the cas unique value for the item.

Gets ( string keys, uint hashes, ulong &uniques ) : object[]
Gets ( string keys, ulong &uniques ) : object[]

This method does a multi-gets. It functions exactly like the multi-get method, but it will also return an array of cas unique values as an out parameter.

Increment ( string key, ulong value ) : ulong?

This method corresponds to the "incr" command in the memcached protocol. It will increase the item with the given value and return the new value. It will return null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.

Increment ( string key, ulong value, uint hash ) : ulong?
Prepend ( string key, object value ) : bool

This method corresponds to the "prepend" command in the memcached protocol. It will prepend the given value to the given key, if the key already exists. Modifying a key with this command will not change its expiry time. Using the overload it is possible to specify a custom hash to override server selection.

Prepend ( string key, object value, uint hash ) : bool
Replace ( string key, object value ) : bool

This method corresponds to the "replace" command in the memcached protocol. It will set the given key to the given value only if the key already exists. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully replaced.

Replace ( string key, object value, System.DateTime expiry ) : bool
Replace ( string key, object value, System.TimeSpan expiry ) : bool
Replace ( string key, object value, uint hash ) : bool
Replace ( string key, object value, uint hash, System.DateTime expiry ) : bool
Replace ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
Set ( string key, object value ) : bool

This method corresponds to the "set" command in the memcached protocol. It will unconditionally set the given key to the given value. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully set.

Set ( string key, object value, System.DateTime expiry ) : bool
Set ( string key, object value, System.TimeSpan expiry ) : bool
Set ( string key, object value, uint hash ) : bool
Set ( string key, object value, uint hash, System.DateTime expiry ) : bool
Set ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
SetCounter ( string key, ulong value ) : bool

This method sets the key to the given value, and stores it in a format such that the methods Increment and Decrement can be used successfully on it, i.e. decimal representation of a 64-bit unsigned integer. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the counter was successfully set.

SetCounter ( string key, ulong value, System.DateTime expiry ) : bool
SetCounter ( string key, ulong value, System.TimeSpan expiry ) : bool
SetCounter ( string key, ulong value, uint hash ) : bool
SetCounter ( string key, ulong value, uint hash, System.DateTime expiry ) : bool
SetCounter ( string key, ulong value, uint hash, System.TimeSpan expiry ) : bool
Setup ( string name, string servers ) : void

Static method for creating an instance. This method will throw an exception if the name already exists.

Stats ( ) : Dictionary>

This method corresponds to the "stats" command in the memcached protocol. It will send the stats command to all servers, and it will return a Dictionary for each server containing the results of the command.

Stats ( string key ) : string>.Dictionary

This method corresponds to the "stats" command in the memcached protocol. It will send the stats command to the server that corresponds to the given key, hash or host, and return a Dictionary containing the results of the command.

Stats ( uint hash ) : string>.Dictionary
StatsByHost ( string host ) : string>.Dictionary
Status ( ) : Dictionary>

This method retrives the status from the serverpool. It checks the connection to all servers and returns usage statistics for each server.

Private Methods

Méthode Description
MemcachedClient ( string name, string hosts ) : System
checkKey ( string key ) : void

Private key-checking method. Throws an exception if the key does not conform to memcached protocol requirements: It may not contain whitespace, it may not be null or empty, and it may not be longer than 250 characters.

delete ( string key, bool keyIsChecked, uint hash, int time ) : bool
get ( string command, string key, bool keyIsChecked, uint hash, ulong &unique ) : object
get ( string command, string keys, bool keysAreChecked, uint hashes, ulong &uniques ) : object[]
getCounter ( string key, bool keyIsChecked, uint hash ) : ulong?
getCounter ( string keys, bool keysAreChecked, uint hashes ) : ulong?[]
getUnixTime ( System.DateTime datetime ) : int
hash ( string key ) : uint

Private key hashing method that uses the modified FNV hash.

hash ( uint hashvalue ) : uint

Private hashing method for user-supplied hash values.

hash ( string keys ) : uint[]

Private multi-hashing method.

hash ( uint hashvalues ) : uint[]

Private multi-hashing method for user-supplied hash values.

incrementDecrement ( string cmd, string key, bool keyIsChecked, ulong value, uint hash ) : ulong?
readValue ( PooledSocket socket, object &value, string &key, ulong &unique ) : bool
stats ( SocketPool pool ) : string>.Dictionary
store ( string key, bool keyIsChecked, object value, uint hash, int expiry, ulong unique ) : CasResult
store ( string command, string key, bool keyIsChecked, object value, uint hash ) : bool
store ( string command, string key, bool keyIsChecked, object value, uint hash, int expiry ) : bool
store ( string command, string key, bool keyIsChecked, object value, uint hash, int expiry, ulong unique ) : string

Method Details

Add() public méthode

This method corresponds to the "add" command in the memcached protocol. It will set the given key to the given value only if the key does not already exist. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully added.
public Add ( string key, object value ) : bool
key string
value object
Résultat bool

Add() public méthode

public Add ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Résultat bool

Add() public méthode

public Add ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Résultat bool

Add() public méthode

public Add ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Résultat bool

Add() public méthode

public Add ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Résultat bool

Add() public méthode

public Add ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Résultat bool

Append() public méthode

This method corresponds to the "append" command in the memcached protocol. It will append the given value to the given key, if the key already exists. Modifying a key with this command will not change its expiry time. Using the overload it is possible to specify a custom hash to override server selection.
public Append ( string key, object value ) : bool
key string
value object
Résultat bool

Append() public méthode

public Append ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Résultat bool

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, System.DateTime expiry, ulong unique ) : CasResult
key string
value object
expiry System.DateTime
unique ulong
Résultat CasResult

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, System.TimeSpan expiry, ulong unique ) : CasResult
key string
value object
expiry System.TimeSpan
unique ulong
Résultat CasResult

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, uint hash, System.DateTime expiry, ulong unique ) : CasResult
key string
value object
hash uint
expiry System.DateTime
unique ulong
Résultat CasResult

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, uint hash, System.TimeSpan expiry, ulong unique ) : CasResult
key string
value object
hash uint
expiry System.TimeSpan
unique ulong
Résultat CasResult

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, uint hash, ulong unique ) : CasResult
key string
value object
hash uint
unique ulong
Résultat CasResult

CheckAndSet() public méthode

public CheckAndSet ( string key, object value, ulong unique ) : CasResult
key string
value object
unique ulong
Résultat CasResult

Decrement() public méthode

This method corresponds to the "decr" command in the memcached protocol. It will decrease the item with the given value and return the new value. If the new value would be less than 0, it will be set to 0, and the method will return 0. It will return null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.
public Decrement ( string key, ulong value ) : ulong?
key string
value ulong
Résultat ulong?

Decrement() public méthode

public Decrement ( string key, ulong value, uint hash ) : ulong?
key string
value ulong
hash uint
Résultat ulong?

Delete() public méthode

This method corresponds to the "delete" command in the memcache protocol. It will immediately delete the given key and corresponding value. Use the overloads to specify an amount of time the item should be in the delete queue on the server, or to specify a custom hash to override server selection.
public Delete ( string key ) : bool
key string
Résultat bool

Delete() public méthode

public Delete ( string key, System.DateTime delay ) : bool
key string
delay System.DateTime
Résultat bool

Delete() public méthode

public Delete ( string key, System.TimeSpan delay ) : bool
key string
delay System.TimeSpan
Résultat bool

Delete() public méthode

public Delete ( string key, uint hash ) : bool
key string
hash uint
Résultat bool

Delete() public méthode

public Delete ( string key, uint hash, System.DateTime delay ) : bool
key string
hash uint
delay System.DateTime
Résultat bool

Delete() public méthode

public Delete ( string key, uint hash, System.TimeSpan delay ) : bool
key string
hash uint
delay System.TimeSpan
Résultat bool

Exists() public static méthode

Static method which checks if a given named MemcachedClient instance exists.
public static Exists ( string name ) : bool
name string The name of the instance.
Résultat bool

FlushAll() public méthode

This method corresponds to the "flush_all" command in the memcached protocol. When this method is called, it will send the flush command to all servers, thereby deleting all items on all servers. Use the overloads to set a delay for the flushing. If the parameter staggered is set to true, the client will increase the delay for each server, i.e. the first will flush after delay*0, the second after delay*1, the third after delay*2, etc. If set to false, all servers will flush after the same delay. It returns true if the command was successful on all servers.
public FlushAll ( ) : bool
Résultat bool

FlushAll() public méthode

public FlushAll ( System.TimeSpan delay ) : bool
delay System.TimeSpan
Résultat bool

FlushAll() public méthode

public FlushAll ( System.TimeSpan delay, bool staggered ) : bool
delay System.TimeSpan
staggered bool
Résultat bool

Get() public méthode

This method corresponds to the "get" command in the memcached protocol. It will return the value for the given key. It will return null if the key did not exist, or if it was unable to retrieve the value. If given an array of keys, it will return a same-sized array of objects with the corresponding values. Use the overload to specify a custom hash to override server selection.
public Get ( string key ) : object
key string
Résultat object

Get() public méthode

public Get ( string key, uint hash ) : object
key string
hash uint
Résultat object

Get() public méthode

This method executes a multi-get. It will group the keys by server and execute a single get for each server, and combine the results. The returned object[] will have the same size as the given key array, and contain either null or a value at each position according to the key on that position.
public Get ( string keys ) : object[]
keys string
Résultat object[]

Get() public méthode

public Get ( string keys, uint hashes ) : object[]
keys string
hashes uint
Résultat object[]

GetCounter() public méthode

This method returns the value for the given key as a ulong?, a nullable 64-bit unsigned integer. It returns null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.
public GetCounter ( string key ) : ulong?
key string
Résultat ulong?

GetCounter() public méthode

public GetCounter ( string key, uint hash ) : ulong?
key string
hash uint
Résultat ulong?

GetCounter() public méthode

public GetCounter ( string keys ) : ulong?[]
keys string
Résultat ulong?[]

GetCounter() public méthode

public GetCounter ( string keys, uint hashes ) : ulong?[]
keys string
hashes uint
Résultat ulong?[]

GetInstance() public static méthode

public static GetInstance ( ) : MemcachedClient
Résultat MemcachedClient

GetInstance() public static méthode

Static method for getting an instance. This method will first check for named instances that has been set up programmatically. If no such instance exists, it will check the "beitmemcached" section of the standard config file and see if it can find configuration info for it there. If that also fails, an exception is thrown.
public static GetInstance ( string name ) : MemcachedClient
name string The name of the instance.
Résultat MemcachedClient

Gets() public méthode

public Gets ( string key, uint hash, ulong &unique ) : object
key string
hash uint
unique ulong
Résultat object

Gets() public méthode

This method corresponds to the "gets" command in the memcached protocol. It works exactly like the Get method, but it will also return the cas unique value for the item.
public Gets ( string key, ulong &unique ) : object
key string
unique ulong
Résultat object

Gets() public méthode

public Gets ( string keys, uint hashes, ulong &uniques ) : object[]
keys string
hashes uint
uniques ulong
Résultat object[]

Gets() public méthode

This method does a multi-gets. It functions exactly like the multi-get method, but it will also return an array of cas unique values as an out parameter.
public Gets ( string keys, ulong &uniques ) : object[]
keys string
uniques ulong
Résultat object[]

Increment() public méthode

This method corresponds to the "incr" command in the memcached protocol. It will increase the item with the given value and return the new value. It will return null if the item did not exist, was not stored properly as per the SetCounter method, or if it was not able to successfully retrieve the item.
public Increment ( string key, ulong value ) : ulong?
key string
value ulong
Résultat ulong?

Increment() public méthode

public Increment ( string key, ulong value, uint hash ) : ulong?
key string
value ulong
hash uint
Résultat ulong?

Prepend() public méthode

This method corresponds to the "prepend" command in the memcached protocol. It will prepend the given value to the given key, if the key already exists. Modifying a key with this command will not change its expiry time. Using the overload it is possible to specify a custom hash to override server selection.
public Prepend ( string key, object value ) : bool
key string
value object
Résultat bool

Prepend() public méthode

public Prepend ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Résultat bool

Replace() public méthode

This method corresponds to the "replace" command in the memcached protocol. It will set the given key to the given value only if the key already exists. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully replaced.
public Replace ( string key, object value ) : bool
key string
value object
Résultat bool

Replace() public méthode

public Replace ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Résultat bool

Replace() public méthode

public Replace ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Résultat bool

Replace() public méthode

public Replace ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Résultat bool

Replace() public méthode

public Replace ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Résultat bool

Replace() public méthode

public Replace ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Résultat bool

Set() public méthode

This method corresponds to the "set" command in the memcached protocol. It will unconditionally set the given key to the given value. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the value was successfully set.
public Set ( string key, object value ) : bool
key string
value object
Résultat bool

Set() public méthode

public Set ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Résultat bool

Set() public méthode

public Set ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Résultat bool

Set() public méthode

public Set ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Résultat bool

Set() public méthode

public Set ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Résultat bool

Set() public méthode

public Set ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Résultat bool

SetCounter() public méthode

This method sets the key to the given value, and stores it in a format such that the methods Increment and Decrement can be used successfully on it, i.e. decimal representation of a 64-bit unsigned integer. Using the overloads it is possible to specify an expiry time, either relative as a TimeSpan or absolute as a DateTime. It is also possible to specify a custom hash to override server selection. This method returns true if the counter was successfully set.
public SetCounter ( string key, ulong value ) : bool
key string
value ulong
Résultat bool

SetCounter() public méthode

public SetCounter ( string key, ulong value, System.DateTime expiry ) : bool
key string
value ulong
expiry System.DateTime
Résultat bool

SetCounter() public méthode

public SetCounter ( string key, ulong value, System.TimeSpan expiry ) : bool
key string
value ulong
expiry System.TimeSpan
Résultat bool

SetCounter() public méthode

public SetCounter ( string key, ulong value, uint hash ) : bool
key string
value ulong
hash uint
Résultat bool

SetCounter() public méthode

public SetCounter ( string key, ulong value, uint hash, System.DateTime expiry ) : bool
key string
value ulong
hash uint
expiry System.DateTime
Résultat bool

SetCounter() public méthode

public SetCounter ( string key, ulong value, uint hash, System.TimeSpan expiry ) : bool
key string
value ulong
hash uint
expiry System.TimeSpan
Résultat bool

Setup() public static méthode

Static method for creating an instance. This method will throw an exception if the name already exists.
public static Setup ( string name, string servers ) : void
name string The name of the instance.
servers string A list of memcached servers in standard notation: host:port. /// If port is omitted, the default value of 11211 is used. /// Both IP addresses and host names are accepted, for example: /// "localhost", "127.0.0.1", "cache01.example.com:12345", "127.0.0.1:12345", etc.
Résultat void

Stats() public méthode

This method corresponds to the "stats" command in the memcached protocol. It will send the stats command to all servers, and it will return a Dictionary for each server containing the results of the command.
public Stats ( ) : Dictionary>
Résultat Dictionary>

Stats() public méthode

This method corresponds to the "stats" command in the memcached protocol. It will send the stats command to the server that corresponds to the given key, hash or host, and return a Dictionary containing the results of the command.
public Stats ( string key ) : string>.Dictionary
key string
Résultat string>.Dictionary

Stats() public méthode

public Stats ( uint hash ) : string>.Dictionary
hash uint
Résultat string>.Dictionary

StatsByHost() public méthode

public StatsByHost ( string host ) : string>.Dictionary
host string
Résultat string>.Dictionary

Status() public méthode

This method retrives the status from the serverpool. It checks the connection to all servers and returns usage statistics for each server.
public Status ( ) : Dictionary>
Résultat Dictionary>

Property Details

Name public_oe property

public string Name
Résultat string