本文整理汇总了C#中ServiceStack.Redis.RedisClient.Set方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Set方法的具体用法?C# RedisClient.Set怎么用?C# RedisClient.Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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);
}
示例3: 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);
}
}
示例4: Init1
protected void Init1()
{
RedisClient redisClient = new RedisClient("127.0.0.1", 6379);
var key_ = redisClient.Get<string>("key_");
redisClient.Set("go", "狗");
var user = new User
{
UserName = "张三",
Password = "1234567",
Email = "[email protected]"
};
redisClient.Set<User>("UserModel", user);
//redisClient
redisClient.Custom("SET", "goto", 1);
var c = redisClient.Custom(Commands.Get, "goto");
}
示例5: 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
}
}
示例6: 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");
}
}
示例7: 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));
}
示例8: AddToAccount
public void AddToAccount(string accountName, double secure = 0, double insecure = 0, double nonstandard = 0)
{
using (RedisClient redis = new RedisClient(redisCloudUrl.Value))
{
var currentValue = redis.Get<UserBalance>(accountName) ?? new UserBalance();
currentValue.Secure += secure;
currentValue.Insecure += insecure;
currentValue.Nonstandard += nonstandard;
redis.Set<UserBalance>(accountName, currentValue);
}
}
示例9: Main
static void Main(string[] args)
{
using (var redisClient = new RedisClient("localhost"))
{
redisClient.Set("release-test", "works");
var result = redisClient.Get<string>("release-test");
Console.WriteLine("Result: " + result);
}
Console.ReadKey();
}
示例10: Search_Test
public void Search_Test()
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
const string cacheKey = "urn+metadata:All:SearchProProfiles?SwanShinichi Osawa /0/8,0,0,0";
const long value = 1L;
client.Set(cacheKey, value);
var result = client.Get<long>(cacheKey);
Assert.That(result, Is.EqualTo(value));
}
}
示例11: Main
static void Main(string[] args)
{
Console.WriteLine("初始化队列");
var client = new RedisClient("192.168.31.202");
client.Set<string>("user", "登录用户名");
var pwd= client.Get<string>("user");
Console.WriteLine(pwd);
//StartConstumer();
//StartProducer();
Console.ReadLine();
}
示例12: CacheDemo
public void CacheDemo()
{
const int CachedValue = 42;
ICacheClient redisClient = new RedisClient(RedisHost);
// store some value in cache for one hour
redisClient.Set("cache_key", CachedValue, TimeSpan.FromSeconds(3600));
// get typed value from cache
int valueFromCache = redisClient.Get<int>("cache_key");
Assert.That(valueFromCache, Is.EqualTo(CachedValue));
}
示例13: GetRevistaByTitle
public async Task<Revista> GetRevistaByTitle(string name)
{
if (_repository == null)
{
var compartimossService = new CompartiService();
_repository = await compartimossService.SearchNumbers();
using (var redisClient = new RedisClient("dockerdotnetencamina.westus.cloudapp.azure.com", 6379))
{
redisClient.Set<IEnumerable<Revista>>("revista", _repository);
//redisClient.StoreAll(_repository);
}
}
return _repository.Where(x => x.Numero.Equals(name)).FirstOrDefault();
}
示例14: GetRevistas
public async Task<IEnumerable<Revista>> GetRevistas()
{
if (_repository==null)
{
var compartimossService = new CompartiService();
_repository = await compartimossService.SearchNumbers();
using (var redisClient = new RedisClient("dockerdotnetencamina.westus.cloudapp.azure.com", 6379))
{
// redisClient.StoreAll(_repository);
redisClient.Set<IEnumerable<Revista>>("revista", _repository);
}
}
return _repository;
}
示例15: Test
public static void Test()
{
//连接
RedisClient redisClient = new RedisClient("127.0.0.1", 6379); //redis服务IP和端口
//赋值
redisClient.Set("myKey","heheda");
//取值
string value = redisClient.Get<string>("myKey");
Console.WriteLine(value);
Console.ReadKey();
}