本文整理汇总了C#中ServiceStack.Redis.RedisClient类的典型用法代码示例。如果您正苦于以下问题:C# RedisClient类的具体用法?C# RedisClient怎么用?C# RedisClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RedisClient类属于ServiceStack.Redis命名空间,在下文中一共展示了RedisClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CreateRedisClient
/// <summary>
/// Create a shared client for redis
/// </summary>
/// <returns></returns>
public static RedisClient CreateRedisClient()
{
var redisUri = new Uri(ConfigurationManager.AppSettings.Get("REDISTOGO_URL"));
var redisClient = new RedisClient(redisUri.Host, redisUri.Port);
redisClient.Password = "553eee0ecf0a87501f5c67cb4302fc55";
return redisClient;
}
示例3: 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);
}
}
示例4: RedisSubscription
public RedisSubscription(RedisClient redisClient)
{
this.redisClient = redisClient;
this.SubscriptionCount = 0;
this.activeChannels = new List<string>();
}
示例5: NotifySubscribers
private void NotifySubscribers(string queueName)
{
using (var client = new RedisClient("localhost"))
{
client.PublishMessage(queueName, NewItem);
}
}
示例6: Subscribe
public void Subscribe(string queueName, Action action)
{
Task.Factory.StartNew(() =>
{
using (var client1 = new RedisClient("localhost"))
{
using (var subscription1 = client1.CreateSubscription())
{
subscription1.OnSubscribe =
channel => Debug.WriteLine(string.Format("Subscribed to '{0}'", channel));
subscription1.OnUnSubscribe =
channel => Debug.WriteLine(string.Format("UnSubscribed from '{0}'", channel));
subscription1.OnMessage = (channel, msg) =>
{
Debug.WriteLine(string.Format("Received '{0}' from channel '{1}' Busy: {2}", msg, channel, false));
action();
};
subscription1.SubscribeToChannels(queueName);
Debug.WriteLine("Subscribed");
}
}
}).Start();
}
示例7: Dequeue
public int Dequeue(string queueName)
{
using (var client = new RedisClient("localhost"))
{
return Convert.ToInt32(client.Lists[queueName].Pop());
}
}
示例8: Clear
public void Clear(string queueName)
{
using (var client = new RedisClient("localhost"))
{
client.Lists[queueName].Clear();
}
}
示例9: 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));
}
}
}
示例10: CreateClient
private IRedisClient CreateClient()
{
var hosts = _host.Split(':');
var client = new RedisClient(hosts[0], Int32.Parse(hosts[1]));
client.Password = _password;
return client;
}
示例11: Teacher
public ViewResult Teacher()
{
using (var redis = new RedisClient(new Uri(connectionString))) {
var teacher = redis.As<Teacher>().GetAll().FirstOrDefault();
return View(teacher);
}
}
示例12: GetBalance
public UserBalance GetBalance(string accountName)
{
using (RedisClient redis = new RedisClient(redisCloudUrl.Value))
{
return redis.Get<UserBalance>(accountName) ?? new UserBalance();
}
}
示例13: Main
static void Main(string[] args)
{
var dictionaryData = new string[,]
{
{ ".NET", "platform for applications from Microsoft" },
{ "CLR", "managed execution environment for .NET" },
{ "namespace", "hierarchical organization of classes" },
{ "database", "structured sets of persistent updateable and queriable data" },
{ "blob", "binary large object" },
{ "RDBMS", "relational database management system" },
{ "json", "JavaScript Object Notation" },
{ "xml", "Extensible Markup Language" },
};
using (var redisClient = new RedisClient("127.0.0.1:6379"))
{
for (int i = 0; i < dictionaryData.GetLength(0); i++)
{
if (redisClient.HExists("dictionary", ToByteArray(dictionaryData[i, 0])) == 0)
{
redisClient.HSetNX("dictionary", ToByteArray(dictionaryData[i, 0]), ToByteArray(dictionaryData[i, 1]));
}
}
PrintAllWords(redisClient);
Console.WriteLine("\nSearch for word \"blob\":");
FindWord(redisClient, "blob");
}
}
示例14: 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));
}
}
}
示例15: Main
static void Main(string[] args)
{
Trace.TraceInformation("MEETUP_NOTIFICATION_URL: {0}", _meetupNewsUrl);
Trace.TraceInformation("SLACK_WEBHOOK_URL: {0}", _slackWebhookUrl);
Trace.TraceInformation("REDISTOGO_URL: {0}", _redisUrl);
while(true)
{
using(var redis = new RedisClient(_redisUrl))
{
var lastNotificationID = redis.Get<long>(_lastNotificationIDKey);
var news = GetMeetupNotifications();
var freshNews = news.Where(n => n.id > lastNotificationID);
if(freshNews.Any())
{
var relevantNews = freshNews.Where(n => n.target.group_id == _meetupGroupId)
.OrderBy(n => n.id);
foreach(var item in relevantNews) {
PostNotificationToSlack(item);
}
redis.Set(_lastNotificationIDKey, news.Max(n => n.id));
}
}
Thread.Sleep(60000);
}
}