Remove element at specific index from redis list
So the only way to accomplish what I wanted was to set the value at the index to a pre determined string and then do an removal by value.
see discussion here https://groups.google.com/forum/#!topic/redis-db/c-IpJ0YWa9I
in ruby as follows
@redis.lset("#{@namespace}/#{specified_queue}", index, "DELETED")
@redis.lrem("#{@namespace}/#{specified_queue}", 1, "DELETED")
LSET docs http://redis.io/commands/lset
LREM docs http://redis.io/commands/lrem
How to remove element from list in Redis by value?
http://redis.io/commands/lrem
Lrem is what you are looking for. use LREM POST:544 1 36.
Delete all entries in a Redis list
Delete the key, and that will clear all items. Not having the list at all is similar to not having any items in it. Redis will not throw any exceptions when you try to access a non-existent key.
DEL key
Here's some console logs.
redis> KEYS *
(empty list or set)
redis> LPUSH names John
(integer) 1
redis> LPUSH names Mary
(integer) 2
redis> LPUSH names Alice
(integer) 3
redis> LLEN names
(integer) 3
redis> LRANGE names 0 2
1) "Alice"
2) "Mary"
3) "John"
redis> DEL names
(integer) 1
redis> LLEN names
(integer) 0
redis> LRANGE names 0 2
(empty list or set)
How to delete object Redis list item?
Do you have control over the code that inserts the JSON? If so, you'll need to make sure they generate the same strings. LREM requires an exact match to work. That said, you might want to consider a different data structure or maybe a combination of data structures.
One option is that you could store the JSON as a String and then the List could contain the keys to those Strings. Then, when you delete a comment, you call LREM to remove it from the List and UNLINK or DEL to remove the JSON. The List serves to store an ordered index of the comments. The comments themselves are each stored in a String.
If you can use RedisJSON, you could just store a JSON document with an array of the comments. That would give you ordered data and the data itself and then you could delete a particular comment using JSON.DEL and JSONPath.
Related Topics
How to Store a Ruby Array into a File
Access Localhost on MAC from Xcode? Phonegap Communicating with Ajax to a Local Rails App
Gem Install Dm-Postgres-Adapter Build Error
Failing to Bundle Install Tiny_Tds on MAC Os X 10.8 with Homebrew Freetds
Killing Process Group from Ruby Kills My Whole Computer
Phonegap and Rails 3: How to Interact with a Rails 3 App
Distributing Rails Applications as Native Applications
"Error: Sql.H Not Found" When Installing Ruby-Odbc Gem on Ubuntu
What's The Impact of Eager_Load=True
Passing Local Variables to a View from Controller
How to Find .Index of a Multidimensional Array
Turn a Ruby Hash into HTML List
"Ruby.Exe Is Not Recognized as an Internal or External Command" in Windows 7
Thin Doesn't Respond to Sigint or Sigterm
Preventing Delayed_Job Background Jobs from Consuming Too Much CPU on a Single Server