0

I am brand new to redis so I have a number of questions regarding the setbit function.

I have a dataset of the following type:

{'items':[{'item_1':0001...1000,
           ...
           'item_n':0011...0011}
         ]
}

In each item there are 10's of thousands of bits and there are hundreds of thousands of items. It seems that I can use the following to set the items:

Redis.setbit('item1', 0, 0)
Redis.setbit('item1', 1, 0)
Redis.setbit('item1', 2, 0)
Redis.setbit('item1', 3, 1)
...
  • However this seems horribly inefficient. Is there anyway to set all of the bits at once?
  • Is there someway that I can group these into a set or a hash so I can lookup what items are currently set? They change on a daily basis and I need to know what was previously written so I can analyze and delete it accordingly.
  • How can I look up the names of the previously written items?
user2694306
  • 3,832
  • 10
  • 47
  • 95

1 Answers1

2
  • No and yes. SETBIT (as its name suggests) sets a single bit. However, since Redis uses the string data type to store bits, you can construct the relevant item string in your app and then just SET it in one fell stroke. More information about the internal representation of bits in strings is at Can someone explain redis setbit command?.

  • To keep track items you've written to and look them up, Redis' sets should do the trick nicely. SADD your items to a key (possibly named according to the date) and to fetch use SSCAN.

Community
  • 1
  • 1
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117