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

C# Redis.ConnectionMultiplexer类代码示例

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

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



ConnectionMultiplexer类属于StackExchange.Redis命名空间,在下文中一共展示了ConnectionMultiplexer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
                    }
                }
            }

        }
开发者ID:daishin-securities,项目名称:DSDistributedProcessingSystem,代码行数:32,代码来源:Redis.cs


示例2: 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();
 }
开发者ID:danvy,项目名称:sigfox,代码行数:33,代码来源:EventProcessor.cs


示例3: MessagesController

 public MessagesController(ApplicationDbContext context, UserManager<ApplicationUser> userManager, MapperConfiguration mapperConfiguration, ConnectionMultiplexer redis)
 {
     _context = context;
     _userManager = userManager;
     _mapperConfiguration = mapperConfiguration;
     _redis = redis;
 }
开发者ID:gdoron,项目名称:Forums,代码行数:7,代码来源:MessagesController.cs


示例4: RedisManager

        public RedisManager()
        {
            var configurationOptions = new ConfigurationOptions {Password = "be61827946a5d7a6b7333875104d4a26"};
            configurationOptions.EndPoints.Add(HostAndPort);

            _redisConn = ConnectionMultiplexer.Connect(configurationOptions);
        }
开发者ID:GabrielMCardozo,项目名称:Visivel2,代码行数:7,代码来源:RedisManager.cs


示例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);
                }
            }
        }
开发者ID:Timxuhj,项目名称:redis.workflow,代码行数:60,代码来源:WorkloadManagement.cs


示例6: RedisCacheConfig

        static RedisCacheConfig()
        {
            string isLocal = WebConfigReader.Read("IsLocal");

            if (isLocal == "1")
            {
                connection = ConnectionMultiplexer.Connect(WebConfigReader.Read("RedisServer"));
            }
            else
            {
                var options = new ConfigurationOptions();

                options.EndPoints.Add(WebConfigReader.Read("RedisKeyDns"), 6380);
                options.Ssl = true;

                options.Password = WebConfigReader.Read("RedisPassword");
                options.AllowAdmin = true;

                // necessary?
                options.KeepAlive = 30;
                options.ConnectTimeout = 15000;
                options.SyncTimeout = 15000;

                connection = ConnectionMultiplexer.Connect(options);
            }
        }
开发者ID:togglebrain,项目名称:stock-analytics,代码行数:26,代码来源:RedisCacheConfig.cs


示例7: RedisEntityTagStore

 public RedisEntityTagStore(ConnectionMultiplexer connection, 
     int databaseId = 0,
     TimeSpan? expiry = null)
 {
     _expiry = expiry;
     Init(connection, databaseId);
 }
开发者ID:yyf919,项目名称:CacheCow,代码行数:7,代码来源:RedisEntityTagStore.cs


示例8: RedisCache

 /// <summary>
 /// Initializes a new instance of the <see cref="RedisCache"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public RedisCache(ConfigurationOptions configuration)
 {
     if (RedisCache.connection == null)
     {
         try
         {
             connectionTask = ConnectionMultiplexer.ConnectAsync(configuration);
             connectionTask.ContinueWith(t =>
                 {
                     lock (syncronizationObject)
                     {
                         if (RedisCache.connection == null)
                             RedisCache.connection = t.Result;
                     }
                     this.cache = RedisCache.connection.GetDatabase();
                     Trace.TraceInformation("Redis Cache Provider connection complete - Correlation Id = {0}", Trace.CorrelationManager.ActivityId);
                 });
         }
         catch (AggregateException age)
         {
             age.Handle(e =>
             {
                 Trace.TraceError("Redis Cache Provider error - Correlation Id = {0}\n {1}\n {2}", Trace.CorrelationManager.ActivityId, e.Message, e.StackTrace);
                 return true;
             });
         }
         catch (Exception ex)
         {
             Trace.TraceError("Redis Cache Provider exception - Correlation Id = {0}\n {1}\n {2}", Trace.CorrelationManager.ActivityId, ex.Message, ex.StackTrace);
         }
     }
 }
开发者ID:vsthakur78,项目名称:AzureRedisCacheProvider,代码行数:36,代码来源:RedisCache.cs


示例9: UseRedis

        /// <summary>
        /// Use Redis as the messaging backplane for scaling out of ASP.NET SignalR applications in a web farm.
        /// </summary>
        /// <param name="resolver">The dependency resolver</param>
        /// <param name="configuration">The Redis scale-out configuration options.</param>
        /// <param name="sharedMultiplexer">shared multiplexer</param>
        /// <returns>The dependency resolver.</returns>
        public static IDependencyResolver UseRedis(this IDependencyResolver resolver, RedisScaleoutConfiguration configuration, ConnectionMultiplexer sharedMultiplexer)
        {
            var bus = new Lazy<RedisMessageBus>(() => new RedisMessageBus(resolver, configuration, new RedisConnection(sharedMultiplexer)));
            resolver.Register(typeof(IMessageBus), () => bus.Value);

            return resolver;
        }
