-
Notifications
You must be signed in to change notification settings - Fork 1
/
RedisServerCodec.scala
42 lines (33 loc) · 1.18 KB
/
RedisServerCodec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.github.cb372.fedis
package codec
import handler.ClientAddressInjector
import com.twitter.finagle.redis.naggati.{Codec => NaggatiCodec, Stage}
import com.twitter.finagle.{Codec, ServerCodecConfig, CodecFactory}
import com.twitter.finagle.redis.protocol.{ReplyCodec, CommandCodec, Reply}
import org.jboss.netty.channel.{Channels, ChannelPipelineFactory}
import com.twitter.finagle.redis.naggati.DontCareCounter
object RedisServerCodec {
def apply() = new RedisServerCodec
def get() = apply()
}
class RedisServerCodec extends CodecFactory[CmdFromClient, Reply]#Server {
def apply(config: ServerCodecConfig) =
new Codec[CmdFromClient, Reply] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
val commandCodec = new CommandCodec
val replyCodec = new ReplyCodec
pipeline.addLast("codec",
new NaggatiCodec(
commandCodec.decode,
replyCodec.encode,
DontCareCounter,
DontCareCounter)
)
pipeline.addLast("clientAddr", new ClientAddressInjector)
pipeline
}
}
}
}