mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-03 16:04:30 +00:00
37 lines
690 B
Ruby
37 lines
690 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module Redis
|
|
class CursorStore
|
|
def initialize(namespace, ttl: 1.hour)
|
|
@namespace = namespace
|
|
@ttl = ttl.to_i
|
|
end
|
|
|
|
def commit(payload)
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
redis.set(cache_key, payload.to_json, ex: ttl)
|
|
end
|
|
end
|
|
|
|
def cursor
|
|
Gitlab::Json.parse(value_on_redis).to_h
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :namespace, :ttl
|
|
|
|
def cache_key
|
|
"CursorStore:#{namespace}"
|
|
end
|
|
|
|
def value_on_redis
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
redis.get(cache_key)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|