Esempio n. 1
0
        public UserController()
        {
            string maxUserIdString = RedisDBManager.GetDatabase().StringGet(MAX_USER_ID_KEY);

            try
            {
                this.m_maxUserId = Convert.ToInt32(maxUserIdString, 10);
            }
            catch (OverflowException)
            {
                this.m_maxUserId = 0;
            }
        }
Esempio n. 2
0
        public int PutUser(User user)
        {
            ++this.m_maxUserId;
            string stringId = this.m_maxUserId.ToString();

            System.Threading.Thread.Sleep(1000);
            RedisDBManager.GetDatabase().StringSet(MAX_USER_ID_KEY, stringId);
            user.ID = this.m_maxUserId;
            RedisDBManager.GetDatabase().StringSet(USERS_KEY_PREFIX + stringId, JsonConvert.SerializeObject(
                                                       user,
                                                       Formatting.Indented,
                                                       new JsonSerializerSettings
            {
                ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            }));
            return(this.m_maxUserId);
        }
Esempio n. 3
0
        public User GetUserById(int id)
        {
            var redisObject = RedisDBManager.GetDatabase().StringGet(USERS_KEY_PREFIX + id.ToString());

            if (redisObject.HasValue)
            {
                return(JsonConvert.DeserializeObject <User>(
                           redisObject,
                           new JsonSerializerSettings {
                    ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                }));
            }
            else
            {
                return(null);
            }
        }