Redis 配置密码 ubuntu
-
通过配置文件配置
vim /etc/redis/redis.conf
-
修改配置文件 增添
requirepass passwd
-
重启服务
service redis-server restart
-
测试连接_redis_cli
127.0.0.1:6379> keys * (error) NOAUTH Authentication required. 127.0.0.1:6379> auth password OK 127.0.0.1:6379> keys * 1) "cookie1" 2) "test"
-
测试连接_Python
from redis import StrictRedis redis = StrictRedis(host='127.0.0.1', port=6379, db=0, password='passwd') redis.set('cookie', 'test') print(redis.get('cookie')) # redis = StrictRedis(host='127.0.0.1', port=6379, db=0) # result: # redis.exceptions.AuthenticationError: Authentication required.
-
测试连接_Go
package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func main() { conn,err := redis.Dial( "tcp", "127.0.0.1:6379", redis.DialPassword("passwd"), ) if err != nil{ panic(err) } defer conn.Close() _,err = conn.Do("SET","name","vs6785") name,err := redis.String(conn.Do("GET","name")) fmt.Println(name) }