本文整理汇总了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
}
示例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);
}
示例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);
}
示例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));
}
示例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]);
}
示例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));
}
示例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;
}
示例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)
{
}
}
示例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;
}
示例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());
}
示例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;
}
示例12: IsExpiredLockValue
public static bool IsExpiredLockValue(RedisValue lockValue, DateTime currentTime)
{
if (lockValue.IsEmpty)
return false;
var timeNow = DateTimeExtensions.UnixTimeNow;
return (timeNow >= lockValue);
}
示例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;
}
}
示例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;
}
示例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;
}