本文整理汇总了C#中ServiceStack.Redis.RedisClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Get方法的具体用法?C# RedisClient.Get怎么用?C# RedisClient.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedisLock
public RedisLock(RedisClient redisClient, string key, TimeSpan? timeOut)
{
this.redisClient = redisClient;
this.key = key;
ExecExtensions.RetryUntilTrue(
() =>
{
//This pattern is taken from the redis command for SETNX http://redis.io/commands/setnx
//Calculate a unix time for when the lock should expire
TimeSpan realSpan = timeOut ?? new TimeSpan(365, 0, 0, 0); //if nothing is passed in the timeout hold for a year
DateTime expireTime = DateTime.UtcNow.Add(realSpan);
string lockString = (expireTime.ToUnixTimeMs() + 1).ToString();
//Try to set the lock, if it does not exist this will succeed and the lock is obtained
var nx = redisClient.SetValueIfNotExists(key, lockString);
if (nx)
return true;
//If we've gotten here then a key for the lock is present. This could be because the lock is
//correctly acquired or it could be because a client that had acquired the lock crashed (or didn't release it properly).
//Therefore we need to get the value of the lock to see when it should expire
redisClient.Watch(key);
string lockExpireString = redisClient.Get<string>(key);
long lockExpireTime;
if (!long.TryParse(lockExpireString, out lockExpireTime))
{
redisClient.UnWatch(); // since the client is scoped externally
return false;
}
//If the expire time is greater than the current time then we can't let the lock go yet
if (lockExpireTime > DateTime.UtcNow.ToUnixTimeMs())
{
redisClient.UnWatch(); // since the client is scoped externally
return false;
}
//If the expire time is less than the current time then it wasn't released properly and we can attempt to
//acquire the lock. The above call to Watch(_lockKey) enrolled the key in monitoring, so if it changes
//before we call Commit() below, the Commit will fail and return false, which means that another thread
//was able to acquire the lock before we finished processing.
using (var trans = redisClient.CreateTransaction()) // we started the "Watch" above; this tx will succeed if the value has not moved
{
trans.QueueCommand(r => r.Set(key, lockString));
return trans.Commit(); //returns false if Transaction failed
}
},
timeOut
);
}
示例2: Main
static void Main(string[] args)
{
string host = "localhost";
string elementKey = "testKeyRedis";
using (RedisClient redisClient = new RedisClient(host))
{
if (redisClient.Get<string>(elementKey) == null)
{
// adding delay to see the difference
Thread.Sleep(2000);
// save value in cache
redisClient.Set(elementKey, "default value");
}
//change the value
redisClient.Set(elementKey, "fuck you value");
// get value from the cache by key
string message = "Item value is: " + redisClient.Get<string>(elementKey);
Console.WriteLine(message);
Console.ReadLine();
}
}
示例3: 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();
}
示例4: TestRedis
public void TestRedis()
{
var redisClient = new RedisClient("10.1.200.83", 6379);
Console.WriteLine(redisClient.Get<string>("tongcheng"));
Console.WriteLine("Test");
Assert.Equals(redisClient.Get<string>("city"), "suzhou");
}
示例5: ProcessRequest
public void ProcessRequest(HttpContext context)
{
var land = (context.Request["land"] ?? "").ToLower() == "true";
var image = context.Request["image"] ?? "";
var width = context.Request["width"] ?? "0";
var height = context.Request["height"] ?? "0";
var redis = new RedisClient(ConfigurationManager.AppSettings["ServerRedisMaster"] ?? "", int.Parse(ConfigurationManager.AppSettings["PortRedisMaster"] ?? "0"));
var key = string.Format("storage:imagehandler:{0}", image);
var done = (redis.ContainsKey(key) && !string.IsNullOrEmpty(redis.Get<string>(key) ?? ""));
var noimage = ConfigurationManager.AppSettings["StorageNoImage"] ?? "Common/CEO/noimage.jpg";
//var file = ConfigurationManager.AppSettings["StorageNoImage"] ?? "Common/CEO/noimage.jpg";
var imgPath = ConfigurationManager.AppSettings["imgPath"] ?? "http://images1.cafef.vn/";
var storageServer = ConfigurationManager.AppSettings["StorageServer"] ?? "http://testcafef.vcmedia.vn/";
string imageSrc = storageServer + noimage;
if (!done)
{
if (!string.IsNullOrEmpty(image))
{
imgPath += (land ? "batdongsan/" : "");
if (image.StartsWith(imgPath) && StorageUtils.Utils.checkImageExtension(image))
{
if (StorageUtils.Utils.UploadSiteImage(image, imgPath, (land ? "Common/BDS/" : "")) == "Storage : OK")
{
//file = image.Replace(imgPath, "");
}
}
}
int iw, ih;
if (!int.TryParse(width, out iw)) iw = 0;
if (!int.TryParse(height, out ih)) ih = 0;
imageSrc = image.Contains(imgPath) ? image : (imgPath + image); //GetStorageImage(file, iw, ih, land);
if (!CheckFileExist(imageSrc))
{
imageSrc = storageServer + noimage;
}
if (redis.ContainsKey(key))
redis.Set(key, imageSrc, new TimeSpan(0, 5, 0));
else
redis.Add(key, imageSrc, new TimeSpan(0, 5, 0));
}
else
{
imageSrc = redis.Get<string>(key) ?? (storageServer + noimage);
}
context.Response.ContentType = StorageUtils.Utils.MimeType(imageSrc);
context.Response.Redirect(imageSrc);
//context.Response.BinaryWrite(StorageUtils.Utils.GetFileBinary("", imageSrc));
}
示例6: Main
static void Main(string[] args)
{
using (RedisClient redisClient = new RedisClient("127.0.0.1",6379))
{
if (redisClient.Get<string>("test") == null)
{
Thread.Sleep(1000);
redisClient.Set("test", "hello world");
}
//redisClient.Set("test", "fuck you value");
string message = "Item value is: " + redisClient.Get<string>("test");
Console.WriteLine(message);
}
Console.Read();
}
示例7: GetBalance
public UserBalance GetBalance(string accountName)
{
using (RedisClient redis = new RedisClient(redisCloudUrl.Value))
{
return redis.Get<UserBalance>(accountName) ?? new UserBalance();
}
}
示例8: Main
static void Main(string[] args)
{
var host = args.Length > 0 ? args[0] : "localhost";
var port = args.Length > 1 ? int.Parse(args[1]) : 6379;
var redisClient = new RedisClient(host, port);
var before = DateTime.Now;
for (var i = 0; i < Iterations; i++)
{
var key = KeyMaster + i;
redisClient.Set(key, ValueMaster);
//if (i % LogEveryTimes == 0)
// Console.WriteLine("Time taken at {0}: {1}ms", i, (DateTime.Now - before).TotalMilliseconds);
}
for (int i = 0; i < Iterations; i++)
{
var key = KeyMaster + i;
redisClient.Get<string>(key);
//if (i % LogEveryTimes == 0)
// Console.WriteLine("Time taken at {0}: {1}ms", i, (DateTime.Now - before).TotalMilliseconds);
}
Console.WriteLine("Total Time Taken: {0}ms", (DateTime.Now - before).TotalMilliseconds);
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: RevistaService
public RevistaService()
{
using (var redisClient = new RedisClient("dockerdotnetencamina.westus.cloudapp.azure.com", 6379))
{
_repository = redisClient.Get<IEnumerable<Revista>>("revista");
//_repository = redisClient.GetAll<Revista>();
}
}
示例12: TestString
private static void TestString()
{
using (var client = new RedisClient("127.0.0.1", 6379))
{
#region "字符串类型"
client.Set<string>("HQF.Tutorial.Redis:name", "Reis");
string userName = client.Get<string>("HQF.Tutorial.Redis:name");
Console.WriteLine(userName);
//访问次数
client.Set<int>("HQF.Tutorial.Redis:IpAccessCount", 0);
//次数递增
client.Incr("HQF.Tutorial.Redis:IpAccessCount");
Console.WriteLine(client.Get<int>("HQF.Tutorial.Redis:IpAccessCount"));
#endregion
}
}
示例13: Main
static void Main(string[] args)
{
RedisClient client = new RedisClient("127.0.0.1", 6379);
var result = client.Set<string>("name", "youtao");
if (result)
{
var value = client.Get<string>("name");
}
}
示例14: SaveResults
private static void SaveResults(ServiceResultsDto serviceResults)
{
using (var client = new RedisClient())
{
client.Increment("SERVICE_RESULTS_ID", 1);
serviceResults.Id = client.Get<int>("SERVICE_RESULTS_ID");
var clientService = client.As<ServiceResultsDto>();
clientService.Lists["SERVICE_RESULTS"].Add(serviceResults);
}
}
示例15: DoTest
public static void DoTest()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
RedisClient Client = new RedisClient("192.168.56.2", 6379);
stopWatch.Stop();
Console.WriteLine("RedisClient Construct 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);
Boolean connected = Client.IsSocketConnected();
stopWatch.Restart();
string str = Client.Get<string>("city");
stopWatch.Stop();
Console.WriteLine("RedisClient Get 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);
stopWatch.Restart();
Client.Set<String>("city", "China");
stopWatch.Stop();
Console.WriteLine("RedisClient Set 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);
stopWatch.Restart();
str = Client.Get<string>("city");
stopWatch.Stop();
Console.WriteLine("RedisClient Get 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);
stopWatch.Restart();
Boolean req = Client.Add<String>("country", "China", new TimeSpan(0, 0, 1, 0));
stopWatch.Stop();
Console.WriteLine("RedisClient Add 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);
List<String> keys = Client.SearchKeys("MBSOA:*");
Console.WriteLine("之前通过客户端进行设置的city键值对:{0}", str);
Console.ReadLine();
}