开发者ID:EutechCybernetic,项目名称:SignalR,代码行数:14,代码来源:DependencyResolverExtensions.cs


示例10: MainForm

        public MainForm()
        {
            InitializeComponent();
            var options = new ConfigurationOptions
            {
                ConnectTimeout = 5000,
                SyncTimeout = 2000,
                KeepAlive = 60,
                EndPoints =
                {
                    {Settings.Default.RedisHost, Settings.Default.RedisPort}
                }
            };

            _redis = ConnectionMultiplexer.Connect(options);
            var retries = 0;
            while (!_redis.IsConnected)
            {
                var config = _redis.Configuration;
                _redis.Dispose();
                if (retries > 10)
                {
                    MessageBox.Show(string.Format("Could not connect to the Redis server with configuration: {0}",
                        config));
                    Application.Exit();
                }

                _redis = ConnectionMultiplexer.Connect(options, Console.Out);
                retries++;

            }
            _red = new LightControlSet(button_RedOn, button_RedOff, button_RedFlash, textBox_RedOnDuty, textBox_RedOffDuty, textBox_RedOffset, textBox_RedPower, button_RedApply);
            _green = new LightControlSet(button_GreenOn, button_GreenOff, button_GreenFlash, textBox_GreenOnDuty, textBox_GreenOffDuty, textBox_GreenOffset, textBox_GreenPower, button_GreenApply);
            _blueYellow = new LightControlSet(button_BlueOn, button_BlueOff, button_BlueFlash, textBox_BlueOnDuty, textBox_BlueOffDuty, textBox_BlueOffset, textBox_BluePower, button_BlueApply);
        }
开发者ID:rhysparry,项目名称:HIDVIWINCS,代码行数:35,代码来源:Form1.cs


示例11: Connect

        public static void Connect()
        {
            ConfigurationOptions options = new ConfigurationOptions();
            options.EndPoints.Add("localhost:6379");

            Connection = ConnectionMultiplexer.Connect(options);
        }
开发者ID:angelrubenyui,项目名称:KnowTechDDD,代码行数:7,代码来源:RedisConnectionFactory.cs


示例12: RetrieveMultiplexer

        public static ConnectionMultiplexer RetrieveMultiplexer(ConfigurationOptions config)
        {
           if(_multiplexer != null) return _multiplexer;

            _multiplexer = ConnectionMultiplexer.Connect(config);
            return _multiplexer;
        }
开发者ID:subscriptionapp,项目名称:Client.Net,代码行数:7,代码来源:ConnectionHandler.cs


示例13: RedisStorage

        public RedisStorage(string connectionString, RedisStorageOptions options = null)
        {
            if (connectionString == null) throw new ArgumentNullException("connectionString");
            if (options == null) options = new RedisStorageOptions();

            _connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
            _invisibilityTimeout = options.InvisibilityTimeout;
            var endpoint = _connectionMultiplexer.GetEndPoints()[0];
            if (endpoint is IPEndPoint)
            {
                var ipEp = endpoint as IPEndPoint;
                ConnectionString = string.Format("{0}:{1}", TryGetHostName(ipEp.Address), ipEp.Port);
            }
            else
            {
                var dnsEp = endpoint as DnsEndPoint;
                ConnectionString = string.Format("{0}:{1}", dnsEp.Host, dnsEp.Port);
            }

            Db = options.Db;
            if (Prefix != options.Prefix)
            {
                Prefix = options.Prefix;
            }
            identity = Guid.NewGuid().ToString();
        }
开发者ID:xyting,项目名称:Hangfire.Redis.StackExchange,代码行数:26,代码来源:RedisStorage.cs


示例14: 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");
        }
开发者ID:fingerpasswang,项目名称:Phial,代码行数:28,代码来源:RedisAdaptor.cs


示例15: WatcherManager

        public WatcherManager(IEnumerable<WatchGroup> groups)
        {
            var groupList = groups.ToList();
            var config = new ConfigurationOptions()
            {
                AllowAdmin = true,
            };

            foreach (var group in groupList)
            {
                config.EndPoints.Add(group.Master.EndPoint);
            }

            muxerInstance = ConnectionMultiplexer.Connect(config);
            muxerInstance.ConnectionRestored += MuxerInstanceOnConnectionRestored;

            foreach (var group in groupList)
            {
                var server = muxerInstance.GetServer(group.Master.EndPoint);
                var epStr = server.EndPoint.ToString();

                group.Master.Server = server;
                group.Master.OnPing(TimeSpan.Zero);

                Program.zkAdaptor.Identity(group.Master.EndPoint.ToString());
                this.groups.Add(epStr, group);
                redisInstancesDict.Add(epStr, group.Master);
            }
        }
