You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

  1. package redis_store
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. redis "gopkg.in/redis.v2"
  5. )
  6. type RedisStore struct {
  7. Client *redis.Client
  8. }
  9. func NewRedisStore(hostPort string, password string, database int) *RedisStore {
  10. client := redis.NewTCPClient(&redis.Options{
  11. Addr: hostPort,
  12. Password: password,
  13. DB: int64(database),
  14. })
  15. return &RedisStore{Client: client}
  16. }
  17. func (s *RedisStore) Get(fullFileName string) (fid string, err error) {
  18. fid, err = s.Client.Get(fullFileName).Result()
  19. if err == redis.Nil {
  20. err = filer.ErrNotFound
  21. }
  22. return fid, err
  23. }
  24. func (s *RedisStore) Put(fullFileName string, fid string) (err error) {
  25. _, err = s.Client.Set(fullFileName, fid).Result()
  26. if err == redis.Nil {
  27. err = nil
  28. }
  29. return err
  30. }
  31. // Currently the fid is not returned
  32. func (s *RedisStore) Delete(fullFileName string) (err error) {
  33. _, err = s.Client.Del(fullFileName).Result()
  34. if err == redis.Nil {
  35. err = nil
  36. }
  37. return err
  38. }
  39. func (s *RedisStore) Close() {
  40. if s.Client != nil {
  41. s.Client.Close()
  42. }
  43. }