glemcached/text

Types

The result returned by the cas command. Since it has three possible values, it is not possible to use a boolean to represent them.

pub type CasReturnType {
  CasStored
  CasExists
  CasNotFound
}

Constructors

  • CasStored

    Data was stored successfully, i.e. the data was not modified since it was fetched with g(e|a)ts.

  • CasExists

    Data was not stored, i.e. the data was modified since it was fetched with g(e|a)ts. This value is also returned if the cas_unique value is invalid, but the key exists.

  • CasNotFound

    The key does not exist.

Functions

pub fn add(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  data data: BitArray,
) -> Result(Bool, MemcachedError)

Sets this key in Memcached only if it doesn’t already exist. Returns True if the value was set, and False if not (i.e. the key already exists). Errors are only returned if the command fails to run.

Example

add(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hello, world!">>,
)
pub fn append(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  data data: BitArray,
) -> Result(Bool, MemcachedError)

Adds this value to the end of the existing data. Returns True if the value was set, and False if not (i.e. the key does not exist). Errors are only returned if the command fails to run.

Example

append(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hi!">>,
)
pub fn cas(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  cas_unique cas_unique: Int,
  data data: BitArray,
) -> Result(CasReturnType, MemcachedError)

Sets this value only if it wasn’t modified since the time it was fetched with a CAS (check and store) command like gets/gats. These commands return a unique CAS value, which must be passed as the cas_unique parameter to this function.

Example

cas(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hi!">>,
  cas_unique: 10
)
pub fn decr(
  mem: Memcached,
  key: String,
  value: Int,
) -> Result(Option(Int), MemcachedError)

Decrements the value of the key by value. The value is interpreted to be a 64-bit unsigned integer, and any underflows are replaced with zero by Memcached. The Ok value is an Option, which will be None if key does not exist. If key’s value is not an integer, a CommandError will be raised with the message: "cannot increment or decrement non-numeric value"

Example

decr(
  mem,
  key: "foo"
  value: 1
)
pub fn delete(
  mem: Memcached,
  key: String,
) -> Result(Bool, MemcachedError)

Deletes the key. Returns True if the key existed, otherwise returns False.

Example

gets(
  mem,
  keys: ["foo", "bar", "baz"],
)
pub fn gat(
  mem: Memcached,
  exptime: Int,
  keys: List(String),
) -> Result(List(Value), MemcachedError)

Get and Touch. Change the expiration time of all keys to exptime (in seconds or unix epoch if exptime is greater than 30 days (30 * 24 * 60 * 60 seconds)). An expiration time of 0 indicates that the key never expires, and an expiration time of a negative number indicates immediate expiration. Returns the values of each of the keys (similar to the get function). exptime is specified before keys to mimic the equivalent Memcached command’s syntax.

Example

gat(
  mem,
  exptime: 100
  keys: ["foo", "bar", "baz"]
)
pub fn gats(
  mem: Memcached,
  exptime: Int,
  keys: List(String),
) -> Result(List(ValueCas), MemcachedError)

Get and Touch returning unique CAS values. Change the expiration time of all keys to exptime (in seconds or unix epoch if exptime is greater than 30 days (30 * 24 * 60 * 60 seconds)). An expiration time of 0 indicates that the key never expires, and an expiration time of a negative number indicates immediate expiration. Returns the values of each of the keys (similar to the gets command). exptime is specified before keys to mimic the equivalent Memcached command’s syntax.

Example

gats(
  mem,
  exptime: 100
  keys: ["foo", "bar", "baz"]
)
pub fn get(
  mem: Memcached,
  keys keys: List(String),
) -> Result(List(Value), MemcachedError)

Gets the values and flags of these keys. If a value is not found, that key will not exist in the returned list.

Example

get(
  mem,
  keys: ["foo", "bar", "baz"],
)
pub fn gets(
  mem: Memcached,
  keys keys: List(String),
) -> Result(List(ValueCas), MemcachedError)

Gets the values, flags, and unique CAS values of these keys. If a value is not found, that key will not exist in the returned list. See the cas function to learn more about CAS.

Example

gets(
  mem,
  keys: ["foo", "bar", "baz"],
)
pub fn incr(
  mem: Memcached,
  key: String,
  value: Int,
) -> Result(Option(Int), MemcachedError)

Increments the value of the key by value. The value is interpreted to be a 64-bit unsigned integer, and any overflows are replaced with zero by Memcached. The Ok value is an Option, which will be None if key does not exist. If key’s value is not an integer, a CommandError will be raised with the message: "cannot increment or decrement non-numeric value"

Example

incr(
  mem,
  key: "foo",
  value: 1
)
pub fn prepend(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  data data: BitArray,
) -> Result(Bool, MemcachedError)

Adds this value to the start of the existing data. Returns True if the value was set, and False if not (i.e. the key does not exist). Errors are only returned if the command fails to run.

Example

prepend(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hi!">>,
)
pub fn replace(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  data data: BitArray,
) -> Result(Bool, MemcachedError)

Sets this key in Memcached only if it does already exist. Returns True if the value was set, and False if not (i.e. the key does not exist). Errors are only returned if the command fails to run.

Example

replace(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hello, world!">>,
)
pub fn set(
  mem: Memcached,
  key key: String,
  flags flags: Int,
  exptime exptime: Int,
  data data: BitArray,
) -> Result(Nil, MemcachedError)

Stores this data in memcached. Overrides existing data if any.

Example

set(
  mem,
  key: "foo",
  flags: flag.bit_array_to_uint16(<<1234>>),
  exptime: 100,
  data: <<"Hello, world!">>,
)
|> should.be_ok()
|> should.equal(Nil)
pub fn touch(
  mem: Memcached,
  key: String,
  exptime: Int,
) -> Result(Bool, MemcachedError)

Change the expiration time of key to exptime (in seconds or unix epoch if exptime is greater than 30 days (30 * 24 * 60 * 60 seconds)). An expiration time of 0 indicates that the key never expires, and an expiration time of a negative number indicates immediate expiration.

Example

touch(
  mem,
  key: "foo"
  exptime: 100
)
Search Document