开发者

Ruby Memcached maninuplating stored data

I am storing an array in memcached (see below)

Cache.set 'an_array', [1,2,3,4,5.....N]

I need to pop one value from the array and update the array in Cache again

arr = Cache.get 'an_array'
val = arr.pop
Cache.set 'an_array', arr

Is there a direct way I can pop the value from array stored in Cache and the array get updated automatically? Actually the array to be stored is very huge and it will be very costly to first fetch the array, pop the value and then do a Cache.set with updated array.

Thanks,

Im开发者_StackOverflow社区ran


I don't believe there is an in-built version of pop command available in memcached. According to the wiki only these commands available

      o Standard Protocol
            + No Reply
      o Storage Commands
            + set
            + add
            + replace
            + append
            + prepend
            + cas
      o Retrieval Commands
            + get
            + gets
      o delete
      o incr/decr
      o Statistics
            + stats
            + stats items
            + stats slabs
            + stats sizes
      o flush_all

Update:

If you are starting and looking for other options. i would highly recommend redis for your case. It provides higher set of commands over memcached.

For example, you can pop the value from redis array in multiple ways.

  • LPOP
  • RPOP
  • BLPOP
  • BRPOP
  • SPOP

Check out the whole set of redis commands here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