本文整理匯總了C#中ServiceStack.Redis.RedisClient.AddItemToSortedSet方法的典型用法代碼示例。如果您正苦於以下問題:C# RedisClient.AddItemToSortedSet方法的具體用法?C# RedisClient.AddItemToSortedSet怎麽用?C# RedisClient.AddItemToSortedSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.AddItemToSortedSet方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Index
// GET: Tracker
public ActionResult Index(long userId, int amount = 0)
{
using (IRedisClient client = new RedisClient())
{
var userClient = client.As<User>();
var user = userClient.GetById(userId);
var historyClient = client.As<int>();
var historyList = historyClient.Lists["urn:history:" + userId];
if (amount > 0)
{
user.Total += amount;
userClient.Store(user);
historyList.Prepend(amount);
historyList.Trim(0, 4);
client.AddItemToSortedSet("urn:leaderboard", user.Name, user.Total);
}
ViewBag.HistoryItems = historyList.GetAll();
ViewBag.UserName = user.Name;
ViewBag.Total = user.Total;
ViewBag.Goal = user.Goal;
ViewBag.UserId = user.Id;
}
return View();
}
示例2: Save
public ActionResult Save(string userName, int goal, long? userId)
{
using (IRedisClient client = new RedisClient())
{
var userClient = client.As<User>();
User user;
if (userId != null)
{
user = userClient.GetById(userId);
client.RemoveItemFromSortedSet("urn:leaderboard", user.Name);
}
else
{
user = new User()
{
Id = userClient.GetNextSequence()
};
}
user.Name = userName;
user.Goal = goal;
userClient.Store(user);
userId = user.Id;
client.AddItemToSortedSet("urn:leaderboard", userName, user.Total);
}
return RedirectToAction("Index", "Tracker", new { userId});
}
示例3: SaveItem
public void SaveItem(Item item)
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
var itemClient = client.As<Item>();
var itemList = itemClient.Lists["urn:item:" + item.ProductID];
item.Id = itemClient.GetNextSequence();
itemList.Add(item);
client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);
//Publis top 5 Ranked Items
IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
List<Item> RankList = new List<Item>();
int counter = 0;
foreach (var itm in Data)
{
counter++;
RankList.Add(new Item() { Name = itm.Key, Price = (int)itm.Value, Id = counter });
}
var itemJson = JsonConvert.SerializeObject(RankList);
client.PublishMessage("Rank", itemJson);
//---------------------------------------------
}
}
示例4: TestSortSet
private static void TestSortSet()
{
using (var client = new RedisClient("127.0.0.1", 6379))
{
#region "有序Set操作"
client.AddItemToSortedSet("HQF.Tutorial.Redis:SA", "B", 2);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SA", "C", 1);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SA", "D", 5);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SA", "E", 3);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SA", "F", 4);
//有序集合降序排列
Console.WriteLine("\n有序集合降序排列");
client.GetAllItemsFromSortedSetDesc("HQF.Tutorial.Redis:SA").ForEach(e => Console.Write(e + ","));
Console.WriteLine("\n有序集合升序序排列");
client.GetAllItemsFromSortedSet("HQF.Tutorial.Redis:SA").ForEach(e => Console.Write(e + ","));
client.AddItemToSortedSet("HQF.Tutorial.Redis:SB", "C", 2);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SB", "F", 1);
client.AddItemToSortedSet("HQF.Tutorial.Redis:SB", "D", 3);
Console.WriteLine("\n獲得某個值在有序集合中的排名,按分數的升序排列");
Console.WriteLine(client.GetItemIndexInSortedSet("HQF.Tutorial.Redis:SB", "D"));
Console.WriteLine("\n獲得有序集合中某個值得分數");
Console.WriteLine(client.GetItemScoreInSortedSet("HQF.Tutorial.Redis:SB", "D"));
Console.WriteLine("\n獲得有序集合中,某個排名範圍的所有值");
client.GetRangeFromSortedSet("HQF.Tutorial.Redis:SA", 0, 3).ForEach(e => Console.Write(e + ","));
#endregion
}
}
示例5: UpdateItem
public void UpdateItem(Item item)
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
IRedisTypedClient<Item> itemClient = client.As<Item>();
IRedisList<Item> itemList = itemClient.Lists["urn:item:" + item.ProductID];
var index = itemList.Select((Value, Index) => new { Value, Index })
.Single(p => p.Value.Id == item.Id).Index;
var toUpdateItem = itemList.First(x => x.Id == item.Id);
//var index = itemList.IndexOf(toUpdateItem);
toUpdateItem.Name = item.Name;
toUpdateItem.Price = item.Price;
itemList.RemoveAt(index);
if (itemList.Count - 1 < index)
itemList.Add(toUpdateItem);
else itemList.Insert(index, toUpdateItem);
client.RemoveItemFromSortedSet("urn:Rank", item.Name);
client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);
//Publis top 5 Ranked Items
IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
List<Item> RankList = new List<Item>();
int counter = 0;
foreach (var itm in Data)
{
counter++;
RankList.Add(new Item() { Name = itm.Key, Price = (int)itm.Value, Id = counter });
}
var itemJson = JsonConvert.SerializeObject(RankList);
client.PublishMessage("Rank", itemJson);
//---------------------------------------------
}
}