Raabb Ajam
Raabb Ajam

Reputation: 35

Redis atomic transaction to search by intersectioning set and use returned data to update

Redis experts, I want to search idle data by certain type resource and then mark it as not idle, all in one command (atomic).

I am using redis to keep tab of active resources with different type. How should I approach this problem of mine, I need to get hash data by querying some field values, which I've created their own set and using sinter and then update it to flag it as in use. This is reference how to filtering in redis using set http://robots.thoughtbot.com/redis-set-intersection-using-sets-to-filter-data

Let's say I want to find the id of one idle resource with type X and attribute A, I query it by using intersect on type set and attribute A. Using command SINTER S:type:X S:attribute:A S:active:false. Say it return id of resource #400, I want to use this number to hgetall and update it so active become true, (HGETALL S:resource:400).

And I need it to be atomic. Right now I'm still trying to do this in multi/exec. Please advice if there is easier way.

Upvotes: 0

Views: 185

Answers (1)

Larry Lopez
Larry Lopez

Reputation: 26

use LUA scripting. It's a scripting language that Redis uses. You can load the script into Redis and it will execute the script atomically. Lookup the EVAL, SCRIPT LOAD, and EVALSHA commands of redis and search "lua script redis" on google.

Upvotes: 1

Related Questions