コード例 #1
0
ファイル: Program.cs プロジェクト: zongu/RedisPubSub
        static void Main(string[] args)
        {
            try
            {
                //// 啟動redis發布訂閱中樞
                RedisFactory.Start(NoSqlService.RedisConnections, NoSqlService.RedisAffixKey, NoSqlService.RedisDataBase);
                ////訂閱關注Topics
                var consumer = new RedisConsumer(ConfigHelper.SubscribTopics, new PubSubDispatcher <RedisEventStream>(AutofacConfig.Container));
                consumer.Register();

                //// 發布事件
                RedisProducer.Publish("A", new AEvent()
                {
                    Message = $"{nameof(AEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
                RedisProducer.Publish("B", new AEvent()
                {
                    Message = $"{nameof(BEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
                RedisProducer.Publish("C", new AEvent()
                {
                    Message = $"{nameof(CEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
コード例 #2
0
        public void RedisCacheFactory()
        {
            var factory =
                new RedisFactory(new Dictionary <string, string>
            {
                { "configuration", "config" },
                { "instance-name", "instance" }
            });
            var cache1 = factory.BuildCache();

            Assert.That(cache1, Is.Not.Null, "Factory has yielded null");
            Assert.That(cache1, Is.InstanceOf <RedisCache>(), "Unexpected cache");
            var cache2 = factory.BuildCache();

            Assert.That(cache2, Is.Not.EqualTo(cache1),
                        "The Redis cache factory is supposed to always yield a new instance");

            var options = RedisCacheOptionsField.GetValue(factory);

            Assert.That(options, Is.Not.Null, "Factory cache options not found");
            Assert.That(options, Is.InstanceOf <RedisCacheOptions>(), "Unexpected options type");
            var redisOptions = (RedisCacheOptions)options;

            Assert.That(redisOptions.Configuration, Is.EqualTo("config"));
            Assert.That(redisOptions.InstanceName, Is.EqualTo("instance"));
        }
コード例 #3
0
ファイル: RedisCache.cs プロジェクト: jackyzhou/ZSharp
        public RedisCache(ISerializer serializer, IRedisWrapper redisWrapper = null)
        {
            GuardHelper.ArgumentNotNull(() => serializer);
            if (redisWrapper == null)
            {
                redisWrapper = RedisFactory.GetRedisWrapper();
            }

            this.serializer   = serializer;
            this.redisWrapper = redisWrapper;
        }
コード例 #4
0
        public static IServiceCollection AddAtlassHangfire(this IServiceCollection services, IConfiguration configuration)
        {
            var redis = configuration.GetSection("RedisConfig").Get <RedisConfigDto>();

            var crontab = configuration.GetSection("Crontab").Get <CrontabConfigDto>();

            GlobalContext.RedisConfig      = redis;
            GlobalContext.CrontabConfigDto = crontab;
            try
            {
                RedisFactory.Init(redis);
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception(ex);
            }
            //hangfire
            try
            {
                if (crontab.Enable)
                {
                    string filePath = AppDomain.CurrentDomain.BaseDirectory + @"data\hangfire_lite.db";
                    //string connection = $"Data Source ={filePath};Mode=ReadWriteCreate;Cache=Shared";
                    //LoggerHelper.Info(connection);
                    string liteConnection = $"Filename={filePath};Connection=direct";
                    GlobalStateHandlers.Handlers.Add(new SucceededStateExpireHandler(30));
                    services.AddHangfire(x => x.UseLogProvider(new CustomLogProvider())
                                         .UseLiteDbStorage(liteConnection, null)
                                         .UseHeartbeatPage(checkInterval: TimeSpan.FromSeconds(crontab.CheckInterval)));
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception(ex);
            }



            return(services);
        }
コード例 #5
0
        public IActionResult Auth(string code, string state)
        {
            AccessTokenContainer.RegisterAsync(_wxSetting.WeixinAppId, _wxSetting.WeixinAppSecret, "doctor_platform");
            string state1 = IdHelper.ObjectId();            //随机数,用于识别请求可靠性

            HttpContext.Session.SetString("State", state1); //储存随机数到Session
            string signUrl = Request.AbsoluteUri();

            // LoggerHelper.Info(signUrl);
            // MemoryCacheHelper.Set("test", "nihao", TimeSpan.FromMinutes(1));
            // var keys= MemoryCacheHelper.GetCacheKeys();
            if (!string.IsNullOrEmpty(code))
            {
                var result = OAuthApi.GetAccessToken(_wxSetting.WeixinAppId, _wxSetting.WeixinAppSecret, code);
                if (result.errcode != ReturnCode.请求成功)
                {
                    return(Content("错误:" + result.errmsg));
                }
                //LoggerHelper.Info(result.openid);
                //尝试获取用户信息
                //OAuthUserInfo userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                //string json = userInfo.ToJson();
                //LoggerHelper.Info(json);
                //Task.Factory.StartNew(() => GetUserInfo(result.access_token, result.openid));
                string key         = "{access_token}:wxtoken";
                var    redisClient = RedisFactory.GetRedisClient();
                redisClient.Set(key, result, result.expires_in);

                RequestHelper.SetOpenId(result.openid, result.expires_in);
                string homeUrl = $"/wechat/index.html?openId={result.openid}";
                return(Redirect(homeUrl));
            }
            else
            {
                // signUrl = signUrl + "/WxExpert/Index";snsapi_userinfo snsapi_base
                var url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect",
                                        _wxSetting.WeixinAppId, signUrl.UrlEncode(), state1);
                return(Redirect(url));
            }
        }
コード例 #6
0
 public RedisWrapperTest()
 {
     this.redisWrapper = RedisFactory.GetRedisWrapper();
 }
コード例 #7
0
 public RedisSessionStorage()
 {
     _redisCache = RedisFactory.GetProvider(RedisProviderGroup);
 }
コード例 #8
0
 public IRedisStringTests()
 {
     _provider = RedisFactory.GetProvider();
 }
コード例 #9
0
ファイル: IRedisKeyTests.cs プロジェクト: cnmade/Mstm.CSharp
 public IRedisKeyTests()
 {
     _provider = RedisFactory.GetProvider();
 }
コード例 #10
0
ファイル: LockTest.cs プロジェクト: jackyzhou/ZSharp
 public LockTest(ITestOutputHelper testOutput)
 {
     ServiceLocator.SetLocatorProvider(UnityConfig.GetConfiguredContainer());
     this.redisWrapper = RedisFactory.GetRedisWrapper();
     this.testOutput   = testOutput;
 }