Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
711 B · 43 lines
Go
1234567891011121314151617181920212223242526272829303132333435363738394041424344package cursor
import ( "context" "fmt" "strconv"
"tangled.org/core/appview/cache")
const ( cursorKey = "cursor:%s")
type RedisStore struct { rdb *cache.Cache}
func NewRedisCursorStore(cache *cache.Cache) RedisStore { return RedisStore{ rdb: cache, }}
func (r *RedisStore) Set(knot string, cursor int64) { key := fmt.Sprintf(cursorKey, knot) r.rdb.Set(context.Background(), key, cursor, 0)}
func (r *RedisStore) Get(knot string) (cursor int64) { key := fmt.Sprintf(cursorKey, knot) val, err := r.rdb.Get(context.Background(), key).Result() if err != nil { return 0 } cursor, err = strconv.ParseInt(val, 10, 64) if err != nil { // TODO: log here return 0 }
return cursor}