本文整理汇总了C#中IDatabase.StringSet方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.StringSet方法的具体用法?C# IDatabase.StringSet怎么用?C# IDatabase.StringSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.StringSet方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedisConnectionAndUpload
public static Dictionary<string,string> RedisConnectionAndUpload(string connectionString)
{
var dict = new Dictionary<string, string>()
ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect(configuration: connectionString);
conn = muxer.GetDatabase();
muxer.Wait(conn.PingAsync());
List<City> citys = CityDataSource.CityDataSource.GetCitys();
if (conn.StringGet(key: "IsValue").IsNull)
{
var oneByone = new Stopwatch();
oneByone.Start();
int i = 0;
citys.ToList().ForEach(c =>
{
i++;
conn.HashSetAsync("Citys:Data:" + c.Id.ToString(), c.ToHashEntries());
List<string> prefix = GetPrefix(c.Name);
prefix.Concat(GetPrefix(c.Code));
if (!string.IsNullOrEmpty(c.Name))
conn.SortedSetAdd(key: "CityName", member: c.Name, score: 0);
if (!string.IsNullOrEmpty(c.Code))
conn.SortedSetAdd(key: "CityCode", member: c.Code, score: 0);
foreach (var p in prefix)
{
conn.SortedSetAdd("Citys:index:" + p, c.Id, 0);
}
});
oneByone.Stop();
dict.Add(key: "OneByOne Elapsed Milliseconds: ", value: oneByone.ElapsedMilliseconds.ToString());
dict.Add(key: "OneByOne Elapsed Seconds: ", value: (oneByone.ElapsedMilliseconds/1000).ToString());
var whole = new Stopwatch();
whole.Start();
conn.StringSet(key: "cityslist", value: Serialize(citys));
whole.Stop();
dict.Add(key: "Whole Elapsed Milliseconds: ", value: whole.ElapsedMilliseconds.ToString());
dict.Add(key: "whole Elapsed Seconds: ", value: (whole.ElapsedMilliseconds / 1000).ToString());
conn.StringSet(key: "IsValue", value: true);
}
return dict;
}
示例2: RedisConnectionAndUpload
public static void RedisConnectionAndUpload(string connectionString)
{
var muxer = ConnectionMultiplexer.Connect(configuration: connectionString);
conn = muxer.GetDatabase();
muxer.Wait(conn.PingAsync());
List<City> citys = CityDataSource.CityDataSource.GetCitys();
if (conn.StringGet("IsValue").IsNull)
{
int i = 0;
citys.Take(1000).ToList().ForEach(c =>
{
i++;
conn.HashSetAsync("Citys:Data:" + c.Id.ToString(), c.ToHashEntries());
List<string> prefix = GetPrefix(c.Name);
prefix.Concat(GetPrefix(c.Code));
if (!string.IsNullOrEmpty(c.Name))
conn.SortedSetAdd(key: "CityName", member: c.Name, score: 0);
if (!string.IsNullOrEmpty(c.Code))
conn.SortedSetAdd(key: "CityCode", member: c.Code, score: 0);
foreach (var p in prefix)
{
conn.SortedSetAdd("Citys:index:" + p, c.Id, 0);
}
});
conn.StringSet(key: "IsValue", value: true);
}
}
示例3: RedisSetData
/// <summary>
/// Enters the information about the user in Redis.
/// </summary>
/// <param name="db">Connecting with Redis.</param>
/// <param name="user">Instance information about the user.</param>
/// <param name="logging">Logging class object to create the log.</param>
private static void RedisSetData(IDatabase db, IReadOnlyList<User> user, Logging logging)
{
// Serialization of User class using Json.
var jsonValue = JsonConvert.SerializeObject(user);
try
{
db.StringSet($"user:{user[0].Id}", jsonValue);
// Life Time 10 minutes.
db.KeyExpire($"user:{user[0].Id}", new TimeSpan(0, 10, 0));
}
catch (RedisException ex)
{
logging.ProcessingException(ex);
}
}
示例4: Create
public static RedisSessionStateStore Create(IDatabase database, string id, int timeout)
{
var timeoutSpan = TimeSpan.FromMinutes(timeout);
database.StringSet(id, JsonConvert.SerializeObject(new { Timeout = timeout }), timeoutSpan);
var hashKey = GetHashKey(id);
var entrys = database.HashGetAll(hashKey);
foreach (var entry in entrys)
database.HashDelete(hashKey, entry.Name);
return new RedisSessionStateStore(database, id, TimeSpan.FromMinutes(timeout), hashKey);
}
示例5: ensureRedis
private void ensureRedis(IDatabase db)
{
db.StringSet("testkey", "testvalue");
byte[] value = db.StringGet("testkey");
Console.WriteLine("got from redis: %s", value);
}
示例6: startButton_Click
private void startButton_Click(object sender, EventArgs e)
{
_destVideoFilePath = string.Empty;
_log.Error("destVideo_Click");
if (!chkUseCamera.Checked)
{
OpenFileDialog fileDialog = new OpenFileDialog
{
Multiselect = false,
Title = "请选择文件",
Filter = "所有文件(*.*)|*.*"
};
if (fileDialog.ShowDialog() == DialogResult.OK)
{
_destVideoFilePath = fileDialog.FileName;
}
else
{
return;
}
}
_capCalcOrig = new CaptureCalc();
_capCalcDest = new CaptureCalc();
_capDataOrig = new CaptureData();
_capDataDest = new CaptureData();
_redis = ConnectionMultiplexer.Connect(_redisHost);
if (_redis == null)
return;
_db = _redis.GetDatabase();
if (_db == null)
return;
_db.StringSet(Constants.REDIS_KEY_CAPTURED_DATA, "");
_db.StringSet(Constants.REDIS_KEY_OIRG_DATA, "");
//RedisValue rv= _db.StringGet("CapturedData");
//try to create the capture
if (_capCalcDest.CaptureC == null)
{
try
{
_capCalcDest.CaptureC = !string.IsNullOrEmpty(_destVideoFilePath) ? new Capture(_destVideoFilePath) : new Capture();
}
catch (NullReferenceException ex)
{
//show errors if there is any
MessageBox.Show(ex.Message);
}
}
if (_capCalcOrig.CaptureC == null)
{
try
{
if (!string.IsNullOrEmpty(_origVideoFilePath))
_capCalcOrig.CaptureC = new Capture(_origVideoFilePath);
}
catch (NullReferenceException ex)
{
MessageBox.Show(ex.Message);
}
}
if (_capCalcDest.CaptureC != null) //if camera capture has been successfully created
{
_capCalcDest.ForegroundDetectorC = new BackgroundSubtractorMOG2();
_capCalcDest.MotionHistoryC = new MotionHistory(
1.0, //in second, the duration of motion history you wants to keep
0.05, //in second, maxDelta for cvCalcMotionGradient
0.5); //in second, minDelta for cvCalcMotionGradient
_capCalcDest.CaptureC.ImageGrabbed += ProcessCapturedFrame;
_capCalcDest.CaptureC.Start();
}
if (_capCalcOrig.CaptureC != null) //if camera capture has been successfully created
{
_capCalcOrig.ForegroundDetectorC = new BackgroundSubtractorMOG2();
_capCalcOrig.MotionHistoryC = new MotionHistory(
1.0, //in second, the duration of motion history you wants to keep
0.05, //in second, maxDelta for cvCalcMotionGradient
0.5); //in second, minDelta for cvCalcMotionGradient
_capCalcOrig.CaptureC.ImageGrabbed += ProcessComparedVideoFrame;
_capCalcOrig.CaptureC.Start();
}
}
示例7: GradeButton_Click
private void GradeButton_Click(object sender, EventArgs e)
{
_redis = ConnectionMultiplexer.Connect(_redisHost);
if (_redis == null)
return;
_db = _redis.GetDatabase();
if (_db == null)
return;
RedisValue capturedRv= _db.StringGet(Constants.REDIS_KEY_CAPTURED_DATA);
RedisValue origRv = _db.StringGet(Constants.REDIS_KEY_OIRG_DATA);
string[] capturedDataArr = capturedRv.ToString()
.Split(Constants.REDIS_SEPERATE_SYMBOL.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] origDataArr = origRv.ToString()
.Split(Constants.REDIS_SEPERATE_SYMBOL.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
/*
using (FileStream fs = new FileStream("d:\\temp\\Orig.data", FileMode.OpenOrCreate))
{
byte[] data = new UTF8Encoding().GetBytes(origRv);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
using (FileStream fs = new FileStream("d:\\temp\\Capt.data", FileMode.OpenOrCreate))
{
byte[] data = new UTF8Encoding().GetBytes(capturedRv);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
*/
var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
MotionData[] capturedData = new MotionData[capturedDataArr.Length];
int capturedCounter = 0;
foreach (var str in capturedDataArr)
{
capturedData[capturedCounter] = JsonConvert.DeserializeObject<MotionData>(str, settings);
capturedCounter++;
}
MotionData[] origData = new MotionData[origDataArr.Length];
int origCounter = 0;
foreach (var str in origDataArr)
{
origData[origCounter] = JsonConvert.DeserializeObject<MotionData>(str, settings);
origCounter++;
}
double score = Constants.MAX_SCORE - ProcessVideo.CalculateScore(capturedData, origData);
ScoreLabel.Text = "得分: " + score.ToString();
//Clear db
_db.StringSet(Constants.REDIS_KEY_CAPTURED_DATA, "");
_db.StringSet(Constants.REDIS_KEY_OIRG_DATA, "");
}
示例8: _SetAndGetStringCacheValue
private static void _SetAndGetStringCacheValue(IDatabase database)
{
database.StringSet(StringCacheKey, StringCacheValue);
var retrievedValue = database.StringGet(StringCacheKey);
Console.WriteLine($"Expected value = {StringCacheValue}, Retrieved value = {retrievedValue}");
}
示例9: RedisSetData
// Methods used in filling information of a modal window.
/// <summary>
/// Enters the information about the user in Redis.
/// </summary>
/// <param name="db">Connecting with Redis.</param>
/// <param name="user">Instance information about the user.</param>
private static void RedisSetData(IDatabase db, IReadOnlyList<User> user)
{
// Serialization of User class using Json.
var jsonValue = JsonConvert.SerializeObject(user);
try
{
db.StringSet($"user:{user[0].Id}", jsonValue);
// Life Time 10 minutes.
db.KeyExpire($"user:{user[0].Id}", new TimeSpan(0, 10, 0));
}
catch (RedisException ex)
{
var swRedisExceptionLog = new StreamWriter("RedisExceptionLog.txt", true);
swRedisExceptionLog.WriteLine("#########################################################################################");
swRedisExceptionLog.WriteLine($"RedisException DateTime: {DateTime.Now}\n");
swRedisExceptionLog.WriteLine($"RedisException Data: {ex.Data}\n");
swRedisExceptionLog.WriteLine($"RedisException HelpLink: {ex.HelpLink}\n");
swRedisExceptionLog.WriteLine($"RedisException HResult: {ex.HResult}\n");
swRedisExceptionLog.WriteLine($"RedisException InnerException: {ex.InnerException}\n");
swRedisExceptionLog.WriteLine($"RedisException Message: {ex.Message}\n");
swRedisExceptionLog.WriteLine($"RedisException Source: {ex.Source}\n");
swRedisExceptionLog.WriteLine($"RedisException StackTrace: {ex.StackTrace}\n");
swRedisExceptionLog.WriteLine($"RedisException TargetSite: {ex.TargetSite}\n");
swRedisExceptionLog.Close();
}
}