Chris Lu
10 years ago
5 changed files with 87 additions and 17 deletions
-
31docs/distributed_filer.rst
-
48go/filer/redis_store/redis_store.go
-
5go/weed/filer.go
-
1go/weed/server.go
-
19go/weed/weed_server/filer_server.go
@ -0,0 +1,48 @@ |
|||
package redis_store |
|||
|
|||
import ( |
|||
redis "gopkg.in/redis.v2" |
|||
) |
|||
|
|||
type RedisStore struct { |
|||
Client *redis.Client |
|||
} |
|||
|
|||
func NewRedisStore(hostPort string, database int) *RedisStore { |
|||
client := redis.NewTCPClient(&redis.Options{ |
|||
Addr: hostPort, |
|||
Password: "", // no password set
|
|||
DB: int64(database), |
|||
}) |
|||
return &RedisStore{Client: client} |
|||
} |
|||
|
|||
func (s *RedisStore) Get(fullFileName string) (fid string, err error) { |
|||
fid, err = s.Client.Get(fullFileName).Result() |
|||
if err == redis.Nil { |
|||
err = nil |
|||
} |
|||
return fid, err |
|||
} |
|||
func (s *RedisStore) Put(fullFileName string, fid string) (err error) { |
|||
_, err = s.Client.Set(fullFileName, fid).Result() |
|||
if err == redis.Nil { |
|||
err = nil |
|||
} |
|||
return err |
|||
} |
|||
|
|||
// Currently the fid is not returned
|
|||
func (s *RedisStore) Delete(fullFileName string) (fid string, err error) { |
|||
_, err = s.Client.Del(fullFileName).Result() |
|||
if err == redis.Nil { |
|||
err = nil |
|||
} |
|||
return "", err |
|||
} |
|||
|
|||
func (c *RedisStore) Close() { |
|||
if c.Client != nil { |
|||
c.Client.Close() |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue