Redis command details and use of scene examples--connection (connection)

Source: Internet
Author: User
Tags auth numeric value password protection redis server
redis-cli-h URL [-p]

Client Connection Redis
-H Specify Redis address
-p port number, default 3306 AUTH password

You can use a password to protect the Redis server by setting the value of the Requirepass item in the configuration file (using the command CONFIG set Requirepass password).
If password protection is turned on, after each connection to the Redis server, the AUTH command is used to unlock the lock before using the other Redis commands.
If the password given by the AUTH command matches the password password and the configuration file, the server returns OK and starts accepting the command input.
On the other hand, if the password does not match, the server will return an error and require the client to re-enter the password.
Because of the high performance characteristics of redis, it is possible to try to guess very many passwords in a very short period of time, so make sure the passwords you use are complex enough and long enough to avoid password guessing attacks.
Available Versions:
1.0.0+
complexity of Time:
O (1)
return Value:
Returns OK when the password matches, otherwise an error is returned.
Set Password

Redis> CONFIG Set Requirepass secret_password   # Sets the password to Secret_password
OK
redis> QUIT   
                              # Exit and reconnect and let the new password take effect on the client
[huangz@mypad]$ redis
redis> PING                                     # unauthenticated password, operation denied
(error) ERR operation not permitted
redis> AUTH Wrong_password_testing              # Try to enter the wrong password
(error) ERR Invalid password
redis> AUTH secret_password                     # Enter the correct password
OK
redis> PING                                     # Password Authentication is successful, you can command the normal operation
PONG
Empty Password
Redis> CONFIG Set Requirepass ""   # by setting the password to null to empty the password
OK
redis> QUIT
$ redis                            # Re-enter the client
redis> PING                        # Execute command no longer requires password, empty password operation successful
PONG
ECHO Message

Print a specific message that is used for testing.
Available Versions:
1.0.0
complexity of Time:
O (1)
return Value:
Message itself.

redis> echo "Hello Moto"
"Hello Moto"
redis> ECHO "Goodbye Moto" "Goodbye Moto
"
PING

Use a client to send a PING to the Redis server and return a PONG if the server is working properly.
This is typically used to test whether the connection to the server is still in effect, or to measure the latency value.
Available Versions:
1.0.0
complexity of Time:
O (1)
return Value:
Returns a PONG if the connection is normal, otherwise a connection error is returned.
Client and server connections are normal

redis> PING
PONG

Client and server connections are not working properly (network is not working properly or the server is not functioning properly)

Redis 127.0.0.1:6379> PING
could not connect to Redis at 127.0.0.1:6379:connection refused
QUIT

Requests the server to close the connection to the current client.
Once all the pending replies (if any) are successfully written to the client, the connection is closed.
Available Versions:
1.0.0+
complexity of Time:
O (1)
return Value:
Always return OK (but will not be printed because REDIS-CLI has exited).

$ redis
redis> QUIT
$
SELECT Index

Switches to the specified database, and the database index number is specified with a numeric value, with 0 as the starting index value.
By default, the No. 0 database is used.
Available Versions:
1.0.0+
complexity of Time:
O (1)
return Value:
Ok

Redis> SET db_number 0         # Default to use database No. 0
OK
redis> SELECT 1                # Use 1th database
OK
redis[1]> get db_n Umber        # has switched to database number 1th, note redis

The command prompt now has an extra [1]

(nil)
redis[1]> SET db_number 1
OK
redis[1]> get db_number
"1"
redis[1]> SELECT 3             # switch to 3 Database
OK
redis[3]>                      # Prompt changed from [1] to [3]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.