예제 #1
0
        public SapphireRedisSyncModule(RedisStore redisStore, RedisSyncConfiguration configuration, SyncContext syncContext)
        {
            this.configuration = configuration;
            this.syncContext   = syncContext;
            redisMultiplexer   = redisStore.RedisCache.Multiplexer;

            redisMultiplexer.GetSubscriber().Subscribe($"{configuration.Prefix}sapphiresync/*/*", (channel, message) =>
            {
                string[] channelParts  = channel.ToString().Split('/');
                string senderSessionId = channelParts[^ 2];

                if (syncContext.SessionId.ToString() == senderSessionId)
                {
                    return;
                }

                string channelPath = channelParts[^ 1];
예제 #2
0
 public RedisStore(RedisSyncConfiguration configuration)
 {
     lazyConnection = new Lazy <ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configuration.ConnectionString));
 }
        public static SapphireDatabaseBuilder AddRedisSync(this SapphireDatabaseBuilder databaseBuilder, RedisSyncConfiguration redisSyncConfiguration)
        {
            databaseBuilder.serviceCollection.AddSingleton(redisSyncConfiguration);
            databaseBuilder.serviceCollection.AddSingleton <RedisStore>();
            databaseBuilder.serviceCollection.AddSingleton <ISapphireSyncModule, SapphireRedisSyncModule>();

            return(databaseBuilder);
        }