1 package com.redis.operations
4 * Redis node operations
10 val connection: Connection
14 // save the DB on disk now.
16 connection.write("SAVE\r\n")
17 connection.readBoolean
21 // save the DB in the background.
22 def bgSave: Boolean = {
23 connection.write("BGSAVE\r\n")
24 connection.readBoolean
28 // return the UNIX TIME of the last DB SAVE executed with success.
30 connection.write("LASTSAVE\r\n")
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
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")
49 // the info command returns different information and statistics about the server.
51 connection.write("INFO\r\n")
52 connection.readResponse
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
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
72 def setAsMaster: Boolean = {
73 connection.write("SLAVEOF NO ONE\r\n")
74 connection.readBoolean
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 }
88 // removes all the DB data.
89 def flushDb: Boolean = {
90 connection.write("FLUSHDB\r\n")
91 connection.readBoolean
95 // removes data from all the DB's.
96 def flushAll: Boolean = {
97 connection.write("FLUSHALL\r\n")
98 connection.readBoolean
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
110 def quit: Boolean = {
111 connection.write("QUIT\r\n")
112 connection.disconnect
116 // auths with the server.
117 def auth(secret: String): Boolean = {
118 connection.write("AUTH "+secret+"\r\n")
119 connection.readBoolean