Redis配置密码 Ubuntu 服务器

ubuntu Redis 配置密码

  • 通过配置文件配置

    vim /etc/redis/redis.conf 
    
  • 修改配置文件 增添

    requirepass passwd
    

    Redis配置密码 Ubuntu 服务器_第1张图片

  • 重启服务

    service redis-server restart
    
  • 测试连接_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)
    }
    

你可能感兴趣的:(Redis,GO,Python,redis,python,linux,ubuntu)