当前位置: 首页>>代码示例>>C#>>正文


C# IDatabase.StringGet方法代码示例

本文整理汇总了C#中IDatabase.StringGet方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.StringGet方法的具体用法?C# IDatabase.StringGet怎么用?C# IDatabase.StringGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase.StringGet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
            }
        }
开发者ID:Krishjs,项目名称:UI.GridHelper,代码行数:35,代码来源:RedisHelper.cs

示例2: 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;

        }
开发者ID:Krishjs,项目名称:Redis.ko.suggest,代码行数:51,代码来源:RedisHelper.cs

示例3: TestConcurrent

 private static void TestConcurrent(IDatabase db, RedisKey key, int SyncLoop, int Threads)
 {
     long value;
     db.KeyDelete(key, CommandFlags.FireAndForget);
     var time = RunConcurrent(delegate
     {
         for (int i = 0; i < SyncLoop; i++)
         {
             db.StringIncrement(key);
         }
     }, Threads, timeout: 45000);
     value = (long)db.StringGet(key);
     Assert.AreEqual(SyncLoop * Threads, value);
     Console.WriteLine("Sync: {0} INCR using {1} threads, {2:###,##0}ms, {3} ops/s; final value: {4}",
         SyncLoop * Threads, Threads,
         (long)time.TotalMilliseconds,
         (long)((SyncLoop * Threads) / time.TotalSeconds),
         value);
 }
开发者ID:ninjaferret,项目名称:StackExchange.Redis,代码行数:19,代码来源:SSL.cs

示例4: SyncGeneration

        private void SyncGeneration(IDatabase db)
        {
            var generationKey = CacheNamespace.GetGenerationKey();
            var serverGenerationValue = db.StringGet(generationKey);
            var serverGeneration = Convert.ToInt64(serverGenerationValue);
            var currentGeneration = CacheNamespace.GetGeneration();

            // Generation was cleared by someone else (shouldn't happen).
            if (serverGenerationValue.IsNullOrEmpty)
            {
                db.StringSetAsync(
                    key: generationKey,
                    value: currentGeneration,
                    // Only set if someone else doesn't jump in and set it first.
                    when: When.NotExists,
                    flags: CommandFlags.FireAndForget
                );

                log.InfoFormat("setting server generation ({0}) because it is empty", currentGeneration);
            }
            // Generation was lowered by someone else (shouldn't happen).
            else if (serverGeneration < CacheNamespace.GetGeneration())
            {
                var transaction = db.CreateTransaction();

                // Only set if someone else doesn't jump in and set it first.
                transaction.AddCondition(Condition.StringEqual(generationKey, serverGeneration));

                transaction.StringSetAsync(
                    key: generationKey,
                    value: CacheNamespace.GetGeneration(),
                    flags: CommandFlags.FireAndForget
                );

                // We don't need to worry about the result because we will
                // already retry if we can't sync the generation.
                transaction.ExecuteAsync(CommandFlags.FireAndForget);

                log.InfoFormat("syncing server generation (server={0}, current={1})", serverGeneration, currentGeneration); 
            }
            else
            {
                CacheNamespace.SetHigherGeneration(serverGeneration);

                log.InfoFormat("syncing server generation (server={0}, current={1})", serverGeneration, currentGeneration);
            }
        }
开发者ID:oskarn,项目名称:NHibernate.Caches.Redis,代码行数:47,代码来源:RedisCache.cs

示例5: Get

            public static RedisSessionStateStore Get(IDatabase database, string id)
            {
                var json = database.StringGet(id);

                int timeout;

                try
                {
                    var jobject = JObject.Parse(json);
                    timeout = jobject.Value<int>("Timeout");
                }
                catch (Exception)
                {
                    timeout = 20;
                }

                return new RedisSessionStateStore(database, id, TimeSpan.FromMinutes(timeout), GetHashKey(id));
            }
开发者ID:jango2015,项目名称:Distributed,代码行数:18,代码来源:RedisSessionStateStoreProvider.cs

示例6: LoopTask

        private void LoopTask(IDatabase db)
        {
            int idx = 1;
            while (true)
            {
                string loopMsg = string.Format("GET#{0} for key '{1}'...", idx, testKey);
                WriteConnectionMsg(loopMsg);

                bool callSuccess = false;
                try
                {
                    fileStreamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss.ffff") + " " + loopMsg + "...");

                    RedisValue redisValue = db.StringGet(testKey);
                    callSuccess = !redisValue.IsNullOrEmpty && redisValue == testValue;
                }
                catch (Exception e)
                {
                    fileStreamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss.ffff") + " " + loopMsg + " failed on error: " + e.Message);
                }

                WriteConnectionMsg(loopMsg + " " + GetResultString(callSuccess));

                if (stopEvent.WaitOne(1))
                {
                    WriteConnectionMsg(string.Format("LoopTask was cancelled on {0} loop (before delay).", idx));
                    break;
                }

                Thread.Sleep(1000);

                if (stopEvent.WaitOne(1))
                {
                    WriteConnectionMsg(string.Format("LoopTask was cancelled on {0} loop (after delay).", idx));
                    break;
                }

                idx++;
            }
        }
开发者ID:psulek,项目名称:psulekpub,代码行数:40,代码来源:SentinelTests.cs

示例7: ensureRedis

 private void ensureRedis(IDatabase db)
 {
     db.StringSet("testkey", "testvalue");
     byte[] value = db.StringGet("testkey");
     Console.WriteLine("got from redis: %s", value);
 }
开发者ID:colemickens,项目名称:dotkube_____old,代码行数:6,代码来源:Startup.cs

示例8: 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, "");
        }
开发者ID:Lionel1204,项目名称:MyCode,代码行数:63,代码来源:MotionDetective.cs

示例9: _SetAndGetStringCacheValue

        private static void _SetAndGetStringCacheValue(IDatabase database)
        {
            database.StringSet(StringCacheKey, StringCacheValue);

            var retrievedValue = database.StringGet(StringCacheKey);
            Console.WriteLine($"Expected value = {StringCacheValue}, Retrieved value = {retrievedValue}");
        }
开发者ID:nchetan,项目名称:poc,代码行数:7,代码来源:Program.cs

示例10: _AppendToCacheValue

 private static void _AppendToCacheValue(IDatabase database)
 {
     const string appendString = " appended";
     database.StringAppend(StringCacheValue, appendString);
     var retrievedValue = database.StringGet(StringCacheKey);
     var expected = $"{StringCacheKey}{appendString}";
     Console.WriteLine($"AppendToCacheValue: Expected = {expected}, Actual = {retrievedValue}");
 }
开发者ID:nchetan,项目名称:poc,代码行数:8,代码来源:Program.cs


注:本文中的IDatabase.StringGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。