How to get index of latest element in List Redis? - redis

How to get index of latest element in List Redis?
For example in List is stored id's of messages, I need get last ID message and return index this element.

In Redis, the index -1 always refers to the last element in a LIST
This is a much better idea that trying to find the index from the start of the list (LLEN would be the way to get this), because if someone inserts or removes an item after you get the index but before you access the element, something's gonna break.
To get the last element of a Redis list, you can use the LINDEX key -1 command. You can also atomically remove the last element of a list with the LPOP key command.
Documentation for all of the Redis commands can be found at http://redis.io/commands.

To get the last element you can also use:
lrange mylist -1 -1

Related

How delete Item from ArrayList in Firestore using Koltin

I want to delete one item from the animeId. For example, if I need to remove the animeId[5] or I want to remove the item that the value is equal 5114, how can I do that? I alredy learned how I remove item like the entire animeIdbut not just one item.
Here's an print how the database is organized:
For updating some fields of a document, use the update() method.
If you want to remove a specific item from an Arraylist, you can use a call to:
.update("arrayfield", FieldValue.arrayRemove("itemtoremove"))
For example if you have an arraylist that contains three items as “abc”, “efg”, “xyz”.
And if you want to remove specific item called “efg” from an arraylist you should use a call to:
.update("arrayfield", FieldValue.arrayRemove("efg"))
Please also take a look at this Stackoverflow Link which explains clearly on
how to remove specific items from the array list in the firestore using kotlin.

Retrieving data from multiple-page API using Talend

I have an API with 59 pages, on each page 1000 rows of data. I would like to retrieve all that data and store it in a Microsoft SQL Server.
When I use tloop with a condition run until i<59, it returns the first 1000 rows of data 59 times which is clearly not what I need.
I have tried to create a global variable next_page but I do not know how to connect it to the next_page present in the API, so that when "next_page"="" the program will know to break the loop.
I had a similar case (difference is that I didn't have a "nextPage" element but a "nextLink" which was giving me the complete URL to get to the nextPage).
I created a globalvariable "endJob" with value "false" at the beginning (tJava right before tLoop)
My tLoop is from int i=1, iteration is i++ , condition is !endJob (thus it will loop as long as the job is not marked as ended).
In a tJava right after tLoop, create the URL for your API request, using your page number, which is the tLoop_1_CURRENT_ITERATION
Then after my tRestClient, I put a tReplicate : first flow is for your needed transformations, the other one retrieve only the "nextPage" item. If nextPage is empty, then you update "endJob" variable to "true" : you want to stop the loop.

Token to the next page in pagination API

I have a list of records on the server sorted by a key and use pagination API to return list of segments one by one. Since items can be inserted in the middle of the list, I return the first key of the next page as a pagination token that has to be passed to get the next page.
However, I've found that DynamoDB uses the last key of the current page instead for querying API, which is null if the next page does not exist.
Question:
What are pros and cons between using the last item of the current page and the first item of the next page as a pagination token?
N.B:
As for me returning the first item is more intuitive since it's null only if the next page does not exist.
Using the "last item of the current page" (LICP) is better than using the "first item of the next page" (FINP) because it deals better with the possibility that, in the meantime, some item is inserted between these two items.
For example suppose the first page contains 3 alphabetically ordered names: Adam/Basil/Claude. And suppose the next page is Elon/Francis/Gilbert.
Then with LICP the token is Claude, while with FINP the token is Elon. If no new names are inserted, the result is the same when we get the next page.
However, suppose we insert the name Daniel after getting the first page but before getting the second page. In this case, when we get the second page with LICP we get Daniel/Elon/Francis, while with FINP we get Elon/Francis/Gilbert. That is to say, FINP will miss Daniel, while LICP will not.
Also, FINP may consume more computing resources than LICP, since you must retrieve one extra item (4 items, in the above example, instead of only 3).

remove duplicate VB.NET TreeVeiw node

any hint on how to add only one node to TreeVeiw control while many nodes with same name found in access database field ?
I can loop through the field but all the values add to TreeNode which is why i wanted to remove the duplicate.
Loop through the items and store them in an array while doing so.
If the current item in the loop, already exists in the array => duplicate => remove
You could try that, good luck.

What is the proper way to set and update the contents of a field on a node in Drupal 7?

I've written a Drupal 7 module that creates a custom node type. I've added a number_integer field to the node, to act as a counter. How do I set the counter field to default to zero, when a node gets created?
Next, while processing the node, I need to increase the value of the counter by one and save the new value. Do I do that by altering the $node object and then calling node_save? Or is there a better way, using the Field API or something?
I still would not really dare to save back a node just like that. I would still use
$form_state = array('values' => array());
drupal_form_submit('story_node_form', $form_state, $node);
much like we did in Drupal 6 (just with slightly different syntax).