C# Класс MemcachedClientLibrary.MemcachedClient

Memcached client main class. Use the static methods Setup and GetInstance to setup and get an instance of the client for use.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
Name string

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

Add() публичный Метод

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
Результат bool

Add() публичный Метод

public Add ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Результат bool

Add() публичный Метод

public Add ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Результат bool

Add() публичный Метод

public Add ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Результат bool

Add() публичный Метод

public Add ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Результат bool

Add() публичный Метод

public Add ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Результат bool

Append() публичный Метод

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
Результат bool

Append() публичный Метод

public Append ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Результат bool

CheckAndSet() публичный Метод

public CheckAndSet ( string key, object value, System.DateTime expiry, ulong unique ) : CasResult
key string
value object
expiry System.DateTime
unique ulong
Результат CasResult

CheckAndSet() публичный Метод

public CheckAndSet ( string key, object value, System.TimeSpan expiry, ulong unique ) : CasResult
key string
value object
expiry System.TimeSpan
unique ulong
Результат CasResult

CheckAndSet() публичный Метод

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
Результат CasResult

CheckAndSet() публичный Метод

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
Результат CasResult

CheckAndSet() публичный Метод

public CheckAndSet ( string key, object value, uint hash, ulong unique ) : CasResult
key string
value object
hash uint
unique ulong
Результат CasResult

CheckAndSet() публичный Метод

public CheckAndSet ( string key, object value, ulong unique ) : CasResult
key string
value object
unique ulong
Результат CasResult

Decrement() публичный Метод

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
Результат ulong?

Decrement() публичный Метод

public Decrement ( string key, ulong value, uint hash ) : ulong?
key string
value ulong
hash uint
Результат ulong?

Delete() публичный Метод

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
Результат bool

Delete() публичный Метод

public Delete ( string key, System.DateTime delay ) : bool
key string
delay System.DateTime
Результат bool

Delete() публичный Метод

public Delete ( string key, System.TimeSpan delay ) : bool
key string
delay System.TimeSpan
Результат bool

Delete() публичный Метод

public Delete ( string key, uint hash ) : bool
key string
hash uint
Результат bool

Delete() публичный Метод

public Delete ( string key, uint hash, System.DateTime delay ) : bool
key string
hash uint
delay System.DateTime
Результат bool

Delete() публичный Метод

public Delete ( string key, uint hash, System.TimeSpan delay ) : bool
key string
hash uint
delay System.TimeSpan
Результат bool

Exists() публичный статический Метод

Static method which checks if a given named MemcachedClient instance exists.
public static Exists ( string name ) : bool
name string The name of the instance.
Результат bool

FlushAll() публичный Метод

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
Результат bool

FlushAll() публичный Метод

public FlushAll ( System.TimeSpan delay ) : bool
delay System.TimeSpan
Результат bool

FlushAll() публичный Метод

public FlushAll ( System.TimeSpan delay, bool staggered ) : bool
delay System.TimeSpan
staggered bool
Результат bool

Get() публичный Метод

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
Результат object

Get() публичный Метод

public Get ( string key, uint hash ) : object
key string
hash uint
Результат object

Get() публичный Метод

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
Результат object[]

Get() публичный Метод

public Get ( string keys, uint hashes ) : object[]
keys string
hashes uint
Результат object[]

GetCounter() публичный Метод

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
Результат ulong?

GetCounter() публичный Метод

public GetCounter ( string key, uint hash ) : ulong?
key string
hash uint
Результат ulong?

GetCounter() публичный Метод

public GetCounter ( string keys ) : ulong?[]
keys string
Результат ulong?[]

GetCounter() публичный Метод

public GetCounter ( string keys, uint hashes ) : ulong?[]
keys string
hashes uint
Результат ulong?[]

GetInstance() публичный статический Метод

public static GetInstance ( ) : MemcachedClient
Результат MemcachedClient

GetInstance() публичный статический Метод

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.
Результат MemcachedClient

Gets() публичный Метод

public Gets ( string key, uint hash, ulong &unique ) : object
key string
hash uint
unique ulong
Результат object

Gets() публичный Метод

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
Результат object

Gets() публичный Метод

public Gets ( string keys, uint hashes, ulong &uniques ) : object[]
keys string
hashes uint
uniques ulong
Результат object[]

Gets() публичный Метод

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
Результат object[]

Increment() публичный Метод

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
Результат ulong?

Increment() публичный Метод

public Increment ( string key, ulong value, uint hash ) : ulong?
key string
value ulong
hash uint
Результат ulong?

Prepend() публичный Метод

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
Результат bool

Prepend() публичный Метод

public Prepend ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Результат bool

Replace() публичный Метод

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
Результат bool

Replace() публичный Метод

public Replace ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Результат bool

Replace() публичный Метод

public Replace ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Результат bool

Replace() публичный Метод

public Replace ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Результат bool

Replace() публичный Метод

public Replace ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Результат bool

Replace() публичный Метод

public Replace ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Результат bool

Set() публичный Метод

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
Результат bool

Set() публичный Метод

public Set ( string key, object value, System.DateTime expiry ) : bool
key string
value object
expiry System.DateTime
Результат bool

Set() публичный Метод

public Set ( string key, object value, System.TimeSpan expiry ) : bool
key string
value object
expiry System.TimeSpan
Результат bool

Set() публичный Метод

public Set ( string key, object value, uint hash ) : bool
key string
value object
hash uint
Результат bool

Set() публичный Метод

public Set ( string key, object value, uint hash, System.DateTime expiry ) : bool
key string
value object
hash uint
expiry System.DateTime
Результат bool

Set() публичный Метод

public Set ( string key, object value, uint hash, System.TimeSpan expiry ) : bool
key string
value object
hash uint
expiry System.TimeSpan
Результат bool

SetCounter() публичный Метод

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
Результат bool

SetCounter() публичный Метод

public SetCounter ( string key, ulong value, System.DateTime expiry ) : bool
key string
value ulong
expiry System.DateTime
Результат bool

SetCounter() публичный Метод

public SetCounter ( string key, ulong value, System.TimeSpan expiry ) : bool
key string
value ulong
expiry System.TimeSpan
Результат bool

SetCounter() публичный Метод

public SetCounter ( string key, ulong value, uint hash ) : bool
key string
value ulong
hash uint
Результат bool

SetCounter() публичный Метод

public SetCounter ( string key, ulong value, uint hash, System.DateTime expiry ) : bool
key string
value ulong
hash uint
expiry System.DateTime
Результат bool

SetCounter() публичный Метод

public SetCounter ( string key, ulong value, uint hash, System.TimeSpan expiry ) : bool
key string
value ulong
hash uint
expiry System.TimeSpan
Результат bool

Setup() публичный статический Метод

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.
Результат void

Stats() публичный Метод

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>
Результат Dictionary>

Stats() публичный Метод

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
Результат string>.Dictionary

Stats() публичный Метод

public Stats ( uint hash ) : string>.Dictionary
hash uint
Результат string>.Dictionary

StatsByHost() публичный Метод

public StatsByHost ( string host ) : string>.Dictionary
host string
Результат string>.Dictionary

Status() публичный Метод

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>
Результат Dictionary>

Описание свойств

Name публичное свойство

public string Name
Результат string