Skip to content

Commit 5df4a2c

Browse files
author
John Hann
committed
Clean up and remove last bits of old codebase.
1 parent e49a195 commit 5df4a2c

13 files changed

+32
-208
lines changed

Demo.lhs

Lines changed: 0 additions & 79 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License:
22

3-
Copyright (c) 2005 Evan Martin <[email protected]>
3+
Copyright (c) 2005 NoWait, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

NEWS

Lines changed: 0 additions & 9 deletions
This file was deleted.

Network/Memcache.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
-- Memcached interface.
2-
-- Copyright (C) 2005 Evan Martin <[email protected]>
3-
41
module Network.Memcache (
52
module Network.Memcache.Server,
63
Protocol.Expiry(..),
@@ -14,5 +11,3 @@ import Network.Memcache.Server
1411
import qualified Network.Memcache.Memcache as Memcache
1512
import Network.Memcache.Helpers
1613
import Network.Memcache.Cluster
17-
18-
-- vim: set ts=2 sw=2 et :

Network/Memcache/Cluster.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Network.Memcache.Cluster (
77
import Network.Memcache.Server
88
import Network.Memcache.Key
99
import Network.Memcache.Memcache
10-
import qualified Network.Memcache.Protocol as P
1110

1211
import Data.List (foldl')
1312

@@ -26,12 +25,12 @@ type Distribute = [Server AutoConnection] -> String -> Server AutoConnection
2625

2726
-- this seems ok for short keys
2827
-- TODO: prevent empty list of servers from getting here
29-
simple :: String -> [Server AutoConnection] -> Server AutoConnection
30-
simple k (s : []) = s
31-
simple k ss = head . snd $ splitAt idx ss
28+
simple :: Distribute
29+
simple (s : []) _ = s -- single server special case
30+
simple ss k = head . snd $ splitAt idx ss
3231
where
33-
hash = foldl' (\c i -> i + c * 31) 0 . map fromEnum
3432
idx = (hash . toKey) k `mod` length ss
33+
hash = foldl' (\c i -> i + c * 31) 0 . map fromEnum
3534

3635
instance Memcache Cluster where
3736
get cl k = get (getServer cl k) k
@@ -42,4 +41,5 @@ instance Memcache Cluster where
4241
incr cl k = incr (getServer cl k) k
4342
decr cl k = decr (getServer cl k) k
4443

44+
getServer :: (Key k) => Cluster -> k -> Server AutoConnection
4545
getServer cl key = distribute cl (servers cl) (toKey key)

Network/Memcache/Protocol.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
-- Memcached interface.
2-
-- Copyright (C) 2005 Evan Martin <[email protected]>
3-
41
module Network.Memcache.Protocol where
52

6-
-- TODO:
7-
-- - use exceptions where appropriate for protocol errors
8-
-- - expiration time in store
9-
103
import qualified Network
114
import Network.Memcache.Key
125
import Network.Memcache.Serializable
@@ -49,7 +42,6 @@ data Expiry =
4942
Seconds Word32 | -- ^ Limited at run-time to 2592000 seconds (30 days).
5043
Date UTCTime
5144
deriving (Show)
52-
-- figure out how to limit seconds to the memcached limit of 30 days.
5345

5446
newtype Connection = Connection { sHandle :: Handle }
5547

@@ -108,16 +100,19 @@ incDec cmd (Connection handle) key delta = do
108100
"NOT_FOUND" -> return Nothing
109101
x -> return $ Just (read x)
110102

103+
get :: (Key k, Serializable s) => Connection -> k -> IO (Maybe s)
111104
get (Connection handle) key = do
112105
hPutCommand handle ["get", toKey key]
113-
val <- getOneValue handle
114-
case val of
106+
mval <- getOneValue handle
107+
case mval of
115108
Nothing -> return Nothing
116109
Just val -> do
117110
hGetNetLn handle
118111
hGetNetLn handle
119112
return $ deserialize val
120113

114+
-- TODO: consider throwing instead of returning bool
115+
delete :: (Key k) => Connection -> k -> IO Bool
121116
delete (Connection handle) key = do
122117
hPutCommand handle ["delete", toKey key]
123118
response <- hGetNetLn handle
@@ -130,11 +125,13 @@ expiryToWord expiry = do
130125
Date d -> floor (utcTimeToPOSIXSeconds d)
131126
Seconds s -> safeMemcachedSeconds s
132127

128+
thirtyDays :: Word32
133129
thirtyDays = 30 * 24 * 60 * 60
134130

135131
-- | Prevents accidental converstion to Unix time by memcached
136132
safeMemcachedSeconds :: Word32 -> Word32
137133
safeMemcachedSeconds seconds = min seconds thirtyDays
138134

135+
showFlags :: Maybe Flags -> String
139136
showFlags Nothing = "0"
140137
showFlags (Just f) = show f

Network/Memcache/Serializable.hs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
-- Memcached interface.
2-
-- Copyright (C) 2005 Evan Martin <[email protected]>
3-
41
module Network.Memcache.Serializable(Serializable, serialize, deserialize) where
52

63
import Data.ByteString (ByteString)
74
import Codec.Binary.UTF8.Light (encode, decode)
85

9-
-- It'd be nice to use "show" for serialization, but when we
10-
-- serialize a String we want to serialize it without the quotes.
11-
12-
-- TODO:
13-
-- - allow serializing bytes as Ptr
14-
-- to do this, add a "putToHandle", etc. method in Serializable
15-
-- where the default uses serialize, but for Ptr uses socket stuff.
16-
17-
--import Foreign.Marshal.Utils
18-
--import Foreign.Storable (Storable, sizeOf)
19-
206
class Serializable a where
217
serialize :: a -> ByteString
228
deserialize :: ByteString -> Maybe a

Network/Memcache/Server.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ module Network.Memcache.Server (
1515
import qualified Network.Memcache.Protocol as P
1616
import qualified Network.Memcache.Memcache as MC
1717

18-
import Control.Exception (finally, bracket)
18+
import Control.Exception (bracket)
1919
import Network (HostName, PortNumber)
20-
import Control.Applicative
2120

2221
{- TODO:
2322
- consider some of these updates:
@@ -32,26 +31,27 @@ import Control.Applicative
3231
-- mc <- connect "my-mc-server"
3332
-- Reference: https://github.com/memcached/memcached/blob/master/doc/protocol.txt
3433
data Server c where
35-
Disconnected {
34+
Disconnected :: {
3635
dExpiry :: P.Expiry, -- ^ expiration
3736
dFlags :: Maybe P.Flags -- ^ extra bits stored with each key-value
38-
} :: Server NoConnection
39-
Connected {
37+
} -> Server NoConnection
38+
Connected :: {
4039
cConn :: P.Connection, -- ^ connection
4140
cExpiry :: P.Expiry, -- ^ expiration
4241
cFlags :: Maybe P.Flags -- ^ extra bits stored with each key-value
4342
-- ^ Note: must be memcached 1.2.1 and higher to support 32 bits
44-
} :: Server P.Connection
45-
AutoConnected {
43+
} -> Server P.Connection
44+
AutoConnected :: {
4645
aConn :: AutoConnection,
4746
aExpirty :: P.Expiry,
4847
aFlags :: Maybe P.Flags
49-
} :: Server AutoConnection
48+
} -> Server AutoConnection
5049

5150
data NoConnection
5251
data AutoConnection = AutoConnection HostName (Maybe PortNumber)
5352

54-
defaultPort = 11211 :: PortNumber
53+
defaultPort :: PortNumber
54+
defaultPort = 11211
5555

5656
configure :: P.Expiry -> Maybe P.Flags -> Server NoConnection
5757
configure = Disconnected

Network/Memcache/ServerPool.hs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
-- Memcached interface.
2-
-- Copyright (C) 2005 Evan Martin <[email protected]>
3-
41
module Network.Memcache.ServerPool where
52

63
import qualified Network.Memcache.Server as S
74

85
-- TODO: make sense of this or refactor it
9-
-- TODO: consider implementing ketama:
10-
-- http://www.last.fm/user/RJ/journal/2007/04/10/rz_libketama_-_a_consistent_hashing_algo_for_memcache_clients
11-
-- TODO: a simple algorithm for now:
12-
-- let server = hash key `mod` length serverlist
13-
-- TODO: inject hash algorithm here instead of as a Key class method:
14-
-- 1. create a Distribution class
15-
-- 2. implement (instance) a simple algorithm or a ketama algorithm
16-
17-
data Server = Server (S.Server S.NoConnection) Int
18-
data Pool = Pool (String -> Int)
196

20-
-- vim: set ts=2 sw=2 et :
7+
data Pool = Pool [S.Server]

README

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Haskell emcached Client
2+
3+
TODO

Test.hs

Lines changed: 0 additions & 51 deletions
This file was deleted.

memcached.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: memcached
22
version: 0.2.2
33
stability: Alpha
4-
synopsis: haskell bindings for memcached
5-
description: haskell bindings for memcached
4+
synopsis: Haskell Memcached client
5+
description: Haskell Memcached client
66
category: Network
77
license: OtherLicense
88
license-file: LICENSE
9-
author: Evan Martin <martine@danga.com>
10-
maintainer: Janrain <hackage@janrain.com>
11-
homepage: http://github.com/olegkat/haskell-memcached
9+
author: John Hann <john@nowait.com>
10+
maintainer: John Hann <john@nowait.com>
11+
homepage: http://github.com/nowaitapp/haskell-memcached
1212
build-type: Simple
1313

14-
tested-with: GHC==6.8.2, GHC==6.10
14+
tested-with: GHC==7.10.2
1515

1616
build-depends:
1717
base >3 && <5,

0 commit comments

Comments
 (0)