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.

48 lines
994 B

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