Skip to content

Redis 3.2 add CAS API for string type's storage#3772

Closed
LeechanX wants to merge 2 commits intoredis:3.2from
LeechanX:3.2
Closed

Redis 3.2 add CAS API for string type's storage#3772
LeechanX wants to merge 2 commits intoredis:3.2from
LeechanX:3.2

Conversation

@LeechanX
Copy link

@LeechanX LeechanX commented Jan 23, 2017

Hello Antirez, I add the lockless programming CAS API for string type's storage.

The reason why I add CAS API is: I know Redis can implement CAS operations by using WATCH and MULTI; But many business always package Redis server, for example, using a proxy to access Redis, in this scenario, WATCH and MULTI is hard to use. So I added the CAS API for string type storage.

How I implemented CAS API for string type:
I introduced three APIs:

getcas key
return version and value
setcas

setcas key value version
if key is not exist, version must = 0; otherwise setcas will be failed
if key is exist, version must = cas version in key storage, otherwise setcas will be failed
delcas

delcas key
return version and value

For string type:
when encoding = INT or EMBSTR, rasing INT to RAW, then appending cas version to sds->buf;
when encoding = RAW, appending cas version to sds->buf;

By this easy way, my CAS API supported RDB\AOF\master-slave model\cluster model easily.
I have test my API successfully.

So can you share your idea or give me some advise?

@LeechanX
Copy link
Author

maybe my content is hard to understand , cause my english is not that good...

@LeechanX LeechanX changed the title Redis 3.2 add CAS API for string type Redis 3.2 add CAS API for string type's storage Jan 23, 2017
@itamarhaber
Copy link
Member

itamarhaber commented Jan 23, 2017

Two notes:

  1. I would begin by implementing using server-side Lua scripts
  2. If Lua proves to be too slow (which I find hard to believe since the logic is simple), I would continue by implementing this as a Redis module for v4 and greater

;)

@LeechanX
Copy link
Author

Thanks for your advise,handsome haber. But I wanna know what the shotcoming of my implemention?

@itamarhaber
Copy link
Member

/me blush

I have not reviewed your implementation, but in order to use it it will have to be merged into the core. This may not or may happen. With Lua/Modules, you don't have to wait.

@itamarhaber itamarhaber mentioned this pull request Jan 19, 2021
@LeechanX LeechanX closed this by deleting the head repository May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants