Documentation ¶
Index ¶
- Constants
- Variables
- func GetScores(s []Scored) []float64
- 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) AddSorted(_ string, _ []Scored) error
- func (NoDatabase) Close() error
- func (NoDatabase) Delete(_, _ string) error
- func (NoDatabase) Exists(_ string, _ ...string) ([]int, error)
- func (NoDatabase) GetInt(_, _ string) (int, error)
- func (NoDatabase) GetSet(_ string) ([]string, error)
- func (NoDatabase) GetSorted(_ string, _, _ int) ([]Scored, error)
- func (NoDatabase) GetSortedByScore(_ string, _, _ float64) ([]Scored, error)
- func (NoDatabase) GetSortedScore(_, _ string) (float64, 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) RemSortedByScore(_ string, _, _ float64) error
- func (NoDatabase) SetInt(_, _ string, _ int) 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) AddSorted(key string, scores []Scored) 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) GetSortedByScore(key string, begin, end float64) ([]Scored, error)
- func (r *Redis) GetSortedScore(key, member string) (float64, 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) RemSortedByScore(key string, begin, end float64) 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 is sorted set of ignored items for each user // Ignored items - ignore_items/{user_id} IgnoreItems = "ignore_items" HiddenItems = "hidden_items" // hidden items // ItemNeighbors is sorted set of neighbors for each item. // Global item neighbors - item_neighbors/{item_id} // Categorized item neighbors - item_neighbors/{item_id}/{category} ItemNeighbors = "item_neighbors" // UserNeighbors is sorted set of neighbors for each user. // User neighbors - user_neighbors/{user_id} UserNeighbors = "user_neighbors" // CollaborativeRecommend is sorted set of collaborative filtering recommendations for each user. // Global recommendation - collaborative_recommend/{user_id} // Categorized recommendation - collaborative_recommend/{user_id}/{category} CollaborativeRecommend = "collaborative_recommend" // collaborative filtering recommendation for each user // OfflineRecommend is sorted set of offline recommendation for each user. // Global recommendation - offline_recommend/{user_id} // Categorized recommendation - offline_recommend/{user_id}/{category} 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 the latest items - latest_items/{category} LatestItems = "latest_items" // ItemCategories is the set of item categories. The format of key: // Global item categories - item_categories 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 // GlobalMeta is global meta information GlobalMeta = "global_meta" DataImported = "data_imported" NumUsers = "num_users" NumItems = "num_items" NumUserLabels = "num_user_labels" NumItemLabels = "num_item_labels" NumTotalPosFeedbacks = "num_total_pos_feedbacks" NumValidPosFeedbacks = "num_valid_pos_feedbacks" NumValidNegFeedbacks = "num_valid_neg_feedbacks" LastFitMatchingModelTime = "last_fit_matching_model_time" LastFitRankingModelTime = "last_fit_ranking_model_time" 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 UserNeighborIndexRecall = "user_neighbor_index_recall" ItemNeighborIndexRecall = "item_neighbor_index_recall" MatchingIndexRecall = "matching_index_recall" )
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 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) (float64, error) GetSorted(key string, begin, end int) ([]Scored, error) GetSortedByScore(key string, begin, end float64) ([]Scored, error) RemSortedByScore(key string, begin, end float64) error AddSorted(key string, scores []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) AddSorted ¶ added in v0.3.2
func (NoDatabase) AddSorted(_ string, _ []Scored) error
AddSorted 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) GetInt ¶
func (NoDatabase) GetInt(_, _ string) (int, error)
GetInt 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) GetSortedByScore ¶ added in v0.3.3
func (NoDatabase) GetSortedByScore(_ string, _, _ float64) ([]Scored, error)
GetSortedByScore method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetSortedScore ¶ added in v0.3.1
func (NoDatabase) GetSortedScore(_, _ string) (float64, 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) RemSortedByScore ¶ added in v0.3.4
func (NoDatabase) RemSortedByScore(_ string, _, _ float64) error
RemSortedByScore method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) SetInt ¶
func (NoDatabase) SetInt(_, _ string, _ int) error
SetInt 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) GetSortedByScore ¶ added in v0.3.3
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) RemSortedByScore ¶ added in v0.3.4
func (*Redis) SetCategoryScores ¶ added in v0.3.0
SetCategoryScores method of NoDatabase returns ErrNoDatabase.
func (*Redis) SetSorted ¶ added in v0.3.1
SetSorted set scores in sorted set and clear previous scores.