本文整理汇总了C#中BookSleeve.RedisConnection类的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection类的具体用法?C# RedisConnection怎么用?C# RedisConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisConnection类属于BookSleeve命名空间,在下文中一共展示了RedisConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRedisConnection
private static async Task<RedisConnection> GetRedisConnection(string host)
{
RedisConnection c = new RedisConnection(host);
await c.Open();
return c;
}
示例2: RedisBooksleevePersistence
public RedisBooksleevePersistence()
{
if (conn == null)
{
conn = GetRedisConnection("localhost").Result;
}
}
示例3: Setup
public void Setup()
{
var connection = new RedisConnection("127.0.0.1", allowAdmin: true);
connection.Open();
connection.Server.FlushDb(0);
connection.Close(false);
}
示例4: PerformBitOperation
internal async Task<long> PerformBitOperation(
RedisConnection connection)
{
var keys = new[] { LeftKey, RightKey };
if ("AND".Equals(Operation, StringComparison.Ordinal))
{
return await connection.Strings.BitwiseAnd(Db, Key, keys);
}
if ("OR".Equals(Operation, StringComparison.Ordinal))
{
return await connection.Strings.BitwiseOr(Db, Key, keys);
}
if ("XOR".Equals(Operation, StringComparison.Ordinal))
{
return await connection.Strings.BitwiseXOr(Db, Key, keys);
}
throw new InvalidOperationException(
string.Format(
CultureInfo.CurrentUICulture,
ErrorMessages.CompositeUserActivityReport_PerformBitOperation_Unsupported,
Operation));
}
示例5: foo
public static void foo()
{
using (var redis = new RedisConnection("goosefish.redistogo.com", 9836, -1, "88f5c87381f5564b18b4ecba2647e9ab")) {
redis.Open();
redis.Lists.AddLast(1, "w00t", "t00t");
}
}
示例6: RedisSignalBus
public RedisSignalBus(RedisConnection redisConnection)
{
_handlers = new ConcurrentDictionary<string, SafeSet<EventHandler<SignaledEventArgs>>>();
_redisConnection = redisConnection;
_subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
_subscriberConnection.MessageReceived += OnRedisMessageReceived;
}
示例7: ConnectionReady
private bool ConnectionReady()
{
if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
{
lock (_connectionLock)
{
if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
{
_redisConnection = new RedisConnection(Host, Port, password: Password, maxUnsent: 1);
try
{
_redisConnection.Open().Wait();
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}
return true;
}
示例8: GetBrushActions
public List<CanvasBrushAction> GetBrushActions(string canvasId, int currentPosition)
{
List<CanvasBrushAction> actions = new List<CanvasBrushAction>();
string[] storedActions = null;
using (var conn = new RedisConnection(_redisConfiguration.HostName, _redisConfiguration.
Port, password: _redisConfiguration.Password))
{
conn.Open();
var rangeTask = conn.Lists.RangeString(0, ACTION_PREFIX + canvasId, currentPosition,
Int32.MaxValue);
storedActions = rangeTask.Result;
}
if (storedActions != null)
{
foreach (string storedAction in storedActions)
{
actions.Add(JsonConvert.DeserializeObject<CanvasBrushAction>(storedAction));
}
actions.Sort(new Comparison<CanvasBrushAction>((a, b) =>
{
return a.Sequence.
CompareTo(b.Sequence);
}));
}
return actions;
}
示例9: CanNotOpenNonsenseConnection
public void CanNotOpenNonsenseConnection()
{
using (var conn = new RedisConnection("127.0.0.1", 6500))
{
conn.Wait(conn.Open());
}
}
示例10: CanNotOpenNonsenseConnection_IP
public void CanNotOpenNonsenseConnection_IP()
{
using (var conn = new RedisConnection(Config.LocalHost, 6500))
{
conn.Wait(conn.Open());
}
}
示例11: GetOpen
public RedisConnection GetOpen()
{
lock (syncConnection)
{
if (_Connection != null && !(_Connection.State == RedisConnectionBase.ConnectionState.Closed || _Connection.State == RedisConnectionBase.ConnectionState.Closing))
{
return _Connection;
}
if (_Connection == null || (_Connection.State == RedisConnectionBase.ConnectionState.Closed || _Connection.State == RedisConnectionBase.ConnectionState.Closing))
{
try
{
RoqueTrace.Source.Trace(TraceEventType.Information, "[REDIS] connecting to {0}:{1}", _Host, _Port);
_Connection = new RedisConnection(_Host, _Port, _Timeout);
var openAsync = _Connection.Open();
_Connection.Wait(openAsync);
RoqueTrace.Source.Trace(TraceEventType.Information, "[REDIS] connected");
}
catch (Exception ex)
{
RoqueTrace.Source.Trace(TraceEventType.Error, "[REDIS] error connecting to {0}:{1}, {2}", _Host, _Port, ex.Message, ex);
throw;
}
}
return _Connection;
}
}
示例12: Test
public void Test()
{
Debug.WriteLine("Iniciando");
using (var conn = new RedisConnection("localhost"))
{
conn.Open();
conn.Strings.Set(0, "nome", "joão");
}
Thread.Sleep(2000);
using (var conn = new RedisConnection("localhost", 6380))
{
conn.Open();
conn.Strings.GetString(0, "nome").Result.ShouldEqual("joão");
}
this.redisMaster.Kill();
Thread.Sleep(2000);
using (var conn = new RedisConnection("localhost", 6380))
{
conn.Open();
conn.Strings.GetString(0, "nome").Result.ShouldEqual("joão");
conn.Strings.Set(0, "idade", "27");
conn.Strings.GetString(0, "idade").Result.ShouldEqual("27");
}
Debug.WriteLine("Fim");
}
示例13: should_result_in_field5_with_6
public void should_result_in_field5_with_6()
{
using (var client = new RedisConnection("localhost"))
{
client.Open();
var redis = new RedisBooksleeveConnector(client);
var key = "hello";
var field1 = "world";
var field2 = "world2";
var field3 = "w3";
var field4 = "w4";
var field5 = "w5";
var field6 = "w6";
redis.HSet(key, field1, "1");
redis.HSet(key, field2, "2");
redis.HSet(key, field3, "3");
redis.HSet(key, field4, "4");
redis.HSet(key, field5, "5");
redis.HSet(key, field6, "6");
var result = redis.HGetAll(key);
Assert.That(result[field5], Is.EqualTo("5"));
}
}
示例14: CanNotOpenNonsenseConnection_DNS
public void CanNotOpenNonsenseConnection_DNS()
{
using (var conn = new RedisConnection("doesnot.exist.ds.aasd981230d.com", 6500))
{
conn.Wait(conn.Open());
}
}
示例15: CreateRedisConnection
public Task<RedisConnection> CreateRedisConnection()
{
var settings = RedisConnectionProvider.Instance.ConnectionsSettings;
var redisConnection = new RedisConnection(host: settings["host"], port: Convert.ToInt32(settings["port"]), password: settings["password"]);
var taskCreateConnection = new TaskCompletionSource<RedisConnection>();
try
{
redisConnection.Open().ContinueWith((task) =>
{
if (!task.IsFaulted)
{
taskCreateConnection.SetResult(redisConnection);
}
else
{
task.Exception.Handle(x => true);
taskCreateConnection.SetException(task.Exception);
}
}, TaskScheduler.Default);
}
catch (Exception ex)
{
taskCreateConnection.SetException(ex);
}
return taskCreateConnection.Task;
}