How to Convert LocalDateTime to Long Timestamp in Java
When working with dates and times in Java, you may often need to convert a LocalDateTime object into a long timestamp, typically representing the number of milliseconds or seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). This can be useful for database operations, APIs, or any scenario requiring a numerical representation of date and time. Step-by-Step Conversion ProcessJava’s LocalDateTime is a part of the java.time package introduced in Java 8. Since LocalDateTime is time-zone...
Introduction to Redis Bitmaps
Bitmaps are not an actual data type, but a set of bit-oriented operations defined on the String type which is treated like a bit vector. Since strings are binary safe blobs and their maximum length is 512 MB, they are suitable to set up to 2^32 different bits. You can perform bitwise operations on one or more strings. Some examples of bitmap use cases include: Efficient set representations for cases where the members of a set correspond to the integers 0-N. Object permissions, where each...
How to Install Node JS Latest Long-Term Support Version on Ubuntu 22.04?
Node.js is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts. Node.js is a powerful JavaScript runtime that lets you build scalable and high-performance applications. With the release of Node.js v22, developers now have access to new features, improvements, and bug fixes. This article will guide you step-by-step on how to install Node.js v22 on Ubuntu 22.04. Step 1: Update Your Package...
Redis HyperLogLog PFSELFTEST Command
SyntaxThe basic syntax of the PFSELFTEST command is as follows: 1PFSELFTEST The PFSELFTEST command is an internal command. It is meant to be used for developing and testing Redis. Available SinceVersion 2.8.9 or later. Time ComplexityN/A ACL Categories@hyperloglog, @admin, @slow, @dangerous Return ValueReturns OK. Example1234127.0.0.1:6379> PFSELFTESTOK(0.53s)127.0.0.1:6379>
Redis HyperLogLog PFDEBUG Command
SyntaxThe basic syntax of the PFDEBUG command is as follows: 1PFDEBUG subcommand key The PFDEBUG command is an internal command. It is meant to be used for developing and testing Redis. Available SinceVersion 2.8.9 or later. Time ComplexityN/A ACL Categories@write, @hyperloglog, @admin, @slow, @dangerous
Redis HyperLogLog PFMERGE Command
The Redis PFMERGE command merges multiple HyperLogLogs into a single HyperLogLog. The cardinality estimate of the resulting HyperLogLog is calculated by taking the union of all the given HyperLogLogs. SyntaxThe basic syntax of the PFMERGE command is as follows: 1PFMERGE destkey [sourcekey [sourcekey ...]] The command merges multiple HyperLogLog values to approximate the cardinality of the union of the observed sets. The result is stored in a destination variable, which is created if it...
How to Install Redis on Ubuntu Using the APT Command
Redis is a popular, open-source, in-memory data structure store used as a database, cache, and message broker. Installing Redis on Ubuntu is straightforward, thanks to the Advanced Package Tool (APT), which simplifies installing software on Debian-based Linux systems like Ubuntu. Here’s a step-by-step guide on how to install Redis using APT. Step 1: Update Your SystemBefore installing any new software, it’s good practice to update your package lists to ensure you have the latest versions...
Redis HyperLogLog PFCOUNT Command
The Redis PFCOUNT command returns the cardinality estimate of the given HyperLogLog. SyntaxThe basic syntax of the PFCOUNT command is as follows: 1PFCOUNT key [key ...] Available SinceRedis version 2.8.9 and later. Time Complexity O(1) when called with a single key. O(N) when called with multiple keys, where N is the number of keys. ACL Categories@read, @hyperloglog, @slow Return ValueAn integer representing the cardinality of the given HyperLogLog. If multiple HyperLogLogs are provided,...
How to Fix `java.lang.NoSuchMethodError: org.apache.commons.cli.CommandLine.hasOption` in Apache Flink
When running Apache Flink, you might encounter the following error message during startup or execution: 1java.lang.NoSuchMethodError: org.apache.commons.cli.CommandLine.hasOption For example, when I use Flink version 1.17.2 and start a job in Application Mode, the job is submitted successfully and runs as expected. The command and output information are as follows. 1234567891011121314151617$ /data/flink/flink-1.17.2/bin/flink run-application -t yarn-application -p 3...
Redis HyperLogLog PFADD Command
The PFADD command in Redis adds one or more elements to a HyperLogLog data structure. SyntaxThe basic syntax for the PFADD command is as follows: 1PFADD key [element [element ...]] This command adds all the specified elements to the HyperLogLog data structure stored at the key provided as the first argument. Available SinceRedis version 2.8.9 and later. Time ComplexityO(1) to add every element. ACL Categories@write, @hyperloglog, @fast Return ValueReturns an integer: 1 if at least one...
Redis HyperLogLog
HyperLogLog is a probabilistic data structure used to estimate the cardinality of a set. As a probabilistic data structure, HyperLogLog trades perfect accuracy for efficient space utilization. Redis added the HyperLogLog data structure in version 2.8.9. HyperLogLog in Redis is an algorithm used for cardinality estimation. Its main advantage is that, even when the number of input elements is extremely large, the memory required to calculate the cardinality remains fixed and small. In Redis,...
How to Resolve the "Could Not Get Lock /var/lib/apt/lists/lock" Error in Ubuntu
When using Ubuntu or any Debian-based system, you may come across the error message: “Could not get lock /var/lib/apt/lists/lock.” This is a common issue, particularly when managing software installations or updates via apt or similar commands. For example, I recently encountered this error while trying to install an application using the apt command on Ubuntu: 12345$ sudo apt updateReading package lists... DoneE: Could not get lock /var/lib/apt/lists/lock. It is held by process 1390...
Resolving the "TTransportException" Error in Superset Hive Database Connection
Issue Description:After successfully installing Superset, running the command superset run -p 8088 -h 0.0.0.0 to start the application, and attempting to configure the Hive database connection through the interface, an error occurs. The server logs display the following: 123Unexpected error TTransportExceptionWARNING: superset.views.core: Unexpected error TTransportExceptionINFO: werkzeug:10.10.17.34 - - [11/Jan/2022 12:07:37] "POST /superset/testconn HTTP/1.1" 400 - Upon seeing...
Running Multiple Pipelines in Apache Flink: Separate Jobs vs. Single Job with Multiple Pipelines
When it comes to building data processing flows in Apache Flink, there are times you might want to run multiple independent pipelines, ideally sharing resources for efficiency. Here, we explore two common approaches to achieve this and provide a practical guide to help decide which one best suits your use case. Imagine you have two independent flows that look like this: Flow 1: Source1 -> operator1 -> Sink1 Flow 2: Source2 -> operator2 -> Sink2 The goal is to use a single...
Redis Set SADD Command
The Redis SADD command adds one or more member elements to a set. If an element already exists in the set, it will be ignored. If the set key does not exist, a new set is created with the added elements as its members. If the key is not of the set type, an error is returned. Note: In Redis version 2.4 and earlier, the SADD command only accepts a single member value. SyntaxThe basic syntax of the SADD command is as follows: 1SADD key member [member ...] Available SinceRedis version >=...
Bulk Deleting Keys in Redis Using Wildcards
Be Cautious with the KEYS Command in Production: Commands like KEYS, FLUSHALL, and FLUSHDB can block Redis when working with large datasets. They may scan the entire keyspace, potentially locking up Redis and degrading performance. Redis currently does not support bulk deletion of keys using wildcards. However, we can achieve this using the del command in combination with Linux pipes and the xargs command. The del command in Redis allows you to delete one or more specified keys...
Analyzing Redis Source Code: The Structure and Design of Hash Tables, Chained Hashing, and Incremental Rehashing
Redis offers a classic implementation of hash tables. To handle hash collisions, Redis employs chained hashing, which links data with the same hash value in a list rather than expanding the table. This ensures that all data remains accessible within the hash table. To minimize the performance impact of rehashing, Redis uses a incremental rehashing strategy, which distributes the workload of rehashing over time to reduce system overhead. In this article, I’ll guide you through the core...
Analyzing Redis Source Code: Simple Dynamic Strings (SDS) – An Efficient and Flexible String Implementation
Redis’s Requirements for StringsStrings are an essential data type in app development, frequently used to store a variety of information such as user profiles, product descriptions, and system messages. In Redis, a popular in-memory data store, both the keys and often the values in key-value pairs are represented as strings. This makes strings one of the foundational data types in Redis, contributing to its flexibility and simplicity when handling data. For instance, when saving user data...
Why Does Redis Use the SDS Structure for Strings Instead of char*?
Redis, known for its performance and efficiency, uses a data structure called SDS (Simple Dynamic String) for handling strings in its key-value pairs rather than the traditional C string (char*). Understanding why this decision was made requires a look into both how Redis operates and the limitations of the C string. What is char* (C String)?In C, strings are represented as arrays of characters terminated by a null character (\0). While simple and efficient for static, unchanging strings,...
How to Delete Data in Elasticsearch: Single, Multiple, Clear, and All
Are you working with Elasticsearch and need to manage your data effectively? One crucial aspect of data management is knowing how to delete data when necessary. In this comprehensive guide, we’ll explore various Elasticsearch operations for deleting data, including single document deletion, multiple document deletion, clearing indices, and removing all data. Deleting a Single DocumentTo delete a single document from Elasticsearch, you’ll use the DELETE API. Here’s the basic syntax: 1DELETE...