本文整理汇总了C#中BookSleeve.RedisConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.Open方法的具体用法?C# RedisConnection.Open怎么用?C# RedisConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookSleeve.RedisConnection
的用法示例。
在下文中一共展示了RedisConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例2: GetRedisConnection
private static async Task<RedisConnection> GetRedisConnection(string host)
{
RedisConnection c = new RedisConnection(host);
await c.Open();
return c;
}
示例3: AsyncRedisUsage
// could also be void; only a Task here so I can Wait on
// completion from my Main method, which is not declared
// as async
async static Task AsyncRedisUsage()
{
const int db = 4; // no reason
using(var conn = new RedisConnection("127.0.0.1"))
{
// let's wait until all handshakes have happened
await conn.Open();
var existed = conn.Keys.Remove(db, "some-key");
for (int i = 0; i < 100; i++)
{ // this are also tasks, but I don't
// need to wait on them in this case
#pragma warning disable 4014
conn.Strings.Increment(db, "some-key");
#pragma warning restore 4014
}
// at this point, some messages are flying around
// from a background queue, with responses being
// handled by IOCP; let's add a GET onto the
// bottom of the queue, and let other stuff
// happen until we have the answer (obviously
// we could make much more subtle use here, by
// awaiting multiple things requested much earlier,
// or by doing some SQL Server work etc before
// calling await, essentially acting as a "join")
string result = await conn.Strings.GetString(db, "some-key");
Console.WriteLine(await existed
? "(it already existed; we removed it)"
: "(it didn't exist)");
Console.WriteLine(result);
}
}
示例4: ClearData
public void ClearData()
{
connection = new RedisConnection("localhost", 6379, -1, null, 2147483647, true,10000);
subject = new RedisRepository(connection);
connection.Open();
connection.Server.FlushDb(db);
}
示例5: ConnectionReady
public 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);
try
{
_redisConnection.Open();
_subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
_subscriberConnection.MessageReceived += OnRedisMessageReceived;
_subscriberConnection.Error += OnRedisError;
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}
return true;
}
示例6: Setup
public void Setup()
{
var connection = new RedisConnection("127.0.0.1", allowAdmin: true);
connection.Open();
connection.Server.FlushDb(0);
connection.Close(false);
}
示例7: CanNotOpenNonsenseConnection_IP
public void CanNotOpenNonsenseConnection_IP()
{
using (var conn = new RedisConnection(Config.LocalHost, 6500))
{
conn.Wait(conn.Open());
}
}
示例8: CanNotOpenNonsenseConnection
public void CanNotOpenNonsenseConnection()
{
using (var conn = new RedisConnection("127.0.0.1", 6500))
{
conn.Wait(conn.Open());
}
}
示例9: 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;
}
}
示例10: foo
public static void foo()
{
using (var redis = new RedisConnection("goosefish.redistogo.com", 9836, -1, "88f5c87381f5564b18b4ecba2647e9ab")) {
redis.Open();
redis.Lists.AddLast(1, "w00t", "t00t");
}
}
示例11: 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"));
}
}
示例12: CanNotOpenNonsenseConnection_DNS
public void CanNotOpenNonsenseConnection_DNS()
{
using (var conn = new RedisConnection("doesnot.exist.ds.aasd981230d.com", 6500))
{
conn.Wait(conn.Open());
}
}
示例13: 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;
}
示例14: 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;
}
示例15: RedisMessageBus
public RedisMessageBus(string server, int port, string password, int db, IEnumerable<string> keys, IDependencyResolver resolver)
: base(resolver)
{
_db = db;
_keys = keys.ToArray();
_connection = new RedisConnection(host: server, port: port, password: password);
_connection.Closed += OnConnectionClosed;
_connection.Error += OnConnectionError;
// Start the connection
_connectTask = _connection.Open().Then(() =>
{
// Create a subscription channel in redis
_channel = _connection.GetOpenSubscriberChannel();
// Subscribe to the registered connections
_channel.Subscribe(_keys, OnMessage);
// Dirty hack but it seems like subscribe returns before the actual
// subscription is properly setup in some cases
while (_channel.SubscriptionCount == 0)
{
Thread.Sleep(500);
}
});
}