本文整理汇总了C#中StackExchange.Redis.ConnectionMultiplexer.GetDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMultiplexer.GetDatabase方法的具体用法?C# ConnectionMultiplexer.GetDatabase怎么用?C# ConnectionMultiplexer.GetDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackExchange.Redis.ConnectionMultiplexer
的用法示例。
在下文中一共展示了ConnectionMultiplexer.GetDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Redis
private Redis()
{
try
{
redis = ConnectionMultiplexer.Connect("localhost");
DB = redis.GetDatabase();
}
catch (RedisConnectionException rce)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = Environment.CurrentDirectory + @"\redis\redis.windows.conf";
startInfo.FileName = Environment.CurrentDirectory + @"\redis\redis-server.exe";
startInfo.WorkingDirectory = Environment.CurrentDirectory + @"\redis\";
Process p = Process.Start(startInfo);
Thread.Sleep(200);
for (int i = 0; i < 3; ++i)
{
try
{
redis = ConnectionMultiplexer.Connect("localhost");
DB = redis.GetDatabase();
break;
}
catch (RedisConnectionException rce2)
{
Thread.Sleep(1000);
}
}
}
}
示例2: RedisServer
public RedisServer()
{
ConfigurationOptions config=new ConfigurationOptions();
config.Password=ConfigurationSettings.AppSettings["RedisPass"];
config.EndPoints.Add(ConfigurationSettings.AppSettings["RedisServer"]);
redis = ConnectionMultiplexer.Connect(config);
companies_db = redis.GetDatabase(0);
relations_db = redis.GetDatabase(1);
}
示例3: RedisAdaptor
public RedisAdaptor(List<EndPoint> endPoints)
{
var config = new ConfigurationOptions()
{
AllowAdmin = true,
};
foreach (var endPoint in endPoints)
{
config.EndPoints.Add(endPoint);
}
muxerInstance = ConnectionMultiplexer.Connect(config);
Handle = muxerInstance.GetDatabase();
var script = Load("update_multikeys_multifields.lua");
//todo a hack way .. to be changed later
foreach (var endPoint in muxerInstance.GetEndPoints())
{
var server = muxerInstance.GetServer(endPoint);
updateScriptSha = server.ScriptLoad(script);
}
Handle.StringSet("test", "111");
}
示例4: OpenAsync
public async Task OpenAsync(PartitionContext context)
{
if (!WebJobsHelper.RunAsWebJobs)
Console.WriteLine(string.Format("EventProcessor initialization. Partition: '{0}', Offset: '{1}'",
context.Lease.PartitionId, context.Lease.Offset));
partitionContext = context;
var retries = 3;
while (retries > 0)
{
try
{
retries--;
hubClient = EventHubClient.CreateFromConnectionString(
ConfigurationManager.ConnectionStrings["SigfoxDemoAlertSender"].ConnectionString,
"alert");
cacheConnection = await ConnectionMultiplexer.ConnectAsync(ConfigurationManager.ConnectionStrings["SigfoxDemoCache"].ConnectionString);
cacheDatabase = cacheConnection.GetDatabase();
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SigfoxDemoDatabase"].ConnectionString);
//sqlConnection.Open();
//sqlCommand = new SqlCommand("InsertAlert", sqlConnection) { CommandType = CommandType.StoredProcedure };
//sqlCommand.Parameters.Add(new SqlParameter("@Device", SqlDbType.VarChar));
retries = 0;
}
catch (Exception e)
{
Console.Error.WriteLine("Error opening destination Event Hub: " + e.Message);
if (retries == 0)
throw;
}
}
checkpointStopWatch = new Stopwatch();
checkpointStopWatch.Start();
}
示例5: WorkflowManagement
internal WorkflowManagement(ConnectionMultiplexer mux, ITaskHandler taskHandler, WorkflowHandler workflowHandler, string identifier, IEnumerable<string> typesProcessed, ILua lua, EventHandler<Exception> exceptionHandler = null, Behaviours behaviours = Behaviours.All)
{
_taskHandler = taskHandler;
_workflowHandler = workflowHandler;
if (exceptionHandler != null)
{
ExceptionThrown += exceptionHandler;
}
_typesProcessed = typesProcessed;
_db = mux.GetDatabase();
_sub = mux.GetSubscriber();
if (_typesProcessed == null || _typesProcessed.Count() == 0)
{
_sub.Subscribe("submittedTask", (c, v) =>
{
ProcessNextTask();
});
}
else
{
foreach(var t in _typesProcessed)
{
_sub.Subscribe("submittedTask:" + t, (c, v) =>
{
ProcessNextTask(t);
});
}
}
_sub.Subscribe("workflowFailed", (c, v) =>
{
ProcessNextFailedWorkflow();
});
_sub.Subscribe("workflowComplete", (c, v) =>
{
ProcessNextCompleteWorkflow();
});
_lua = lua;
_lua.LoadScripts(_db, mux.GetServer("localhost:6379"));
_identifier = identifier;
if (behaviours.HasFlag(Behaviours.AutoRestart))
{
var resubmittedTasks = ResubmitTasks();
foreach (var item in resubmittedTasks)
{
Console.WriteLine("Resubmitted {0}", item);
}
}
}
示例6: ConnectAsync
public async Task ConnectAsync()
{
if (_connection == null)
{
_connection = await ConnectionMultiplexer.ConnectAsync(_options.Configuration);
_cache = _connection.GetDatabase();
}
}
示例7: Connect
public void Connect()
{
if (_connection == null)
{
_connection = ConnectionMultiplexer.Connect(_options.Configuration);
_cache = _connection.GetDatabase();
}
}
示例8: RedisCache
/// <summary>
/// Initializes a new instance of the <see cref="RedisCache"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="hostname">The hostname.</param>
public RedisCache(string name, string hostname = "localhost")
: base(name)
{
_redis = ConnectionMultiplexer.Connect(hostname);
_redis.PreserveAsyncOrder = false;
_redisDb = _redis.GetDatabase();
_level1Cache = new MemoryCache(name);
}
示例9: Init
public async Task Init(Logger logger, IProviderConfiguration config, string providerName, int numQueues)
{
_logger = logger;
_redisListBaseName = $"orleans-{providerName}-queue";
ReadRedisConnectionParams(config);
_connection = await ConnectionMultiplexer.ConnectAsync(_server);
_database = _connection.GetDatabase(_databaseNum);
logger.AutoInfo($"connection to Redis successful.");
IsInitialised = true;
}
示例10: DbClientRedis
//-------------------------------------------------------------------------
public DbClientRedis(string databaseName, string connectionString)
{
DatabaseNumber = int.Parse(databaseName);
object asyncState = null;
var c = ConfigurationOptions.Parse(connectionString);
c.AllowAdmin = true;
CM = ConnectionMultiplexer.Connect(c);
DB = CM.GetDatabase(DatabaseNumber, asyncState);
}
示例11: RedisClient
private RedisClient(IPEndPoint endPoint, ConnectionMultiplexer redis)
: base(endPoint)
{
if (null == redis)
{
throw new ArgumentNullException("redis");
}
this.redis = redis;
this.db = redis.GetDatabase();
}
示例12: Execute
internal static void Execute(ConnectionMultiplexer redis)
{
Redis = redis;
var db = Redis.GetDatabase();
Console.Clear();
SimpleTest();
Console.Write("<ENTER> to close ");
Console.ReadLine();
}
示例13: RedisConnectionManager
public RedisConnectionManager(IConfig config)
{
ConfigurationOptions options = new ConfigurationOptions();
options.EndPoints.Add(config.GetString("redisCacheHostName"), config.GetInt("redisCachePortNumber"));
options.Ssl = config.GetBool("redisCacheUseSSL");
options.Password = config.GetString("redisCachePassword");
options.AbortOnConnectFail = false;
options.ConnectTimeout = 30000;
connection = ConnectionMultiplexer.Connect(options);
cache = connection.GetDatabase();
}
示例14: Redis
private void Redis(string message)
{
if (_connection == null)
{
_connection = ConnectionMultiplexer.Connect(ConfigurationManager.ConnectionStrings["AzureRedis"].ToString());
if (_cache == null)
{
_cache = _connection.GetDatabase();
}
}
_cache.ListLeftPush("s", message);
}
示例15: Run
internal static void Run(StackExchange.Redis.ConnectionMultiplexer redis)
{
Console.WriteLine("Hit <ESC> to shutdown this worker.");
Redis = redis;
while ((!Console.KeyAvailable) || (Console.ReadKey().Key != ConsoleKey.Escape))
{
var msg = Redis.GetDatabase().ListLeftPop(Tools.WORKQUEUE);
if (!msg.IsNullOrEmpty)
HandleClusterWork(msg);
else
Thread.Sleep(0);
}
}