memcache-0.6.0.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, validateCredentials,
-- * 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, validateCredentials)
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.
-- "Database.Memcache.Client" throws v'Database.Memcache.Errors.ClientError'
-- 'Database.Memcache.Errors.InvalidArgument' for a larger one, before sending
-- anything.
type Expiration = Word32
-- | Application-defined value flags.
type Flags = Word32
-- | CAS version associated with a value. On a memcached started with @-C@,
-- every version 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)