Documentation ¶
Index ¶
- Constants
- Variables
- func Key(keys ...string) string
- func RemoveScores(items []Scored) []string
- func SortScores(scores []Scored)
- type Database
- type NoDatabase
- func (NoDatabase) AddSet(_ string, _ ...string) error
- func (NoDatabase) AppendScores(_, _ string, _ ...Scored) error
- func (NoDatabase) ClearScores(_, _ string) error
- func (NoDatabase) Close() error
- func (NoDatabase) Delete(_, _ string) error
- func (NoDatabase) Exists(_ string, _ ...string) ([]int, error)
- func (NoDatabase) GetCategoryScores(_, _, _ string, _, _ int) ([]Scored, error)
- func (NoDatabase) GetInt(_, _ string) (int, error)
- func (NoDatabase) GetScores(_, _ string, _, _ int) ([]Scored, error)
- func (NoDatabase) GetSet(_ string) ([]string, error)
- func (NoDatabase) GetSorted(_ string, _, _ int) ([]Scored, error)
- func (NoDatabase) GetSortedScore(_, _ string) (float32, error)
- func (NoDatabase) GetString(_, _ string) (string, error)
- func (NoDatabase) GetTime(_, _ string) (time.Time, error)
- func (NoDatabase) IncrInt(_, _ string) error
- func (NoDatabase) IncrSorted(_, _ string) error
- func (NoDatabase) RemSet(_ string, _ ...string) error
- func (NoDatabase) RemSorted(_, _ string) error
- func (NoDatabase) SetCategoryScores(_, _, _ string, _ []Scored) error
- func (NoDatabase) SetInt(_, _ string, _ int) error
- func (NoDatabase) SetScores(_, _ string, _ []Scored) error
- func (NoDatabase) SetSet(_ string, _ ...string) error
- func (NoDatabase) SetSorted(_ string, _ []Scored) error
- func (NoDatabase) SetString(_, _, _ string) error
- func (NoDatabase) SetTime(_, _ string, _ time.Time) error
- type Redis
- func (r *Redis) AddSet(key string, members ...string) error
- func (r *Redis) AppendScores(prefix, name string, items ...Scored) error
- func (r *Redis) ClearScores(prefix, name string) error
- func (r *Redis) Close() error
- func (r *Redis) Delete(prefix, name string) error
- func (r *Redis) Exists(prefix string, names ...string) ([]int, error)
- func (r *Redis) GetCategoryScores(prefix, name, category string, begin, end int) ([]Scored, error)
- func (r *Redis) GetInt(prefix, name string) (int, error)
- func (r *Redis) GetScores(prefix, name string, begin, end int) ([]Scored, error)
- func (r *Redis) GetSet(key string) ([]string, error)
- func (r *Redis) GetSorted(key string, begin, end int) ([]Scored, error)
- func (r *Redis) GetSortedScore(key, member string) (float32, error)
- func (r *Redis) GetString(prefix, name string) (string, error)
- func (r *Redis) GetTime(prefix, name string) (time.Time, error)
- func (r *Redis) IncrInt(prefix, name string) error
- func (r *Redis) IncrSorted(key, member string) error
- func (r *Redis) RemSet(key string, members ...string) error
- func (r *Redis) RemSorted(key, member string) error
- func (r *Redis) SetCategoryScores(prefix, name, category string, items []Scored) error
- func (r *Redis) SetInt(prefix, name string, val int) error
- func (r *Redis) SetScores(prefix, name string, items []Scored) error
- func (r *Redis) SetSet(key string, members ...string) error
- func (r *Redis) SetSorted(key string, scores []Scored) error
- func (r *Redis) SetString(prefix, name, val string) error
- func (r *Redis) SetTime(prefix, name string, val time.Time) error
- type Scored
Constants ¶
const ( IgnoreItems = "ignore_items" // ignored items for each user HiddenItems = "hidden_items" // hidden items ItemNeighbors = "item_neighbors" // neighbors of each item UserNeighbors = "user_neighbors" // neighbors of each user CollaborativeRecommend = "collaborative_recommend" // collaborative filtering recommendation for each user OfflineRecommend = "offline_recommend" // offline recommendation for each user // PopularItems is sorted set of popular items. The format of key: // Global popular items - latest_items // Categorized popular items - latest_items/{category} PopularItems = "popular_items" // LatestItems is sorted set of the latest items. The format of key: // Global latest items - latest_items // Categorized latest items - latest_items/{category} LatestItems = "latest_items" // ItemCategories is the set of item categories. The format of key: // Global item categories - item_categories // Categories of an item - item_categories/{item_id} ItemCategories = "item_categories" LastModifyItemTime = "last_modify_item_time" // the latest timestamp that a user related data was modified LastModifyUserTime = "last_modify_user_time" // the latest timestamp that an item related data was modified LastUpdateUserRecommendTime = "last_update_user_recommend_time" // the latest timestamp that a user's recommendation was updated LastUpdateUserNeighborsTime = "last_update_user_neighbors_time" // the latest timestamp that a user's neighbors item was updated LastUpdateItemNeighborsTime = "last_update_item_neighbors_time" // the latest timestamp that an item's neighbors was updated LastUpdateLatestItemsTime = "last_update_latest_items_time" // the latest timestamp that latest items were updated LastUpdatePopularItemsTime = "last_update_popular_items_time" // the latest timestamp that popular items were updated // GlobalMeta is global meta information GlobalMeta = "global_meta" DataImported = "data_imported" LastFitRankingModelTime = "last_fit_match_model_time" LastRankingModelVersion = "latest_match_model_version" )
Variables ¶
var ( ErrObjectNotExist = errors.NotFoundf("object") ErrNoDatabase = errors.NotAssignedf("database") )
var ( SetScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: "gorse", Subsystem: "cache", Name: "set_scores_seconds", }) GetScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: "gorse", Subsystem: "cache", Name: "get_scores_seconds", }) ClearScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: "gorse", Subsystem: "cache", Name: "clear_scores_seconds", }) AppendScoresSeconds = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: "gorse", Subsystem: "cache", Name: "append_scores_seconds", }) )
Functions ¶
func RemoveScores ¶
RemoveScores resolve items for a slice of ScoredItems.
func SortScores ¶ added in v0.3.1
func SortScores(scores []Scored)
SortScores sorts scores from high score to low score.
Types ¶
type Database ¶
type Database interface { Close() error SetScores(prefix, name string, items []Scored) error GetScores(prefix, name string, begin int, end int) ([]Scored, error) ClearScores(prefix, name string) error AppendScores(prefix, name string, items ...Scored) error SetCategoryScores(prefix, name, category string, items []Scored) error GetCategoryScores(prefix, name, category string, begin, end int) ([]Scored, error) GetString(prefix, name string) (string, error) SetString(prefix, name string, val string) error GetTime(prefix, name string) (time.Time, error) SetTime(prefix, name string, val time.Time) error GetInt(prefix, name string) (int, error) SetInt(prefix, name string, val int) error IncrInt(prefix, name string) error Delete(prefix, name string) error Exists(prefix string, names ...string) ([]int, error) GetSet(key string) ([]string, error) SetSet(key string, members ...string) error AddSet(key string, members ...string) error RemSet(key string, members ...string) error GetSortedScore(key, member string) (float32, error) GetSorted(key string, begin, end int) ([]Scored, error) SetSorted(key string, scores []Scored) error IncrSorted(key, member string) error RemSorted(key, member string) error }
Database is the common interface for cache store.
type NoDatabase ¶
type NoDatabase struct{}
NoDatabase means no database used for cache.
func (NoDatabase) AddSet ¶ added in v0.3.1
func (NoDatabase) AddSet(_ string, _ ...string) error
AddSet method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) AppendScores ¶ added in v0.2.7
func (NoDatabase) AppendScores(_, _ string, _ ...Scored) error
AppendScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) ClearScores ¶ added in v0.2.7
func (NoDatabase) ClearScores(_, _ string) error
ClearScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Close ¶
func (NoDatabase) Close() error
Close method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Delete ¶ added in v0.3.1
func (NoDatabase) Delete(_, _ string) error
Delete method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Exists ¶ added in v0.3.1
func (NoDatabase) Exists(_ string, _ ...string) ([]int, error)
Exists method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetCategoryScores ¶ added in v0.3.0
func (NoDatabase) GetCategoryScores(_, _, _ string, _, _ int) ([]Scored, error)
GetCategoryScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetInt ¶
func (NoDatabase) GetInt(_, _ string) (int, error)
GetInt method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetScores ¶
func (NoDatabase) GetScores(_, _ string, _, _ int) ([]Scored, error)
GetScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetSet ¶ added in v0.3.1
func (NoDatabase) GetSet(_ string) ([]string, error)
GetSet method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetSorted ¶ added in v0.3.1
func (NoDatabase) GetSorted(_ string, _, _ int) ([]Scored, error)
GetSorted method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetSortedScore ¶ added in v0.3.1
func (NoDatabase) GetSortedScore(_, _ string) (float32, error)
GetSortedScore method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetString ¶
func (NoDatabase) GetString(_, _ string) (string, error)
GetString method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetTime ¶
func (NoDatabase) GetTime(_, _ string) (time.Time, error)
GetTime method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) IncrInt ¶
func (NoDatabase) IncrInt(_, _ string) error
IncrInt method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) IncrSorted ¶ added in v0.3.1
func (NoDatabase) IncrSorted(_, _ string) error
IncrSorted method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) RemSet ¶ added in v0.3.1
func (NoDatabase) RemSet(_ string, _ ...string) error
RemSet method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) RemSorted ¶ added in v0.3.1
func (NoDatabase) RemSorted(_, _ string) error
RemSorted method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetCategoryScores ¶ added in v0.3.0
func (NoDatabase) SetCategoryScores(_, _, _ string, _ []Scored) error
SetCategoryScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetInt ¶
func (NoDatabase) SetInt(_, _ string, _ int) error
SetInt method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetScores ¶
func (NoDatabase) SetScores(_, _ string, _ []Scored) error
SetScores method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetSet ¶ added in v0.3.1
func (NoDatabase) SetSet(_ string, _ ...string) error
SetSet method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetSorted ¶ added in v0.3.1
func (NoDatabase) SetSorted(_ string, _ []Scored) error
SetSorted method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetString ¶
func (NoDatabase) SetString(_, _, _ string) error
SetString method of NoDatabase returns ErrNoDatabase.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis cache storage.
func (*Redis) AppendScores ¶ added in v0.2.7
AppendScores appends a list of scored items to Redis.
func (*Redis) ClearScores ¶ added in v0.2.7
ClearScores clears a list of scored items in Redis.
func (*Redis) GetCategoryScores ¶ added in v0.3.0
GetCategoryScores method of NoDatabase returns ErrNoDatabase.
func (*Redis) GetSortedScore ¶ added in v0.3.1
GetSortedScore get the score of a member from sorted set.
func (*Redis) IncrSorted ¶ added in v0.3.1
IncrSorted increase score in sorted set.
func (*Redis) SetCategoryScores ¶ added in v0.3.0
SetCategoryScores method of NoDatabase returns ErrNoDatabase.