Set redis access password
On the server, take the linux server as an example to configure the password for redis.
1. The first way (the current method of configuring redis passwords in linux is temporary, and the password will expire after redis restart,)
(1) enter redis first. If redis is not enabled, you need to enable it first:
# redis-cli-p 6379
127.0.0.1purl 6379 >
(2) check whether the current redis has set a password:
127.0.0.1 purl 6379 > config get requirepass
1) "requirepass"
2) "
(3) if there is no password as shown above, set the password now:
127.0.0.1 purl 6379 > config set requirepass abcdefg
OK
127.0.0.1purl 6379 >
(4) if you check the current redis again, you will be prompted to need a password:
127.0.0.1 purl 6379 > config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1purl 6379 >
two。 The second way (permanent way)
If you need a permanent configuration password, go to the configuration file of redis.conf to find the parameter requirepass, as follows:
Modify redis.conf configuration file
# requirepass foobared
Requirepass 123 specify password 123
Just restart redis after saving it
Connect redis
1.redis-cli connection redis
# redis-cli
127.0.0.1 6379 > keys *
(error) NOAUTH Authentication required.
127.0.0.1 auth 6379 > specify password
OK
127.0.0.1 6379 > keys *
1) "a"
2) "cit"
3) "clist"
4) "1"
127.0.0.1purl 6379 >
2.Jedis connection redis
Java code mode
/ / Connect to the redis server, 192.168.0.100pur6379
Jedis = new Jedis ("ip", 6379)
/ / permission authentication
Jedis.auth ("password")
Configuration file mode
Other commands of redis.
If you need to close redis:
# pkill redis
If you need to enable redis:
# redis-server &
The purpose of the plus-symbol is to convert this process into a background process without consuming shell services.
The more you invest, the more value you get.