Skip to content
Snippets Groups Projects
Select Git revision
  • 7e601d485aa44ddbffe5e4a3c800d42600a6b91c
  • master default protected
  • greenkeeper/webpack-4.10.1
  • greenkeeper/webpack-4.10.0
  • greenkeeper/webpack-4.9.2
  • greenkeeper/promise-polyfill-8.0.0
  • greenkeeper/webpack-4.9.1
  • greenkeeper/webpack-4.9.0
  • greenkeeper/webpack-manifest-plugin-2.0.3
  • greenkeeper/update-to-node-10
  • gh-pages
  • greenkeeper/webpack-4.8.3
  • greenkeeper/webpack-4.8.2
  • greenkeeper/webpack-4.7.0
  • greenkeeper/webpack-manifest-plugin-2.0.2
  • greenkeeper/webpack-manifest-plugin-2.0.1
  • greenkeeper/style-loader-0.21.0
  • greenkeeper/webpack-4.6.0
  • greenkeeper/sass-loader-7.0.1
  • greenkeeper/sass-loader-7.0.0
  • greenkeeper/webpack-manifest-plugin-2.0.0
  • 2.7.3
  • 2.7.2
  • 2.7.1
  • 2.7.0
  • 2.6.6
  • 2.6.5
  • 2.6.4
  • 2.6.3
  • 2.6.2
  • 2.6.1
  • 2.6.0
  • 2.5.5
  • 2.5.4
  • 2.5.3
  • 2.5.2
  • 2.5.1
  • 2.5.0
  • 2.4.0
  • 2.3.0
  • 2.2.6
41 results

start

Blame
  • cache_redis.go 988 B
    package main
    
    import (
    	"encoding/json"
    	"errors"
    	"git.kuschku.de/justjanne/bahn-api"
    	"github.com/go-redis/cache"
    	"github.com/go-redis/redis"
    	"time"
    )
    
    type RedisCache struct {
    	backend        *cache.Codec
    	expirationTime time.Duration
    }
    
    func (m RedisCache) Set(key string, value interface{}) error {
    	return m.backend.Set(&cache.Item{
    		Key:        key,
    		Object:     value,
    		Expiration: m.expirationTime,
    	})
    }
    
    func (m RedisCache) Get(key string, value interface{}) error {
    	err := m.backend.Get(key, &value)
    	if err != nil {
    		return err
    	} else if value == nil {
    		return errors.New("redis returned empty result")
    	}
    	return nil
    }
    
    func NewRedisCache(address string, password string, expirationTime time.Duration) bahn.CacheBackend {
    	return RedisCache{
    		backend: &cache.Codec{
    			Redis: redis.NewClient(&redis.Options{
    				Addr:     address,
    				Password: password,
    			}),
    			Marshal:   json.Marshal,
    			Unmarshal: json.Unmarshal,
    		},
    		expirationTime: expirationTime,
    	}
    }