4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
8 object OperationsSpec extends Specification with Mockito {
10 "Redis Client Operations" should {
12 var client: RedisTestClient = null
13 var connection: Connection = null
16 connection = mock[Connection]
17 client = new RedisTestClient(connection)
21 connection.readBoolean returns true
22 client.set("a", "b") mustEqual true
23 connection.write("SET a 1\r\nb\r\n") was called
26 "set a key with setKey" in {
27 connection.readBoolean returns true
28 client.setKey("a", "b") mustEqual true
29 connection.write("SET a 1\r\nb\r\n") was called
32 "set a key with expiration" in {
33 connection.readBoolean returns true
34 client.set("a", "b", 4) mustEqual true
35 connection.write("SET a 1\r\nb\r\n") was called
36 connection.write("EXPIRE a 4\r\n") was called
40 connection.readBoolean returns true
41 client.expire("a", 4) mustEqual true
42 connection.write("EXPIRE a 4\r\n") was called
46 connection.readResponse returns "b"
47 client.get("a") mustEqual "b"
48 connection.write("GET a\r\n") was called
51 "get and set a key" in {
52 connection.readResponse returns "old"
53 client.getSet("a", "new") mustEqual "old"
54 connection.write("GETSET a 3\r\nnew\r\n") was called
58 connection.readBoolean returns true
59 client.delete("a") mustEqual true
60 connection.write("DEL a\r\n") was called
63 "tell if a key exists" in {
64 connection.readBoolean returns true
65 client.exists("a") mustEqual true
66 connection.write("EXISTS a\r\n") was called
69 "tell if a key exists" in {
70 connection.readBoolean returns true
71 client.exists("a") mustEqual true
72 connection.write("EXISTS a\r\n") was called
75 "increment a value" in {
76 connection.readInt returns 1
77 client.incr("a") mustEqual 1
78 connection.write("INCR a\r\n") was called
81 "increment a value by N" in {
82 connection.readInt returns 27
83 client.incr("a", 23) mustEqual 27
84 connection.write("INCRBY a 23\r\n") was called
87 "decrement a value" in {
88 connection.readInt returns 0
89 client.decr("a") mustEqual 0
90 connection.write("DECR a\r\n") was called
93 "decrement a value by N" in {
94 connection.readInt returns 25
95 client.decr("a", 2) mustEqual 25
96 connection.write("DECRBY a 2\r\n") was called
99 "return type of key" in {
100 connection.readResponse returns "String"
101 client.getType("a") mustEqual "String"
102 connection.write("TYPE a\r\n") was called