• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# RedisKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: HashSlot

        /// <summary>
        /// Computes the hash-slot that would be used by the given key
        /// </summary>
        public unsafe int HashSlot(RedisKey key)
        {
            //HASH_SLOT = CRC16(key) mod 16384
            if (key.IsNull) return NoSlot;
            unchecked
            {
                var blob = (byte[])key;
                fixed (byte* ptr = blob)
                {
                    int offset = 0, count = blob.Length, start, end;
                    if ((start = IndexOf(ptr, (byte)'{', 0, count - 1)) >= 0
                        && (end = IndexOf(ptr, (byte)'}', start + 1, count)) >= 0
                        && --end != start)
                    {
                        offset = start + 1;
                        count = end - start; // note we already subtracted one via --end
                    }

                    uint crc = 0;
                    for (int i = 0; i < count; i++)
                        crc = ((crc << 8) ^ crc16tab[((crc >> 8) ^ ptr[offset++]) & 0x00FF]) & 0x0000FFFF;
                    return (int)(crc % RedisClusterSlotCount);
                }
            }
        }
开发者ID:carfaxad,项目名称:StackExchange.Redis,代码行数:28,代码来源:ServerSelectionStrategy.cs


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


示例3: WithKeyPrefix

        /// <summary>
        ///     Creates a new <see cref="IDatabase"/> instance that provides an isolated key space
        ///     of the specified underyling database instance.
        /// </summary>
        /// <param name="database">
        ///     The underlying database instance that the returned instance shall use.
        /// </param>
        /// <param name="keyPrefix">
        ///     The prefix that defines a key space isolation for the returned database instance.
        /// </param>
        /// <returns>
        ///     A new <see cref="IDatabase"/> instance that invokes the specified underlying
        ///     <paramref name="database"/> but prepends the specified <paramref name="keyPrefix"/>
        ///     to all key paramters and thus forms a logical key space isolation.
        /// </returns>
        /// <remarks>
        /// <para>
        ///     The following methods are not supported in a key space isolated database and
        ///     will throw an <see cref="NotSupportedException"/> when invoked:
        /// </para>    
        /// <list type="bullet">
        ///     <item><see cref="IDatabaseAsync.KeyRandomAsync(CommandFlags)"/></item>
        ///     <item><see cref="IDatabase.KeyRandom(CommandFlags)"/></item>
        /// </list>
        /// <para>
        ///     Please notice that keys passed to a script are prefixed (as normal) but care must
        ///     be taken when a script returns the name of a key as that will (currently) not be
        ///     "unprefixed".
        /// </para>
        /// </remarks>
        public static IDatabase WithKeyPrefix(this IDatabase database, RedisKey keyPrefix)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            if (keyPrefix.IsNull)
            {
                throw new ArgumentNullException("keyPrefix");
            }

            if (keyPrefix.IsEmpty)
            {
                return database; // fine - you can keep using the original, then
            }

            if(database is DatabaseWrapper)
            {
                // combine the key in advance to minimize indirection
                var wrapper = (DatabaseWrapper)database;
                keyPrefix = wrapper.ToInner(keyPrefix);
                database = wrapper.Inner;
            }

            return new DatabaseWrapper(database, keyPrefix.AsPrefix());
        }
开发者ID:okaywang,项目名称:ZpRedis,代码行数:57,代码来源:DatabaseExtension.cs


示例4: 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


示例5: 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


