memcache-0.5.1.0: Database/Memcache/Types.hs
{-|
Module : Database.Memcache.Types
Description : Memcached Types
Copyright : (c) David Terei, 2016
License : BSD
Maintainer : code@davidterei.com
Stability : stable
Portability : GHC
Stores the various types needed by Memcached. Mostly concerned with the
representation of the protocol.
-}
module Database.Memcache.Types (
-- * Authentication
Authentication(..), Username, Password,
-- * Fields & Values
Key, Value, Initial, Delta, Expiration, Flags,
Version, Status(..),
ServerSpec(..), defaultServerSpec, parseServerSpec
) where
import Data.ByteString (ByteString)
import Data.Word
import Database.Memcache.Types.Authentication (Authentication(..), Username, Password)
import Database.Memcache.Types.ServerSpec (ServerSpec(..), defaultServerSpec, parseServerSpec)
-- | Memcached key bytes.
type Key = ByteString
-- | Memcached value bytes.
type Value = ByteString
-- | Initial value used when creating an arithmetic counter.
type Initial = Word64
-- | Arithmetic increment or decrement amount.
type Delta = Word64
-- | When a value expires, in seconds: @0@ for never, up to 30 days
-- (@2592000@) a number of seconds from now, and above that a Unix time, so
-- that one in the past expires the value at once.
--
-- memcached takes an expiration as a signed 32-bit number, so the latest Unix
-- time it takes is @2147483647@ (2^31 - 1), 03:14:07 UTC on 19 January 2038:
-- use that or less. This client sends @2147483648@ or more as it is, except
-- that 'Database.Memcache.Client.increment' and
-- 'Database.Memcache.Client.decrement' take 'maxBound' to mean that a missing
-- key isn't created, and don't send it. memcached 1.6.45 and later (1.6.40
-- for 'Database.Memcache.Client.flush') reject such a number with
-- @CLIENT_ERROR@, which the operation throws as
-- v'Database.Memcache.Errors.ProtocolError'
-- 'Database.Memcache.Errors.BadCommand', having changed nothing. Earlier
-- releases do the same on a 32-bit system, but on a 64-bit one read such a
-- number as negative, and so in the past: the value expires at once, though
-- the operation reports success. The notes on expiration in
-- "Database.Memcache.Client" say what each operation does.
type Expiration = Word32
-- | Application-defined value flags.
type Flags = Word32
-- | CAS version associated with a value. Operations that take a version skip
-- the CAS check when it is @0@.
type Version = Word64
-- | Status reported by a Memcached operation.
data Status
-- | The operation succeeded.
= NoError
-- | The key was not found.
| ErrKeyNotFound
-- | The key already exists.
| ErrKeyExists
-- | The value exceeds the server limit. The client also throws this
-- itself, before sending anything, for a value larger than 1 GiB, more
-- than any memcached server can store.
| ErrValueTooLarge
-- | The item was not stored.
| ErrItemNotStored
-- | The value is not numeric.
| ErrValueNonNumeric
-- | The server is out of memory.
| ErrOutOfMemory
-- | Text authentication failed.
| TextAuthFail
deriving (Eq, Show)