ruby - Using Redis to store array of hashes -


i have started @ redis , able store array of hashes, can pop random key/value out , put in when need to.

so in ruby have this

users = [{ username: "user1", password: "password"}, { username: "user2", password: 'password'}] 

so if wanted random key/value object array this

@user = users.shuffle!.pop 

and put array

users.push(@user) 

the idea using redis have 2 processes (ruby based app) need share pool of users @ same time. once process has finished user want put pool.

could point me in right direction please

thanks

you redis hash store user info , redis set store these hashes together.

steps:

  1. make redis hash hset command:hmset userid_653 username "tom" password "gd36e3hd38d3jdj3yd3hd38"
  2. add hash in set called users: sadd users userid_653. set contains users.
  3. get random user key set: srandom users. return userid_653
  4. get corresponding values hash using hget userid_653 username
  5. if need pop key spop userid_653 after step 3. , sadd again after processing in step 4.

a similar question better understanding: redis how store associative array

references:

ps: have no experience in ruby. suitable redis ruby api support these operations!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -