WenboR / redis

Automatically exported from code.google.com/p/redis
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[FEATURE REQUEST]HMSETX/HSETX #655

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using redis as a cache server, and storing some datas in hashes(usually 
contains thousands of items). 

For instance, a user has many friends, we can cache all his/her friends in a 
key, like: 
    uid:xxx:friends -> {'friend1': '...', 'friend2': '...', ...}

There're two general requests:
1. list all friends
    val = redis.hgetall(key)
    if not val:
        val = database.get(key)

2. modify or add friend
    friend = redis.hget(key, 'friend1')    # 1
    friend = ...                                      
    if database.save(key, 'friend1', friend):
        redis.hset(key, 'friend1', friend)       # 2

What will happen if the key is discarded(maxmemory reached) between #1 and #2? 
The result is, only one item "friend1" would remain in that key.  All the 
following "list all friends" requests will get only one friend because the key 
still exists.

HSETX/HMSETX(hset/hmset if the KEY exists) can solve this problem perfectly.

PS: maybe HXSET/HXMSET are better names?

Original issue reported on code.google.com by timium.z...@gmail.com on 6 Sep 2011 at 3:34

GoogleCodeExporter commented 9 years ago
Redis scripting can address this very simply and easily. I believe there is a 
scripting branch on Redis 2.2, or you can wait for 2.4 to come out soon.

Original comment by josiah.c...@gmail.com on 6 Sep 2011 at 8:00

GoogleCodeExporter commented 9 years ago
Is there any documentation about redis scripting?

Original comment by timium.z...@gmail.com on 7 Sep 2011 at 1:52

GoogleCodeExporter commented 9 years ago
I'm not seeing docs up on the standard redis.io site, but I there are some 
older blog posts by Antirez on his blog, most recently a couple posts here: 
http://antirez.com/index.php?start=3

Original comment by josiah.c...@gmail.com on 8 Sep 2011 at 12:53