本文整理匯總了C#中ServiceStack.Redis.RedisClient.As方法的典型用法代碼示例。如果您正苦於以下問題:C# RedisClient.As方法的具體用法?C# RedisClient.As怎麽用?C# RedisClient.As使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.As方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: OsmDataCacheRedis
/// <summary>
/// Creates a new osm data cache for simple OSM objects kept in memory.
/// </summary>
public OsmDataCacheRedis()
{
_client = new RedisClient();
_clientNode = _client.As<RedisNode>();
_clientWay = _client.As<RedisWay>();
_clientRelation = _client.As<RedisRelation>();
}
示例2: 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();
}
示例3: Main
static void Main(string[] args)
{
using (var redisClient = new RedisClient("localhost"))
{
while (true)
{
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
//Console.WriteLine("ping: " + ping + ", time: " + time);
//redisClient.DeleteAll<Counter>();
IRedisTypedClient<Counter> redis = redisClient.As<Counter>();
//var key = redis.GetAllKeys();
var c = redis.GetAndSetValue("the-counter", new Counter());
c.Value += 1;
redis.GetAndSetValue("the-counter", c);
Console.WriteLine("counter: " + c.Value);
Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
}
示例4: 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);
//---------------------------------------------
}
}
示例5: AboutPhone
public ActionResult AboutPhone()
{
string message = string.Empty;
string host = "localhost";
using (RedisClient redisClient = new RedisClient(host))
{
IRedisTypedClient<Phone> phones = redisClient.As<Phone>();
Phone phoneFive = phones.GetValue(5.ToString());
if (phoneFive == null)
{
// make a small delay
Thread.Sleep(5000);
phoneFive = new Phone
{
Id = 5,
Manufacturer = "Motorolla",
Model = "xxxxx",
Owner = new Person
{
Id = 1,
Age = 90,
Name = "OldOne",
Profession = "sportsmen",
Surname = "OldManSurname"
}
};
phones.SetEntry(phoneFive.Id.ToString(), phoneFive);
}
message = "Phone model is " + phoneFive.Manufacturer;
message += "Phone Owner Name is: " + phoneFive.Owner.Name;
message += "Phone Id is: " + phoneFive.Id.ToString();
}
ViewBag.Message = message;
return View("Index");
}
示例6: Teacher
public ViewResult Teacher()
{
using (var redis = new RedisClient(new Uri(connectionString))) {
var teacher = redis.As<Teacher>().GetAll().FirstOrDefault();
return View(teacher);
}
}
示例7: SetAsync
public Task<bool> SetAsync(string series, int index, long value)
{
using (var client = new RedisClient(Host))
{
var cache = client.As<Dictionary<int, long>>();
if (cache.ContainsKey(series))
{
cache[series][index] = value;
}
else
{
lock (cache)
{
cache.SetValue(series,
new Dictionary<int, long>()
{
[index] = value
});
}
}
return Task.FromResult(true);
}
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
using (var redisClient = new RedisClient("localhost"))
{
//DanhMucDal.ClearCache(CacheManager.Loai.Redis);
//LoaiDanhMucDal.ClearCache(CacheManager.Loai.Redis);
//var list = DanhMucDal.List;
var dm = redisClient.As<DanhMuc>();
var key = string.Format("urn:danhmuc:list");
var obj = dm.Lists[key];
Response.Write(obj.Count + "<br/>");
foreach (var item in obj.ToList())
{
Response.Write(string.Format("{0}:{1}", item.Ten,item.LoaiDanhMuc.Ten));
Response.Write(item.Ten + "<br/>");
}
Response.Write("<hr/>");
foreach (var _key in dm.GetAllKeys())
{
Response.Write(string.Format("{0}<br/>", _key));
}
}
}
示例9: UsingIRedisTypedClient
private static void UsingIRedisTypedClient(RedisClient client)
{
var redisTodos = client.As<Todo>();
// Mark all Todos, that have passed deadline, as DONE
redisTodos.GetAll()
.Where(t => t.Deadline >= DateTime.Now)
// Extension method to execute a lambda expression for each element of a IEnumerable<T>
.ForEach(t => t.IsDone = true);
var todo = new Todo()
{
Id = redisTodos.GetNextSequence(),
Text = "Todo created at " + DateTime.Now,
Deadline = DateTime.Now.AddDays(1),
IsDone = false,
AssignedTo = new User()
{
Name = "Nakov"
}
};
redisTodos.Store(todo);
redisTodos.GetAll()
.Print();
}
示例10: Main
static void Main(string[] args)
{
try
{
var redisClient = new RedisClient("10.1.200.83", 6379);
Console.WriteLine(redisClient.Get<string>("city"));
Console.WriteLine(redisClient.Get<string>("tongcheng"));
Console.WriteLine("Test");
var redisUser = redisClient.As<User>();
redisUser.Store(new User()
{
Name = "gu yang",
Password = "redis use"
});
var user = redisUser.GetAll();
Console.WriteLine(user.First().Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
示例11: 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});
}
示例12: DeleteAllTechnologyRadarPosts
public void DeleteAllTechnologyRadarPosts()
{
using (var redisClient = new RedisClient("mtl-ba584:6379"))
{
var redis = redisClient.As<PostElement>();
redis.Lists["technologyradar"].RemoveAll();
}
}
示例13: DeleteAllDailyPosts
public void DeleteAllDailyPosts()
{
using (var redisClient = new RedisClient("mtl-ba584:6379"))
{
var redis = redisClient.As<PostElement>();
redis.Lists["dailyposts"].RemoveAll();
}
}
示例14: setProductos
public void setProductos(IEnumerable<Producto> productos)
{
using (IRedisClient redisClient = new RedisClient(host, port, password, 1))//creamos nuestro objeto de conexion.
{
//creamos un objeto IRedisTypedClient y le especificamos que trabajara con nuestra clase Producto como tipo.
IRedisTypedClient<Producto> redisTypeClient = redisClient.As<Producto>();
redisTypeClient.StoreAll(productos);//almacenamos todos nuestros productos.
}
}
示例15: Main
private static void Main(string[] args)
{
using (var client = new RedisClient())
{
var clientServices = client.As<ServiceDto>();
services = clientServices.Lists["SERVICE"].ToList();
}
services.ForEach(service => SaveResults(InvokeService(service)));
}