Redis CRUD operations.

1,131 views
Skip to first unread message

Mahernoz Daruwala

unread,
Dec 15, 2014, 9:45:11 AM12/15/14
to redi...@googlegroups.com
Hello,

I am looking to replicate an sql database and storing in redis server. Which i did that in string datatype. My id is like {urn:tablename:Id} and data is in json format which is taken from sql server database. 

Now, I am looking towards getting the CRUD operations for my application needs. 

GetByID
GetAll
Insert
Update
Delete
GetByColumnNameOtherThanID

I was able to get all these operations but only one operation is now pending GetByColumnNameOtherThanID. (not getting the exact redis command)
I am using NServiceKit.Redis as my c# client which is clone of ServiceStack.Redis. 

I want to know how to implement this funcitonality in strings datatype. If this is not possible in string datatype then which datatype to use and please guide me regarding the commands to be used if some other datatype instead of strings is to be followed.

- Mahernoz Daruwala 
  

Josiah Carlson

unread,
Dec 15, 2014, 4:39:50 PM12/15/14
to redi...@googlegroups.com
There does not exist a pre-existing datatype that builds indexes for you, so you would have build your own secondary indexes to query by other (logical) columns in your json-encoded data.

The only built-in behavior (with respect to your 6 CRUD operations) is the Redis equivalent of GetByID, which we call GET (but you'd still need to decode the json). Everything else you will need to implement yourself. I would suggest checking out Redis' built-in Lua scripting to limit/eliminate race conditions, depending on the semantics of the operations you want to perform.

On the indexing side of things, chapter 7 of Redis in Action[1] covers almost everything you might want to know about indexing with Redis.

 - Josiah



--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Mahernoz Daruwala

unread,
Dec 18, 2014, 5:08:44 AM12/18/14
to redi...@googlegroups.com
Okay, so that means, i have to implement my own non-clustered index functionality in redis as the same as MsSql. am i right?
But another problem is MsSql nonclustered indexes are logical tables internally and in redis i have to create physical tables to make nonclustered indexes. 

- Mahernoz

Josiah Carlson

unread,
Dec 18, 2014, 12:35:51 PM12/18/14
to redi...@googlegroups.com
If you want full CRUD behavior in Redis, yes you will have to build your own indexing functionality. That is what I said in my earlier reply, and it is still true.

That said, Redis itself doesn't have a "table" or "index" data type. Redis has data structures. You can build logical ideas on top of the data structures like "tables" and "indexes", but Redis doesn't include a "table" or "index" datatype.

Is there a reason why you want to do this? Because for many (perhaps most) use-cases, you will likely be better served by using pre-existing tools on top of a pre-existing relational database engine. Clustered indexes may not make sense, but a regular non-covering index may be sufficient. Or maybe using Tokutek's MySQL/MariaDB backend gets you a viable clustered index (if you want it).

I ask "why" because I have built a Redis object mapper for Python[1], and I can assure you that indexes, queries, data cleanup (deletion), and everything else can be challenging to get right even when you have experience.

 - Josiah


* And ordered indexes beyond the precision of a C double requires substantially more thought in constructing the index entries and index queries than most people realize.
Reply all
Reply to author
Forward
0 new messages