using Edu.CacheManager.Base;
using System;
using System.Collections.Generic;
using System.Text;

namespace Edu.Cache.Customer
{
    public class CustomerRedisCache
    {
        /// <summary>
        /// 使用redis第几号库
        /// </summary>
        public static readonly int REDIS_DB3 = 3;

        static readonly RedisHelper redis = new RedisHelper(REDIS_DB3);

        static readonly string DISTRIBUTION_RULE_KEY = "DISTRIBUTION_CURSOR";

        static readonly object LOCKER = new object();

        static readonly object LOCKED = new object();

        public static void Set(object Data)
        {
            lock (LOCKER)
            {
                lock (LOCKED)
                {
                    try
                    {
                        redis.StringSet(DISTRIBUTION_RULE_KEY, Data);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }

        public static int Get()
        {
            lock (LOCKER)
            {
                lock (LOCKED)
                {
                    try
                    {
                        var info = redis.StringGet<int>(DISTRIBUTION_RULE_KEY);
                        //默认往后移动一位
                        redis.StringSet(DISTRIBUTION_RULE_KEY, (info + 1));
                        return info;
                    }
                    catch (Exception)
                    {
                        return 0;
                    }
                }
            }
        }
    }
}
