add redis password

fix https://github.com/chrislusf/seaweedfs/issues/263
This commit is contained in:
chrislusf 2016-03-08 08:46:28 -08:00
parent f7f9129b05
commit 4c8367a8b3
4 changed files with 9 additions and 6 deletions

View File

@ -8,10 +8,10 @@ type RedisStore struct {
Client *redis.Client
}
func NewRedisStore(hostPort string, database int) *RedisStore {
func NewRedisStore(hostPort string, password string, database int) *RedisStore {
client := redis.NewTCPClient(&redis.Options{
Addr: hostPort,
Password: "", // no password set
Password: password,
DB: int64(database),
})
return &RedisStore{Client: client}

View File

@ -27,6 +27,7 @@ type FilerOptions struct {
cassandra_server *string
cassandra_keyspace *string
redis_server *string
redis_password *string
redis_database *int
}
@ -42,6 +43,7 @@ func init() {
f.cassandra_server = cmdFiler.Flag.String("cassandra.server", "", "host[:port] of the cassandra server")
f.cassandra_keyspace = cmdFiler.Flag.String("cassandra.keyspace", "seaweed", "keyspace of the cassandra server")
f.redis_server = cmdFiler.Flag.String("redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379")
f.redis_password = cmdFiler.Flag.String("redis.password", "", "password in clear text")
f.redis_database = cmdFiler.Flag.Int("redis.database", 0, "the database on the redis server")
f.secretKey = cmdFiler.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
@ -80,7 +82,7 @@ func runFiler(cmd *Command, args []string) bool {
*f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing,
*f.secretKey,
*f.cassandra_server, *f.cassandra_keyspace,
*f.redis_server, *f.redis_database,
*f.redis_server, *f.redis_password, *f.redis_database,
)
if nfs_err != nil {
glog.Fatalf("Filer startup error: %v", nfs_err)

View File

@ -89,6 +89,7 @@ func init() {
filerOptions.cassandra_server = cmdServer.Flag.String("filer.cassandra.server", "", "host[:port] of the cassandra server")
filerOptions.cassandra_keyspace = cmdServer.Flag.String("filer.cassandra.keyspace", "seaweed", "keyspace of the cassandra server")
filerOptions.redis_server = cmdServer.Flag.String("filer.redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379")
filerOptions.redis_password = cmdServer.Flag.String("filer.redis.password", "", "redis password in clear text")
filerOptions.redis_database = cmdServer.Flag.Int("filer.redis.database", 0, "the database on the redis server")
}
@ -169,7 +170,7 @@ func runServer(cmd *Command, args []string) bool {
*filerOptions.redirectOnRead, *filerOptions.disableDirListing,
*filerOptions.secretKey,
*filerOptions.cassandra_server, *filerOptions.cassandra_keyspace,
*filerOptions.redis_server, *filerOptions.redis_database,
*filerOptions.redis_server, *filerOptions.redis_password, *filerOptions.redis_database,
)
if nfs_err != nil {
glog.Fatalf("Filer startup error: %v", nfs_err)

View File

@ -28,7 +28,7 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle
replication string, redirectOnRead bool, disableDirListing bool,
secret string,
cassandra_server string, cassandra_keyspace string,
redis_server string, redis_database int,
redis_server string, redis_password string, redis_database int,
) (fs *FilerServer, err error) {
fs = &FilerServer{
master: master,
@ -46,7 +46,7 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle
}
fs.filer = flat_namespace.NewFlatNamespaceFiler(master, cassandra_store)
} else if redis_server != "" {
redis_store := redis_store.NewRedisStore(redis_server, redis_database)
redis_store := redis_store.NewRedisStore(redis_server, redis_password, redis_database)
fs.filer = flat_namespace.NewFlatNamespaceFiler(master, redis_store)
} else {
if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {