Class: BoJack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bojack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname = "127.0.0.1", port = 5000) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/bojack.rb', line 8

def initialize(hostname = "127.0.0.1", port = 5000)
  @hostname = hostname
  @port = port
  @socket = TCPSocket.new(@hostname, @port)
  # @socket.tcp_nodelay = true
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



6
7
8
# File 'lib/bojack.rb', line 6

def hostname
  @hostname
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/bojack.rb', line 6

def port
  @port
end

Instance Method Details

#append(key, value) ⇒ Object



27
28
29
# File 'lib/bojack.rb', line 27

def append(key, value)
  send("append #{key} #{value}")
end

#closeObject



47
48
49
# File 'lib/bojack.rb', line 47

def close
  send("close")
end

#delete(key) ⇒ Object



35
36
37
# File 'lib/bojack.rb', line 35

def delete(key)
  send("delete #{key}")
end

#get(key) ⇒ Object



23
24
25
# File 'lib/bojack.rb', line 23

def get(key)
  send("get #{key}")
end

#increment(key) ⇒ Object



19
20
21
# File 'lib/bojack.rb', line 19

def increment(key)
  send("increment #{key}")
end

#pingObject



39
40
41
# File 'lib/bojack.rb', line 39

def ping
  send("ping")
end

#pop(key) ⇒ Object



31
32
33
# File 'lib/bojack.rb', line 31

def pop(key)
  send("pop #{key}")
end

#send(raw) ⇒ Object



51
52
53
54
# File 'lib/bojack.rb', line 51

def send(raw)
  @socket.puts(raw)
  @socket.gets
end

#set(key, value) ⇒ Object



15
16
17
# File 'lib/bojack.rb', line 15

def set(key, value)
  send("set #{key} #{value}")
end

#sizeObject



43
44
45
# File 'lib/bojack.rb', line 43

def size
  send("size")
end