本文整理汇总了C#中ServiceStack.Redis.RedisClient.GetRangeWithScoresFromSortedSet方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.GetRangeWithScoresFromSortedSet方法的具体用法?C# RedisClient.GetRangeWithScoresFromSortedSet怎么用?C# RedisClient.GetRangeWithScoresFromSortedSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.GetRangeWithScoresFromSortedSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
//---------------------------------------------
}
}
示例2: 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);
//---------------------------------------------
}
}
示例3: GetRanks
public JsonResult GetRanks()
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank",0,4);
List<Item> RankList = new List<Item>();
int counter = 0;
foreach(var item in Data)
{
counter++;
RankList.Add(new Item() { Name = item.Key, Price = (int)item.Value, Id=counter });
}
return Json(RankList, JsonRequestBehavior.AllowGet);
}
}