Redis Losing Data When doing an Add Operation

66 views
Skip to first unread message

Mohammad Habbab

unread,
Sep 22, 2012, 4:30:18 AM9/22/12
to servic...@googlegroups.com
  Code:
            var Objects_key = AssembleKey_CommentObjects(streamId);
            var PublicEvents_key = AssembleKey_PublicEventstream(streamId);
            var Lock_key = AssembleKey_StreamLock(streamId);
            var PrivateEvents_key = AssembleKey_ParticipantEventStream(streamUserId,streamId);
            var Ids_key = AssembleKey_CommentIds(streamId);
           
            using (cacheClient.AcquireLock(Lock_key))
            {
                var tempclient = cacheClient.GetTypedClient<Comment>();
                long time_score = streamObject.CreationTime.Value.Ticks;
                tempclient.Sets[Objects_key].Add(streamObject);
                cacheClient.Sets[Ids_key].Add(streamObject.Id);
                string event_message = "Added:" + streamObject.Id;
                cacheClient.AddItemToSortedSet(PublicEvents_key, event_message, time_score);
                cacheClient.AddItemToSortedSet(PrivateEvents_key, event_message, time_score);
            }
            if (OnStreamWriteSuccess != null)
                OnStreamWriteSuccess(streamId, streamUserId, streamObject);

The code above is accessed by multiple clients on multiple threads. however the operations are serialized in the lock-surrounding section. For reason that i'm not aware of, the Set Operation sometimes while adding removes the set , if it was already there, all together, and other times it just does the add operation as it's intended to be.
Extra Info:
 1- The class containing this code is initialized with a client [CacheClient] that it gets from a PooledRedisClientManager or a BasicRedisClientManager [the problem occurs on both]. and the class implements the IDisposable interface where it disposes the connection.
 2- The App has a Singletone IRedisClientManager (which was mentioned in point-1) which provides a GetClient() call which is called on this class initialization.
 

Mohammad Habbab

unread,
Sep 22, 2012, 12:06:48 PM9/22/12
to servic...@googlegroups.com
Sorry .. The problem seemed to be cause by ExpireIn() API and the ExpireAt() API.. whenever i try to re-new the expiration period of a set of keys, the ExpireAt() and ExpireIn() functions return false.. is there any work around for this ?
The following code is the code i use to refresh my keys

            var Objects_key = AssembleKey_CommentObjects(streamId);
            var PublicEventStream_key = AssembleKey_PublicEventstream(streamId);
            var Ids_key = AssembleKey_CommentIds(streamId);
            var PrivateEventStream_key = AssembleKey_ParticipantEventStream(authenticationToken, streamId);
            var Marker_key = AssembleKey_EventStreamMarker(authenticationToken, streamId);

            if (cacheClient.ContainsKey(Objects_key))
            {
                var result = cacheClient.ExpireEntryIn(Objects_key, DefaultTimeOut); //this returns false after first time being set, so no renewal
                var timeToLive = cacheClient.GetTimeToLive(Objects_key);
            }
            if(cacheClient.ContainsKey(PublicEventStream_key))
                cacheClient.ExpireEntryIn(PublicEventStream_key, DefaultTimeOut);

            if(cacheClient.ContainsKey(Ids_key))
                cacheClient.ExpireEntryIn(Ids_key, DefaultTimeOut);

            if(cacheClient.ContainsKey(PrivateEventStream_key))
                cacheClient.ExpireEntryIn(PrivateEventStream_key, DefaultTimeOut);

            if(cacheClient.ContainsKey(Marker_key))
                cacheClient.ExpireEntryIn(Marker_key, DefaultTimeOut);
Reply all
Reply to author
Forward
0 new messages