示例6: GetString

                /// <summary>
                /// Returns the value associated with field in the hash stored at key.
                /// </summary>
                /// <returns>
                /// the value associated with field, or nil when field is not present in the hash or key does not exist.
                /// </returns>
                /// <remarks>http://redis.io/commands/hget</remarks>
                public static Task<RedisValue> GetString(RedisKey key, RedisValue field)
                {
                    Task<RedisValue> result = SharedCache.Instance.GetReadConnection(key)
                        .GetDatabase(SharedCache.Instance.Db)
                        .HashGetAsync(key, field);

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


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


示例8: Lock

 public bool Lock(RedisKey resource, TimeSpan ttl, out Lock lockObject)
 {
     var task = LockAsync(resource, ttl);
     task.Wait();
     var result = task.Result;
     lockObject = result.Item2;
     return result.Item1;
 }
开发者ID:collinsauve,项目名称:redlock-cs,代码行数:8,代码来源:Redlock.cs


示例9: Delete

                /// <summary>
                /// Removes the specified key. A key is ignored if it does not exist.
                /// </summary>
                /// <param name="key">
                /// The key.
                /// </param>
                /// <returns>
                /// True if the key was removed.
                /// </returns>
                /// <remarks>
                /// http://redis.io/commands/del
                /// </remarks>
                public static bool Delete(RedisKey key)
                {
                    bool result = SharedCache.Instance.GetWriteConnection(key)
                        .GetDatabase(SharedCache.Instance.Db)
                        .KeyDelete(key);

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


示例10: 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


示例11: DeleteAsync

                /// <summary>
                /// Removes the specified key. A key is ignored if it does not exist.
                /// </summary>
                /// <param name="key">
                /// The key.
                /// </param>
                /// <returns>
                /// True if the key was removed.
                /// </returns>
                /// <remarks>
                /// http://redis.io/commands/del
                /// </remarks>
                public static Task<bool> DeleteAsync(RedisKey key)
                {
                    Task<bool> result = SharedCache.Instance.GetWriteConnection(key)
                        .GetDatabase(SharedCache.Instance.Db)
                        .KeyDeleteAsync(key);

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


示例12: CommandStart

        public void CommandStart(RedisSettings usedSettings, string command, RedisKey key)
        {
            if (TimerStrategy == null) return;
            this.start = TimerStrategy.Start();

            this.usedSettings = usedSettings;
            this.command = command;
            this.key = key;
        }
开发者ID:cloud9-plus,项目名称:CloudStructures,代码行数:9,代码来源:GlimpseRedisCommandTracer.cs


示例13: ExecuteAfterHandlers

        /// <summary>
        /// Executes all Redis command handlers, running behaviors that must run after some given command has been already executed.
        /// </summary>
        /// <typeparam name="TResult">The type of Redis command result</typeparam>
        /// <param name="handlers">The sequence of Redis command handlers</param>
        /// <param name="command">The Redis command</param>
        /// <param name="involvedKeys">An array of involved Redis keys in the command</param>
        /// <param name="result">The result of the Redis command execution</param>
        /// <returns>True if handlers could be executed. Otherwise, false.</returns>
        public static bool ExecuteAfterHandlers(this IEnumerable<IRedisCommandHandler> handlers, RedisCommand command, RedisKey[] involvedKeys, ref object result)
        {
            bool canExecute = CanExecuteHandlers(handlers, command);

            if (canExecute)
                foreach (IRedisCommandHandler handler in handlers)
                    handler.OnExecuted(command, ref result, involvedKeys);

            return canExecute;
        }
开发者ID:mfidemraizer,项目名称:StackExchange.Redis,代码行数:19,代码来源:IRedisCommandHandlerExtensions.cs


示例14: ExecuteBeforeHandlers

        /// <summary>
        /// Executes all Redis command handlers, running behaviors that must run before some given command is about to get executed.
        /// </summary>
        /// <param name="handlers">The sequence of Redis command handlers</param>
        /// <param name="command">The Redis command</param>
        /// <param name="involvedKeys">An array of involved Redis keys in the command</param>
        /// <param name="involvedValues">An array of involved Redis values in the command</param>
        /// <returns>True if handlers could be executed. Otherwise, false.</returns>
        public static bool ExecuteBeforeHandlers(this IEnumerable<IRedisCommandHandler> handlers, RedisCommand command, RedisKey[] involvedKeys = null, RedisValue[] involvedValues = null)
        {
            bool canExecute = CanExecuteHandlers(handlers, command);

            if (canExecute)
                foreach (IRedisCommandHandler handler in handlers)
                    handler.OnExecuting(command, involvedKeys, involvedValues);

            return canExecute;
        }
开发者ID:mfidemraizer,项目名称:StackExchange.Redis,代码行数:18,代码来源:IRedisCommandHandlerExtensions.cs


示例15: SetUniqueVal

        internal static void SetUniqueVal(RedisKey hashKey, RedisValue hashField, RedisValue value, RedisKey indexKey)
        {
            var result = Store.Database.ScriptEvaluate(Script, new {hashKey, hashField, finalVal = value, indexKey});
            if ((bool)result)
            {
                return;
            }

            throw new UniqueConstraintViolatedException();
        }
开发者ID:JasonPunyon,项目名称:RedisStore,代码行数:10,代码来源:UniqueConstraintAttribute.cs


示例16: GetUserDeviceTokensAsync

 public async Task<IEnumerable<DeviceToken>> GetUserDeviceTokensAsync(IEnumerable<string> userIds)
 {
     var keys = new RedisKey[userIds.Count()];
     for (int i = 0; i < userIds.Count(); i++)
     {
         keys[i] = userIds.ElementAt(i);
     }
     var dtJsons = await pubsubRedis.GetDatabase().StringGetAsync(keys.ToArray(), CommandFlags.PreferSlave);
     return from item in dtJsons select JsonToDeviceToken(item);
 }
开发者ID:Sharelink,项目名称:BahamutZero,代码行数:10,代码来源:BahamutPubSubService.cs


示例17: RedisTimelineMessage

 public RedisTimelineMessage(RedisSettings usedSettings, string command, RedisKey key, object sentObject, long sentSize, object receivedObject, long receivedSize, bool isError)
 {
     UsedSettings = usedSettings;
     Command = command;
     Key = key;
     SentObject = sentObject;
     SentSize = sentSize;
     ReceivedObject = receivedObject;
     ReceivedSize = receivedSize;
     IsError = isError;
 }
开发者ID:cloud9-plus,项目名称:CloudStructures,代码行数:11,代码来源:RedisTimelineMessage.cs


示例18: Remove

 /// <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>
 /// <remarks>http://redis.io/commands/hdel</remarks>
 /// <returns>The number of fields that were removed.</returns>
 public static Task<long> Remove(RedisKey key, RedisValue[] fields)
 {
     var connections = SharedCache.Instance.GetWriteConnections(key);
     Task<long> result = null;
     foreach (var connection in connections)
     {
         var task = connection.GetDatabase(SharedCache.Instance.Db)
             .HashDeleteAsync(key, fields);
         if (null == result)
             result = task;
     }
     return result;
 }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:19,代码来源:SharedHashesCache.cs


示例19: Exists

 /// <summary>
 /// Returns if field is an existing field in the hash stored at key.
 /// </summary>
 /// <returns>
 /// 1 if the hash contains field. 0 if the hash does not contain field, or key does not exist.
 /// </returns>
 /// <remarks>http://redis.io/commands/hexists</remarks>
 public static Task<bool> Exists(RedisKey key, RedisValue field)
 {
     var connections = SharedCache.Instance.GetWriteConnections(key);
     Task<bool> result = null;
     foreach (var connection in connections)
     {
         var task = connection.GetDatabase(SharedCache.Instance.Db)
             .HashExistsAsync(key, field);
         if (null == result)
             result = task;
     }
     return result;
 }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:20,代码来源:SharedHashesCache.cs


示例20: ScriptEvaluateAsync

        public Task ScriptEvaluateAsync(int database, string script, string key, byte[] messageArguments)
        {
            if (_connection == null)
            {
                throw new InvalidOperationException(Resources.Error_RedisConnectionNotStarted);
            }

            var keys = new RedisKey[] { key };

            var arguments = new RedisValue[] { messageArguments };

          return _connection.GetDatabase(database).ScriptEvaluateAsync(script, keys, arguments);
        }
开发者ID:MATTCASH83,项目名称:SignalR,代码行数:13,代码来源:RedisConnection.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RedisValue类代码示例发布时间:2022-05-24
下一篇:
C# RedisClient类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap