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


C# RedisValue类代码示例

本文整理汇总了C#中RedisValue的典型用法代码示例。如果您正苦于以下问题:C# RedisValue类的具体用法?C# RedisValue怎么用?C# RedisValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CheckNotSame

 private void CheckNotSame(RedisValue x, RedisValue y)
 {
     Assert.IsFalse(Equals(x, y));
     Assert.IsFalse(x.Equals(y));
     Assert.IsFalse(y.Equals(x));
     Assert.IsFalse(x.GetHashCode() == y.GetHashCode()); // well, very unlikely
 }
开发者ID:liweisx,项目名称:StackExchange.Redis,代码行数:7,代码来源:KeysAndValues.cs

示例2: KeyCommand

        protected KeyCommand(string key, params RedisValue[] values)
        {
            ValidateKey(key);
            var vals = new RedisValue[1 + values.Length];
            vals[0] = key;
            if (values.Length > 0)
                values.CopyTo(vals, 1);

            SetParameters(vals);
        }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:10,代码来源:KeyCommand.cs

示例3: CanHandleCommands

        public void CanHandleCommands()
        {
            RedisServiceFactory.Register<IRedisCommandHandler, TestCommandHandler>();
            TestCommandHandler cmdHandler = (TestCommandHandler)RedisServiceFactory.CommandHandlers.First();

            bool onExecutingDone = false;
            bool onExecutedDone = false;
            RedisKey[] testKeys = new RedisKey[] { "test" };
            RedisValue[] testValues = new RedisValue[] { "test value" };
            object testResult = (RedisValue)"hello world";

            cmdHandler.onExecuting = (command, involvedKeys, involvedValues) =>
            {
                Assert.AreEqual(RedisCommand.SET, command);
                Assert.AreEqual(1, testKeys.Intersect(involvedKeys).Count());
                Assert.AreEqual(1, testValues.Intersect(involvedValues).Count());
                onExecutingDone = true;
            };
            cmdHandler.onExecuted = (RedisCommand command, ref object result, RedisKey[] involvedKeys) =>
            {
                Assert.AreEqual(RedisCommand.HMSET, command);
                Assert.AreEqual(1, testKeys.Intersect(involvedKeys).Count());
                Assert.AreEqual(testResult, result);
                onExecutedDone = true;
            };

            RedisServiceFactory.CommandHandlers.ExecuteBeforeHandlers(RedisCommand.SET, new RedisKey[] { "test" }, new RedisValue[] { "test value" });
            RedisServiceFactory.CommandHandlers.ExecuteAfterHandlers(RedisCommand.HMSET, new RedisKey[] { "test" }, ref testResult);

            Assert.IsTrue(onExecutingDone);
            Assert.IsTrue(onExecutedDone);
        }
开发者ID:mfidemraizer,项目名称:StackExchange.Redis,代码行数:32,代码来源:RedisCommandHandlerTest.cs

示例4: RedisLock

        public RedisLock([NotNull]IDatabase redis, [NotNull]RedisKey key, [NotNull]RedisValue owner, [NotNull]TimeSpan timeOut)
        {
            _redis = redis;
            _key = key;
            _owner = owner;

            //The comparison below uses timeOut as a max timeSpan in waiting Lock
            int i = 0;
            DateTime lockExpirationTime = DateTime.UtcNow +timeOut;
            while (DateTime.UtcNow < lockExpirationTime)
            {
                if (_redis.LockTake(key, owner, timeOut))
                    return;
                //assumes that a second call made by the same owner means an extension request
                var lockOwner = _redis.LockQuery(key);
                
                if (lockOwner.Equals(owner))
                {
                    //extends the lock only for the remaining time
                    var ttl = redis.KeyTimeToLive(key) ?? TimeSpan.Zero;
                    var extensionTTL = lockExpirationTime - DateTime.UtcNow;
                    if (extensionTTL > ttl)
                        _redis.LockExtend(key, owner, extensionTTL - ttl);
                    isRoot = false;
                    return;
                }
                SleepBackOffMultiplier(i);
                i++;
            }
            throw new TimeoutException(string.Format("Lock on {0} with owner identifier {1} Exceeded timeout of {2}", key, owner.ToString(), timeOut));
        }
