0
I’m trying to make an App that modifies a DB Redis, but when I send the function connect to a user he should do Conectado = true
and UsuarioConectado = UsuarioQueConectou
.
But when the function Desconectar(DB, connected, usernameConnected)
checks whether connected == true
he should ask if I want to disconnect.
What if connected == false
(standard) it says it is already disconnected, but when connected it does Conectado == true
, but he did not modify.
And if I use $connectado
it gives error because it does not allow to use global variables.
My code:
connected = false
connectedUser = "none"
def connectUser(db, conectado, usrconnected)
puts "What's The Username"
getusername = gets.chomp
puts "What's The Password"
getpassword = gets.chomp
achou = false
achou2 = false
...
def disconectUser(connected, usercnt)
if connected and usercnt != "" and !(isNul(usercnt))
puts "Disconect ? (Y , N)"
tmp2 = gets.chomp
if tmp2 == "Y" or tmp2 == "y"
connected = false
usercnt = "none"
elsif tmp2 == "N" or tmp2 == "n"
puts "Ok ! Canceled With Sucess !"
else
puts "Unknown #{tmp2} -> Y or N !"
end
elsif !connected
puts "Already Disconnected !"
else
puts "Error With Var's ! (Connected : Boolean)"
end
end
In Case You Need To Test:
- Open Redis-server.exe for First
- Open App.Rb (Open with CMD If An Error Appears And you might want to see)