Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains an implementation of the etcd client.
- data Client
- createClient :: [Text] -> IO Client
- data Node = Node {
- _nodeKey :: !Key
- _nodeCreatedIndex :: !Index
- _nodeModifiedIndex :: !Index
- _nodeDir :: !Bool
- _nodeValue :: !(Maybe Value)
- _nodeNodes :: !(Maybe [Node])
- _nodeTTL :: !(Maybe TTL)
- _nodeExpiration :: !(Maybe UTCTime)
- type Index = Int
- type Key = Text
- type Value = Text
- type TTL = Int
- get :: Client -> Key -> IO (Maybe Node)
- set :: Client -> Key -> Value -> Maybe TTL -> IO (Maybe Node)
- create :: Client -> Key -> Value -> Maybe TTL -> IO Node
- createDirectory :: Client -> Key -> Maybe TTL -> IO ()
- listDirectoryContents :: Client -> Key -> IO [Node]
- removeDirectory :: Client -> Key -> IO ()
- removeDirectoryRecursive :: Client -> Key -> IO ()
Documentation
The Client
holds all data required to make requests to the etcd
cluster. You should use createClient
to initialize a new client.
createClient :: [Text] -> IO Client Source
Create a new client and initialize it with a list of seed machines. The list must be non-empty.
Types
The Node
corresponds to the node object as returned by the etcd API.
There are two types of nodes in etcd. One is a leaf node which holds a value, the other is a directory node which holds zero or more child nodes. A directory node can not hold a value, the two types are exclusive.
On the wire, the two are not really distinguished, except that the JSON objects have different fields.
A node may be set to expire after a number of seconds. This is indicated by
the two fields ttl
and expiration
.
Node | |
|
The etcd index is a unique, monotonically-incrementing integer created for each change to etcd. See etcd documentation for more details.
Keys are strings, formatted like filesystem paths (ie. slash-delimited list of path components).
Values attached to leaf nodes are strings. If you want to store structured data in the values, you'll need to encode it into a string.
TTL is specified in seconds. The server accepts negative values, but they don't make much sense.
Low-level key operations
create :: Client -> Key -> Value -> Maybe TTL -> IO Node Source
Create a value in the given key. The key must be a directory.
Directory operations
listDirectoryContents :: Client -> Key -> IO [Node] Source
List all nodes within the given directory.
removeDirectory :: Client -> Key -> IO () Source
Remove the directory at the given key. The directory MUST be empty,
otherwise the removal fails. If you don't care about the keys within, you
can use removeDirectoryRecursive
.
removeDirectoryRecursive :: Client -> Key -> IO () Source
Remove the directory at the given key, including all its children.