开发者ID:xyting,项目名称:Hangfire.Redis.StackExchange,代码行数:31,代码来源:RedisLock.cs

示例5: GetMessageUpdates

        private static void GetMessageUpdates(RedisChannel channel, RedisValue value)
        {
            var vals = value.ToString().Split('|');
            if (vals.Length != 3 || vals[0] == InstanceId) return;

            GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients.All.receiveMessage(vals[1], vals[2]);
        }
开发者ID:Abdullah2993,项目名称:Klepet,代码行数:7,代码来源:ChatHub.cs

示例6: Eval

        public object Eval(string script, string[] keyArgs, object[] valueArgs)
        {
            RedisKey[] redisKeyArgs = new RedisKey[keyArgs.Length];
            RedisValue[] redisValueArgs = new RedisValue[valueArgs.Length];

            int i = 0;
            foreach (string key in keyArgs)
            {
                redisKeyArgs[i] = key;
                i++;
            }

            i = 0;
            foreach (object val in valueArgs)
            {
                if (val.GetType() == typeof(byte[]))
                {
                    // User data is always in bytes
                    redisValueArgs[i] = (byte[])val;
                }
                else
                {
                    // Internal data like session timeout and indexes are stored as strings
                    redisValueArgs[i] = val.ToString();
                }
                i++;
            }
            return RetryLogic(() => _connection.ScriptEvaluate(script, redisKeyArgs, redisValueArgs));
        }
开发者ID:McMlok,项目名称:aspnet-redis-providers,代码行数:29,代码来源:StackExchangeClientConnection.cs

示例7: SetAsync

        public async Task<bool> SetAsync(string key, RedisValue value, int expirySeconds)
        {
            var conn = _connectionManager.GetConnection();
            await conn.GetDatabase(_db).StringSetAsync(key, value, _isRedisExpiryEnabled ? (TimeSpan?)TimeSpan.FromSeconds(expirySeconds) : null).ConfigureAwait(false);

            return true;
        }
开发者ID:CrescentFresh,项目名称:TagCache.Redis,代码行数:7,代码来源:RedisClient.cs

示例8: OnInstanceNotified

 private void OnInstanceNotified(RedisChannel channel,RedisValue notification)
 {
     try
     {
         var list = monitors[channel];
         var notify = BahamutAppInstanceNotification.FromJson(notification);
         switch (notify.NotifyType)
         {
             case BahamutAppInstanceNotification.TYPE_INSTANCE_HEART_BEAT:
                 foreach (var monitor in list) { monitor.OnInstanceHeartBeating(notify); }
                 break;
             case BahamutAppInstanceNotification.TYPE_INSTANCE_OFFLINE:
                 foreach (var monitor in list) { monitor.OnInstanceOffline(notify); }
                 break;
             case BahamutAppInstanceNotification.TYPE_REGIST_APP_INSTANCE:
                 foreach (var monitor in list) { monitor.OnInstanceRegisted(notify); }
                 break;
             default:
                 break;
         }
     }
     catch (Exception)
     {
     }
 }
开发者ID:Sharelink,项目名称:ServerControl,代码行数:25,代码来源:BahamutAppInstanceMonitor.cs

示例9: ConstructParameters

        public static RedisValue[] ConstructParameters(string name, string dstKey, IEnumerable<string> keys)
        {
            if (keys == null)
                throw new ArgumentNullException("keys");
            var count = keys.Count();
            if (count == 0)
                throw new ArgumentException("At least 1 source key must be specified.");

            bool hasDest = dstKey != null; 
            var parameters = new RedisValue[count + (hasDest ? 2 : 1)];
            int i = 1;
            parameters[0] = name;
            if (hasDest)
            {
                parameters[1] = dstKey;
                i++;
            }
            foreach (var key in keys)
            {
                if (key == null)
                    throw new ArgumentNullException("keys", "Null value found for key");
                parameters[i++] = key;
            }
            return parameters;
        }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:25,代码来源:CommandHelpers.cs

