]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/main/scala/com/redis/Operations/NodeOperations.scala
3deb8dd010ae5a19591ae60c3a6b9664023f6272
[redis.git] / client-libraries / scala / src / main / scala / com / redis / Operations / NodeOperations.scala
1 package com.redis.operations
2
3 /**
4 * Redis node operations
5 *
6 */
7
8 trait NodeOperations {
9
10 val connection: Connection
11 var db: Int
12
13 // SAVE
14 // save the DB on disk now.
15 def save: Boolean = {
16 connection.write("SAVE\r\n")
17 connection.readBoolean
18 }
19
20 // BGSAVE
21 // save the DB in the background.
22 def bgSave: Boolean = {
23 connection.write("BGSAVE\r\n")
24 connection.readBoolean
25 }
26
27 // LASTSAVE
28 // return the UNIX TIME of the last DB SAVE executed with success.
29 def lastSave: Int = {
30 connection.write("LASTSAVE\r\n")
31 connection.readInt
32 }
33
34 // SHUTDOWN
35 // Stop all the clients, save the DB, then quit the server.
36 def shutdown: Boolean = {
37 connection.write("SHUTDOWN\r\n")
38 connection.readBoolean
39 }
40
41 // MGET (key, key, key, ...)
42 // get the values of all the specified keys.
43 def mget(keys: String*) = {
44 connection.write("MGET "+keys.mkString(" ")+"\r\n")
45 connection.readList
46 }
47
48 // INFO
49 // the info command returns different information and statistics about the server.
50 def info = {
51 connection.write("INFO\r\n")
52 connection.readResponse
53 }
54
55 // MONITOR
56 // is a debugging command that outputs the whole sequence of commands received by the Redis server.
57 def monitor: Boolean = {
58 connection.write("MONITOR\r\n")
59 connection.readBoolean
60 }
61
62 // SLAVEOF
63 // The SLAVEOF command can change the replication settings of a slave on the fly.
64 def slaveOf(options: Any): Boolean = options match {
65 case (host: String, port: Int) => {
66 connection.write("SLAVEOF "+host+" "+port.toString+"\r\n")
67 connection.readBoolean
68 }
69 case _ => setAsMaster
70 }
71
72 def setAsMaster: Boolean = {
73 connection.write("SLAVEOF NO ONE\r\n")
74 connection.readBoolean
75 }
76
77 // SELECT (index)
78 // selects the DB to connect, defaults to 0 (zero).
79 def selectDb(index: Int): Boolean = {
80 connection.write("SELECT "+index+"\r\n")
81 connection.readBoolean match {
82 case true => { db = index; true }
83 case _ => false
84 }
85 }
86
87 // FLUSHDB the DB
88 // removes all the DB data.
89 def flushDb: Boolean = {
90 connection.write("FLUSHDB\r\n")
91 connection.readBoolean
92 }
93
94 // FLUSHALL the DB's
95 // removes data from all the DB's.
96 def flushAll: Boolean = {
97 connection.write("FLUSHALL\r\n")
98 connection.readBoolean
99 }
100
101 // MOVE
102 // Move the specified key from the currently selected DB to the specified destination DB.
103 def move(key: String, db: Int) = {
104 connection.write("MOVE "+key+" "+db.toString+"\r\n")
105 connection.readBoolean
106 }
107
108 // QUIT
109 // exits the server.
110 def quit: Boolean = {
111 connection.write("QUIT\r\n")
112 connection.disconnect
113 }
114
115 // AUTH
116 // auths with the server.
117 def auth(secret: String): Boolean = {
118 connection.write("AUTH "+secret+"\r\n")
119 connection.readBoolean
120 }
121 }