本文整理汇总了C#中ServiceStack.Redis.RedisClient类的典型用法代码示例。如果您正苦于以下问题:C# RedisClient类的具体用法?C# RedisClient怎么用?C# RedisClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisClient类属于ServiceStack.Redis命名空间,在下文中一共展示了RedisClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:Robooto,项目名称:ProteinTracker,代码行数:30,代码来源:TrackerController.cs
示例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;
}
开发者ID:JustinBeckwith,项目名称:AppHarborDemo,代码行数:11,代码来源:Globals.cs
示例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);
}
}
开发者ID:vvs9983,项目名称:MySeriesService,代码行数:25,代码来源:SeriesCache.cs
示例4: RedisSubscription
public RedisSubscription(RedisClient redisClient)
{
this.redisClient = redisClient;
this.SubscriptionCount = 0;
this.activeChannels = new List<string>();
}
开发者ID:EvgeniyProtas,项目名称:servicestack,代码行数:7,代码来源:RedisSubscription.cs
示例5: NotifySubscribers
private void NotifySubscribers(string queueName)
{
using (var client = new RedisClient("localhost"))
{
client.PublishMessage(queueName, NewItem);
}
}
开发者ID:joaofx,项目名称:nedis,代码行数:7,代码来源:NedisQueue.cs
示例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();
}
开发者ID:joaofx,项目名称:nedis,代码行数:27,代码来源:NedisQueue.cs
示例7: Dequeue
public int Dequeue(string queueName)
{
using (var client = new RedisClient("localhost"))
{
return Convert.ToInt32(client.Lists[queueName].Pop());
}
}
开发者ID:joaofx,项目名称:nedis,代码行数:7,代码来源:NedisQueue.cs
示例8: Clear
public void Clear(string queueName)
{
using (var client = new RedisClient("localhost"))
{
client.Lists[queueName].Clear();
}
}
开发者ID:joaofx,项目名称:nedis,代码行数:7,代码来源:NedisQueue.cs
示例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));
}
}
}
开发者ID:nhatkycon,项目名称:xetui,代码行数:25,代码来源:Redis.aspx.cs
示例10: CreateClient
private IRedisClient CreateClient()
{
var hosts = _host.Split(':');
var client = new RedisClient(hosts[0], Int32.Parse(hosts[1]));
client.Password = _password;
return client;
}
开发者ID:michal-franc,项目名称:SilverlightBoids,代码行数:7,代码来源:RedisClientManagerPassword.cs
示例11: Teacher
public ViewResult Teacher()
{
using (var redis = new RedisClient(new Uri(connectionString))) {
var teacher = redis.As<Teacher>().GetAll().FirstOrDefault();
return View(teacher);
}
}
开发者ID:gbabiars,项目名称:Homework,代码行数:7,代码来源:HomeController.cs
示例12: GetBalance
public UserBalance GetBalance(string accountName)
{
using (RedisClient redis = new RedisClient(redisCloudUrl.Value))
{
return redis.Get<UserBalance>(accountName) ?? new UserBalance();
}
}
开发者ID:jmaxxz,项目名称:csrfmvc,代码行数:7,代码来源:Vault.cs
示例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");
}
}
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:29,代码来源:RedisDictionary.cs
示例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));
}
}
}
开发者ID:chavp,项目名称:RedisLab,代码行数:27,代码来源:Program.cs
示例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);
}
}
开发者ID:jasonholloway,项目名称:meetup2slack,代码行数:32,代码来源:Program.cs
示例16: 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});
}
开发者ID:Robooto,项目名称:ProteinTracker,代码行数:30,代码来源:UsersController.cs
示例17: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
redisHost = ConfigurationManager.AppSettings["redisHost"];
redisPort = int.Parse(ConfigurationManager.AppSettings["redisPort"]);
redisPassword = ConfigurationManager.AppSettings["redisPassword"];
if (!IsPostBack)
{
RedisClient redisClient = new RedisClient(redisHost, redisPort) { Password = redisPassword };
using (var redisGuids = redisClient.GetTypedClient<Guids>())
{
redisGuids.Store(new Guids { Date = DateTime.Now, Value = Guid.NewGuid() });
var allValues = redisGuids.GetAll();
GridView1.DataSource = allValues;
GridView1.DataBind();
}
}
}
catch (Exception ex)
{
throw new WebException(ex.ToString(), WebExceptionStatus.ConnectFailure);
}
}
开发者ID:UhuruSoftware,项目名称:vcap-dotnet,代码行数:25,代码来源:default.aspx.cs
示例18: checkverification
//Verification是前端传进来的验证码
public int checkverification(string mobile, string smsType, string verification)
{
try
{
var Client = new RedisClient("127.0.0.1", 6379);
var verify = Client.Get<string>(mobile + smsType);
if (verify != null)
{
if (verify == verification)
{
return 1;//验证码正确
}
else
{
return 2;//验证码错误
}
}
else
{
return 0;//没有验证码或验证码已过期
}
}
catch (Exception ex)
{
HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "匹配验证码功能错误", "WebService调用异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
return 3;
throw (ex);
}
}
开发者ID:wfguanhan,项目名称:CDMISrestful,代码行数:30,代码来源:ServiceRepository.cs
示例19: ChangeTranslation
private static void ChangeTranslation(RedisClient client)
{
Console.WriteLine("Enter word.");
string word = Console.ReadLine();
byte[] wordInBytes = Extensions.ToAsciiCharArray(word);
Console.WriteLine("Enter translation.");
string translation = Console.ReadLine();
byte[] translationInBytes = Extensions.ToAsciiCharArray(translation);
if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
{
if (client.HExists(dictionary, wordInBytes) == 1)
{
client.HSet(dictionary, wordInBytes, translationInBytes);
Console.WriteLine("Translation of the word {0} is changed.", word);
}
else
{
Console.WriteLine("There is no word {0}.", word);
}
}
else
{
Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
}
}
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:25,代码来源:RedisDictionary.cs
示例20: Main
static void Main()
{
RedisClient client = new RedisClient("127.0.0.1:6379");
using (client)
{
Console.WriteLine("Enter command - Add, Change, Find or Exit");
string command = Console.ReadLine();
while (command != exit)
{
if (command == add)
{
AddToDictionary(client);
}
else if (command == change)
{
ChangeTranslation(client);
}
else if (command == find)
{
ShowTranslation(client);
}
else if (command != exit)
{
Console.WriteLine("Enter invalid command. Please try again.");
}
Console.WriteLine("Enter command - Add, Change, Find or Exit");
command = Console.ReadLine();
}
}
}
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:31,代码来源:RedisDictionary.cs
注:本文中的ServiceStack.Redis.RedisClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论