示例10: CheckSame

 private void CheckSame(RedisValue x, RedisValue y)
 {
     Assert.IsTrue(Equals(x, y));
     Assert.IsTrue(x.Equals(y));
     Assert.IsTrue(y.Equals(x));
     Assert.IsTrue(x.GetHashCode() == y.GetHashCode());
 }
开发者ID:liweisx,项目名称:StackExchange.Redis,代码行数:7,代码来源:KeysAndValues.cs

示例11: ListenForMessage

 public void ListenForMessage(RedisChannel channel, RedisValue value)
 {
     Assert.AreEqual(RedisKey, channel.ToString());
     Assert.IsFalse(!value.HasValue || value.IsNullOrEmpty);
     Assert.AreEqual("INFO test pub/sub message", value.ToString());
     ActionRun = true;
 }
开发者ID:roh85,项目名称:NLog.Redis,代码行数:7,代码来源:RedisTargetTests.cs

示例12: IsExpiredLockValue

 public static bool IsExpiredLockValue(RedisValue lockValue, DateTime currentTime)
 {
     if (lockValue.IsEmpty)
         return false;
     var timeNow = DateTimeExtensions.UnixTimeNow;
     return (timeNow >= lockValue);
 }
开发者ID:vebin,项目名称:Guanima.Redis,代码行数:7,代码来源:RedisClient.Locks.cs

示例13: SaveHash

        /// <summary>
        ///This method save one or more values to the Set 
        /// </summary>
        /// <param name="Key">One key</param>
        /// <param name="RedisObjectList">A list of objects to the Set</param>
        /// <returns></returns>
        public long SaveHash(string Key, List<RedisObject> RedisObjectList)
        {
            try
            {
                ConnectionMultiplexer Connection = ConnectionMultiplexer.Connect(this.ConnectionString);
                var DataBase = Connection.GetDatabase();

                RedisValue[] RedisValueArray = new RedisValue[RedisObjectList.Count()];

                int ValueIndex = 0;

                foreach (RedisObject RedisObjectFound in RedisObjectList)
                {
                    RedisValueArray[ValueIndex] = new RedisValue();
                    RedisValueArray[ValueIndex] = RedisObjectFound.Value;

                    ValueIndex++;
                }

                return DataBase.SetAdd(Key, RedisValueArray);
            }
            catch (Exception)
            {

                throw;
            }
        }
开发者ID:vemoreno,项目名称:AzureRedisCacheSets,代码行数:33,代码来源:RedisCache.cs

示例14: Delete

                /// <summary>
                /// Removes the specified fields from the hash stored at key. Non-existing fields are ignored. Non-existing keys
                /// are treated as empty hashes and this command returns 0.
                /// </summary>
                /// <param name="key">
                /// The key.
                /// </param>
                /// <param name="field">
                /// The field.
                /// </param>
                /// <remarks>
                /// http://redis.io/commands/hdel
                /// </remarks>
                /// <returns>
                /// The number of fields that were removed.
                /// </returns>
                public static bool Delete(RedisKey key, RedisValue field)
                {
                    bool result = SharedCache.Instance.GetWriteConnection(key)
                        .GetDatabase(SharedCache.Instance.Db)
                        .HashDelete(key, field);

                    return result;
                }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:24,代码来源:Hashes.cs

示例15: AppendAsync

                /// <summary>
                /// If key already exists and is a string, this command appends the value at the end of the string. If key does
                /// not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.
                /// </summary>
                /// <param name="key">
                /// The key.
                /// </param>
                /// <param name="value">
                /// The value.
                /// </param>
                /// <returns>
                /// the length of the string after the append operation.
                /// </returns>
                /// <remarks>
                /// http://redis.io/commands/append
                /// </remarks>
                public static Task<long> AppendAsync(RedisKey key, RedisValue value)
                {
                    Task<long> result = SharedCache.Instance.GetWriteConnection(key)
                        .GetDatabase(SharedCache.Instance.Db)
                        .StringAppendAsync(key, value);

                    return result;
                }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:24,代码来源:Strings.cs


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