开发者ID:fingerpasswang,项目名称:Phial.Fantasy,代码行数:29,代码来源:WatcherManager.cs


示例16: Create

 public StackExchange.Redis.ConnectionMultiplexer Create()
 {
     Logger.Info("Connect to Redis.");
     if (instance != null && instance.IsConnected)
     {
         Logger.Info("Redis is connected 1");
         return instance;
     }
     lock (LockObject)
     {
         if (instance != null && instance.IsConnected)
         {
             Logger.Info("Redis is connected 2");
             return instance;
         }
         if (instance != null)
         {
             instance.Dispose();
             Logger.Info("Connection disconnected. Disposing connection...");
         }
         instance = ConnectionMultiplexer.Connect(redisConnectionString);
         Logger.Info("Creating new instance of Redis Connection");
     }
     return instance;
 }
开发者ID:S-origin,项目名称:Tam.Framework,代码行数:25,代码来源:SingletonRedisConnection.cs


示例17: RedisSubscriptionBroker

 public RedisSubscriptionBroker(ConnectionMultiplexer connection, string prefix)
 {
     this.connection = connection;
     this.subscriptionChannel = string.Format("{0}.subscriptions.broker", prefix);
     this.handlers = new ConcurrentBag<Action<SubscriptionChange, Subscription>>();
     this.initializationTask = new Lazy<Task>(() => this.Initialize());
 }
开发者ID:mfelicio,项目名称:NDomain,代码行数:7,代码来源:RedisSubscriptionBroker.cs


示例18: RedisCache

        public RedisCache(string regionName, IDictionary<string, string> properties, RedisCacheElement element, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options)
        {
            this.connectionMultiplexer = connectionMultiplexer.ThrowIfNull("connectionMultiplexer");
            this.options = options.ThrowIfNull("options").ShallowCloneAndValidate();

            RegionName = regionName.ThrowIfNull("regionName");

            if (element == null)
            {
                expiry = TimeSpan.FromSeconds(
                    PropertiesHelper.GetInt32(Cfg.Environment.CacheDefaultExpiration, properties, DefaultExpiry)
                );
            }
            else
            {
                expiry = element.Expiration;
            }

            log.DebugFormat("using expiration : {0} seconds", expiry.TotalSeconds);

            var @namespace = CacheNamePrefix + RegionName;

            CacheNamespace = new RedisNamespace(@namespace);
            SyncInitialGeneration();
        }
开发者ID:oskarn,项目名称:NHibernate.Caches.Redis,代码行数:25,代码来源:RedisCache.cs


示例19: Init

        public static void Init(string sHost, int iPort, string sPassword)
        {
            CacheDatabase._Host = sHost;
            CacheDatabase._Port = iPort;
            CacheDatabase._Password = sPassword;
            if (CacheDatabase._Password.Length > 0)
            {
                CacheDatabase._AuthRequired = true;
            }
            else
            {
                CacheDatabase._AuthRequired = false;
            }

            _oConectionOptions = new ConfigurationOptions();
            if (CacheDatabase._AuthRequired)
            {
                CacheDatabase._oConectionOptions.Password = CacheDatabase._Password;
            }

            CacheDatabase._oConectionOptions.EndPoints.Add(CacheDatabase._Host + ":" + CacheDatabase._Port.ToString());
            CacheDatabase._oCacheConnection = ConnectionMultiplexer.Connect(CacheDatabase._oConectionOptions);
            CacheDatabase._oCommand = CacheDatabase._oCacheConnection.GetDatabase();
            //Check to make sure the Key Exists and if not then set it to 0
            if (!_oCommand.KeyExists(CacheDatabase._ObjectCounterKeyName))
            {
                CacheDatabase._oCommand.StringSet(CacheDatabase._ObjectCounterKeyName, 0);
            }
        }
开发者ID:jordanburnam,项目名称:SpotifyChangeControl,代码行数:29,代码来源:CacheDatabase.cs


示例20: RedisSessionStateStoreProvider

 static RedisSessionStateStoreProvider()
 {
     ConnectionMultiplexer = ConnectionMultiplexer.Connect(new ConfigurationOptions
     {
         EndPoints = { ConfigurationManager.AppSettings["RedisServer"] },
         ConnectTimeout = 30 * 1000
     });
 }
开发者ID:RabbitTeam,项目名称:Distributed,代码行数:8,代码来源:RedisSessionStateStoreProvider.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# StacMan.ApiUrlBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Redis.ConfigurationOptions类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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