I have a patch I'd like to contribute, if you guys would like. This 
adds a new feature; I'm not sure if this conflicts with other 
development or sort of steps on other functionality but let me give 
you the background and what I did. 
For an e-commerce site I'm working on we needed a solution for fast server-side carts. After looking at a few options Redis made the most sense. We brought up a Redis server (as well as a slave, for replication) and store carts as a session ID mapping to a hash object (i.e. HSET and HGET).
To eliminate cruft from abandoned carts I used EXPIRE so that old carts will idle away after some generous amount of time. I realized that changes to a hash that's set to EXPIRE will actually eliminate all items in the cart, due to EXPIRE semantics. I worked around it with a complete hash read + rewrite with new data, followed by a new EXPIRE.
That works (it's in production now) but the reading, deleting, re- writing, and EXPIRE-ing might get costly. I added a new function "IDLE" that's similar but allows changing of something that's set to IDLE without destroying all the state. Things that are idle and untouched (read, written to) get deleted like the EXPIREd items do.
This doesn't address all the issues as I saw discussed previously on the FAQ about updating items set to EXPIRE, namely the ones concerning replication and replays from the binary log. Regardless I see more grumblings from people wanting to change EXPIRE-ing stuff than people concerned with those (indeed, legitimate) issues. So I'd like to release this in the hopes the community finds this useful. (Perhaps a warning, in documentation form or a message spit out at runtime, would help prevent ill effects.)
I hope you guys find this patch useful. This was written as part of my usual job at Sony Music Entertainment, supporting stores on www.sonymusicdigital.com. I just got consent to release this little bit of code to the BSD-licensed project.
My gmail account (in case that's necessary for me to add files under the project in Google Code) is:
I can be contacted there if you have any further questions.
Thanks for creating Redis! I hope this contribution is at least partial payback. :)
Steve O'Brien's gravatar image asked Jul 26 2010 at 12:55 in Redis-Db by Steve O'Brien

4 Answers

Hello Steve, thank you for your patch and the nice write up of your use case. In this days I'm fixing the problem in Redis master in a definitive way, that is allowing writes against expiring keys but without violating consistency.
This should solve all the issues, I'm working on this currently so I expect this to be available in one week more or less.
Cheers, Salvatore
Salvatore Sanfilippo's gravatar image answered Jul 27 2010 at 01:31 by Salvatore Sanfilippo
Looking forward to this change! I've always found EXPIRE counterintuitive, great news.
Alan Kennedy's gravatar image answered Jul 27 2010 at 02:06 by Alan Kennedy
Steve, Salvatore, Thanks, I am down on my knees with tears in my eyes, you can't imagine how this is going to take away on of two pains taht I suffer with Redis (everyhing else is A1)
Looking forward for the new version.
I proposed a while ago a similar KEEP_UNTIL command, but as you can see Salvatore's plans point more to the core.
By the way, heavily testing latest RC with _heavy_ use of more or less all the structures, and it has been working like a charm.
Thanks a lot for such excellent code,
-- Anbal Rojas Ruby on Rails Web Developer http://www.google.com/profiles/anibalrojas
Anbal Rojas's gravatar image answered Jul 27 2010 at 05:42 by Anbal Rojas
Excellent! Then we'll be looking out for this new EXPIRE functionality and keep our code as before (do a read/write on the hash, and set EXPIRE again). Actually, will it be so that EXPIRE can be set on an already-EXPIRE'd object? We'd need that to keep the "idle" functionality -- where something that hasn't been read/written goes away (there's a "moving" expiration date, not just a single point set at creation time).
2010/7/27 Anbal Rojas
Steve O'Brien's gravatar image answered Jul 27 2010 at 07:35 by Steve O'Brien

Related Discussions

  • Redis Gui Client What Functionality You Want? in Redis-db

  • Hello friend, i am started develop FastoRedis gui crossplatform client for Redis. This client based on redis-cli, all functionality of redis-cli you may use in Fastoredis, also i implement base functionality for application for with connection, you may connect more than one server, disconect, execute some comands in async mode, some information about server, database list, but now i don't have any...

  • FastoRedis (Redis Gui Client) What Functionality You Want? in Redis-db

  • Hello friend, we release FastoRedis gui crossplatform client for Redis. This client based on redis-cli, all functionality of redis-cli you may use in Fastoredis, you may connect more than one server also support ssh connection, execute some comands in async mode, some information about server, database list, usefull grafics about server and more other things.If this solution iteresting for you, please...

  • How To Support GC Like Functionality In Redis in Redis-db

  • I want to implement a garbage collector like feature for my application which uses redis db. I am using sets, sorted sets, lists and hashes of redis to store my data. I have a real time app which is inserting/updating contents in redis. I want to cleanup selective data from those structures based on few conditions without stopping my real time application which is inserting /updating values. ...

  • [redis-db] Better ZRANGE Functionality / Scoreboard in Redis-db

  • This could be a repeat of a post i did that didnt show up, i'm new to google groups. I have a need to have a scoreboard type functionality, where people have points added as they do specific things, but its possible for the points to show a tie. I know that redis uses a lexicographic sorting order when there is a tie, but that would not work for me. What i need is to be able to discriminate...

  • Monitor Functionality in Redis-db

  • I've noticed a bug in redis-cli. I didn't find github issues for this. I'm working on a redis console and would like it's input/output to function similar to redis-cli. how to reproduce: $ redis-cli redis> MULTI OK redis> MONITOR QUEUED QUIT uh oh... [can't do anything else really but server sees commands] ^C In contrast, if I run this from my script (with...

  • Additional Functionality in Redis-db

  • Hello! Our company would like to have some more functional to monitor the state and settings optimization of redis, for example: 1. On INFO command wed like to see the the value of the variable maxmemory even if it values 0. 2. in case of turning on vm mode, wed like to see the amount of the keys, values of which are taken from the memory or from swap (hit and miss). We added this functional...

  • Related To Expire Callback Functionality in Redis-db

  • Hi concerning the expire callback functionality here: http://www.google.com/url?sa=D&q=http://code.google.com/p/redis/issues/detail%3Fid%3D360&usg=AFQjCNEkNi2otHWAqMUzwjTZGWnxRNyi-Q and here: http://groups.google.com/group/redis-db/browse_thread/thread/1311ebbbaaf09c39 This is a killer feature (think auto-archiving, reminder functionality, reoccurring published messages, etc.). I think...

  • SETNX Should Have Functionality To Clear The Key On Disconnect in Redis-db

  • Hello, I recently made up a patch for SETNX and added a third optional param (see https://github.com/0x20h/redis/compare/2.6...setnx-delete-on-disconnect). Providing this param will register KEY to be automatically deleted when the client disconnects, given KEY was set successfully. This feature would adapt the semantics of mysql's get_lock functionality (named locks acquired by get_lock will...

  • Replication Of Master/Slave And Pub/sub Functionality in Redis-db

  • Do pub/sub commands also get replicated on slaves? What is the general latency between a new command occurring on a master and then propagating to slaves?...

  • Proposal: New Function (moddelete) And Scripts To Add Nodes W/o Losing Data in Redis-db

  • HI Salvatore and Pieter, I wrote a new redis function "moddelete num modulo" in http://allinram.info/redis/cluster/redis.c which deletes all entries NOT matching (crc32(key)%modulo == num) The idea is if you split a redis-server in half, you want to delete different halves of the entries from each of the new redis-servers. and if you then split the 2 redis-servers into 4 redis-servers, you...