You want to return a list of all elements in two redis sets. which keyword do you use?
Syntax Show
SMEMBERS keyAvailable since:1.0.0Time complexity:O(N) where N is the set cardinality.ACL categories: @read ,
@set , @slow ,Returns all the members of the set value stored at This has the same effect as running ReturnArray reply: all elements of the set. ExamplesSADD myset "Hello" SADD myset "World" SMEMBERS mysetFeedbackIf you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository.
Introduction to Redis lists Redis lists are linked lists of string values. Redis lists are frequently used to:
Examples
LimitsThe max length of a Redis list is 2^32 - 1 (4,294,967,295) elements. Basic commands
Blocking commandsLists support several blocking commands. For example:
See the complete series of list commands. PerformanceList operations that access its head or tail are O(1), which means they're highly efficient. However, commands that manipulate elements within a list are usually O(n). Examples of these include AlternativesConsider Redis streams as an alternative to lists when you need to store and process an indeterminate series of events. Learn more
FeedbackIf you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository. Syntax GRAPH.QUERY graph query [TIMEOUT timeout]Available in: Redis Stack / Graph 1.0.0Time complexity: Executes the given query against a specified graph. Arguments: Returns: Result set
Query-level timeouts can be set as described in the configuration section. Query languageThe syntax is based on Cypher, and only a subset of the language currently supported.
Query structure
MATCHMatch describes the relationship between queried entities, using ascii art to represent pattern(s) to match against. Nodes
are represented by parentheses Each graph entity node/relationship can contain an alias and a label/relationship type, but both can be left empty if necessary. Entity structure: Alias, label/relationship type, and filters are all optional. Example:
In this example, we're interested in actor entities which have the relation "act" with the entity representing the "straight outta compton" movie. It is possible to describe broader relationships by composing a multi-hop query such as:
Here we're interested in finding out who my friends' friends are. Nodes can have more than one relationship coming in or out of them, for instance:
Here we're interested in knowing which of my friends have visited at least one country I've been to. Variable length relationshipsNodes that are a variable number of relationship→node hops away can be found using the following syntax:
When no bounds are given the dots may be omitted. The dots may also be omitted when setting only one bound and this implies a fixed length pattern. Example:
Returns all actors related to 'Charlie Sheen' by 1 to 3 hops. Bidirectional path traversalIf a relationship pattern does not specify a direction, it will match regardless of which node is the source and which is the destination: Example:
Returns all pairs of people connected by a The syntactic sugar The bracketed edge description can be omitted if all relations should be considered: Named pathsNamed path variables are created by assigning a path in a MATCH clause to a single alias with the syntax: The named path includes all entities in the path, regardless of whether they have been explicitly aliased. Named paths can be accessed using designated built-in functions or returned directly if using a language-specific client. Example:
This query will produce all the paths matching the pattern contained in the named path All shortest pathsThe
A minimal length (must be 1) and maximal length (must be at least 1) for the search may be specified. Zero or more relationship types may be specified (e.g. [:R|Q*1..3]). No property filters may be introduced in the pattern.
Filters on properties are supported, and any number of labels may be specified. Example:
This query will produce all paths of the minimum length connecting the actor node representing Charlie Sheen to the one representing Kevin Bacon. There are several 2-hop paths between the two actors, and all of these will be returned. The computation of paths then terminates, as we are not interested in any paths of length greater than 2. Single-Pair minimal-weight bounded-cost bounded-length paths(Since RedisGraph v2.10) The
Input arguments:
Result:
Behavior in presence on multiple-edges:
Example:
Single-Source minimal-weight bounded-cost bounded-length paths(Since RedisGraph v2.10) The
Input arguments:
Result:
Behavior in presence on multiple-edges:
Example:
OPTIONAL MATCHThe OPTIONAL MATCH clause is a MATCH variant that produces null values for elements that do not match successfully, rather than the all-or-nothing logic for patterns in MATCH clauses. It can be considered to fill the same role as LEFT/RIGHT JOIN does in SQL, as MATCH entities must be resolved but nodes and edges introduced in OPTIONAL MATCH will be returned as nulls if they cannot be found. OPTIONAL MATCH clauses accept the same patterns as standard MATCH clauses, and may similarly be modified by WHERE clauses. Multiple MATCH and OPTIONAL MATCH clauses can be chained together, though a mandatory MATCH cannot follow an optional one.
All Cypher is lenient in its handling of null values, so actions like property accesses and function calls on null values will return null values rather than emit errors.
In this case, Clauses like SET, CREATE, MERGE, and DELETE will ignore null inputs and perform the expected updates on real inputs. One exception to this is that attempting to create a relation with a null endpoint will cause an error:
If WHEREThis clause is not mandatory, but if you want to filter results, you can specify your predicates here. Supported operations:
Predicates can be combined using AND / OR / NOT. Be sure to wrap predicates within parentheses to control precedence. Examples:
It is also possible to specify equality predicates within nodes using the curly braces as such:
Here we've required that the president node's name will have the value "Jed Bartlett". There's no difference between inline predicates and predicates specified within the WHERE clause. It is also possible to filter on graph patterns. The following queries, which return all presidents and the states they won in, produce the same results:
and
Pattern predicates can be also negated and combined with the logical operators AND, OR, and NOT. The following query returns all the presidents that did not win in the states where they were governors:
Nodes can also be filtered by label:
When possible, it is preferable to specify the label in the node pattern of the MATCH clause. RETURNIn its simple form, Return defines which properties the returned result-set will contain. Its structure is a list of For convenience, it's possible to specify the alias only when you're interested in every attribute an entity possesses, and don't want to specify each attribute individually. For example:
Use the DISTINCT keyword to remove duplications within the result-set:
In the above example, suppose we have two friends, Joe and Miesha, and both know Dominick. DISTINCT will make sure Dominick will only appear once in the final result set. Return can also be used to aggregate data, similar to group by in SQL. Once an aggregation function is added to the return list, all other "none" aggregated values are considered as group keys, for example:
Here we group data by movie title and for each movie, and we find its youngest and oldest actor age. AggregationsSupported aggregation functions include:
ORDER BYOrder by specifies that the output be sorted and how. You can order by multiple properties by stating each variable in the ORDER BY clause. Each property may specify its sort order with The result will be sorted by the first variable listed. For equal values, it will go to the next property in the ORDER BY clause, and so on.
Below we sort our friends by height. For equal heights, weight is used to break ties.
SKIPThe optional skip clause allows a specified number of records to be omitted from the result set.
This can be useful when processing results in batches. A query that would examine the second 100-element batch of nodes with the label
LIMITAlthough not mandatory, you can use the limit clause to limit the number of records returned by a query:
If not specified, there's no limit to the number of records returned by a query. CREATECREATE is used to introduce new nodes and relationships. The simplest example of CREATE would be a single node creation: It's possible to create multiple entities by separating them with a comma.
To add relations between nodes, in the following example we first find an existing source node. After it's found, we create a new relationship and destination node.
Here the source node is a bounded node, while the destination node is unbounded. As a result, a new node is created representing the band Nirvana and a new relation connects Kurt to the band. Lastly we create a complete pattern. All entities within the pattern which are not bounded will be created.
This query will create three nodes and two relationships. DELETEDELETE is used to remove both nodes and relationships. Note that deleting a node also deletes all of its incoming and outgoing relationships. To delete a node and all of its relationships:
To delete relationship:
This query will delete all SETSET is used to create or update properties on nodes and relationships. To
set a property on a node, use
If you want to set multiple properties in one go, simply separate them with a comma to set multiple properties using a single SET clause.
The same can be accomplished by setting the graph entity variable to a map:
Using In the same way, the full property set of a graph entity can be assigned or merged:
After executing this query, the To remove a node's property, simply set property value to NULL.
MERGEThe MERGE clause ensures that a path exists in the graph (either the path already exists, or it needs to be created). MERGE either matches existing nodes and binds them, or it creates new data and binds that. It’s like a combination of MATCH and CREATE that also allows you to specify what happens if the data was matched or created. For example, you can specify that the graph must contain a node for a user with a certain name. If there isn’t a node with the correct name, a new node will be created and its name property set. Any aliases in the MERGE path that were introduced by earlier clauses can only be matched; MERGE will not create them. When the MERGE path doesn't rely on earlier clauses, the whole path will always either be matched or created. If all path elements are introduced by MERGE, a match failure will cause all elements to be created, even if part of the match succeeded. The MERGE path can be followed by ON MATCH SET and ON CREATE SET directives to conditionally set properties depending on whether or not the match succeeded. Merging nodes To merge a single node with a label:
To merge a single node with properties:
To merge a single node, specifying both label and property:
Merging paths Because MERGE either matches or creates a full path, it is easy to accidentally create duplicate nodes. For example, if we run the following query on our sample graph:
Even though a node with the name 'Charlie Sheen' already exists, the full pattern does not match, so 1 relation and 2 nodes - including a duplicate 'Charlie Sheen' node - will be created. We should use multiple MERGE clauses to merge a relation and only create non-existent endpoints:
If we don't want to create anything if pattern elements don't exist, we can combine MATCH and MERGE clauses. The following query merges a relation only if both of its endpoints already exist:
On Match and On Create directives Using ON MATCH and ON CREATE, MERGE can set properties differently depending on whether a pattern is matched or created. In this query, we'll merge paths based on a list of properties and conditionally set a property when creating new entities:
WITHThe WITH clause allows parts of queries to be independently executed and have their results handled uniquely. This allows for more flexible query composition as well as data manipulations that would otherwise not be possible in a single query. If, for example, we wanted to find all children in our graph who are above the average age of all people:
This also allows us to use modifiers like
UNWINDThe UNWIND clause breaks down a given list into a sequence of records; each contains a single element in the list. The order of the records preserves the original list order.
UNIONThe UNION clause is used to combine the result of multiple queries. UNION combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The number and the names of the columns must be identical in all queries combined by using UNION. To keep all the result rows, use UNION ALL. Using just UNION will combine and remove duplicates from the result set.
FunctionsThis section contains information on all supported functions from the Cypher query language.
Predicate functions
Scalar functions
Aggregating functions
List functions
Mathematical operators
Mathematical functions
Trigonometric functions
String functions
Point functions
Type conversion functions
Node functions
Path functions
List comprehensionsList comprehensions are a syntactical construct that accepts an array and produces another based on the provided map and filter directives. They are a common construct in functional languages and modern high-level languages. In Cypher, they use the syntax:
The following query collects all paths of any length, then for each produces an array containing the
Existential comprehension functionsThe functions
They can operate on any form of input array, but are particularly useful for path filtering. The following query collects all paths of any length in which all traversed edges have a weight less than 3:
Pattern comprehensionsPattern comprehensions are a method of producing a list composed of values found by performing the traversal of a given graph pattern. The following query returns the name of a
Optionally, a
CASE WHENThe case statement comes in two variants. Both accept an input argument and evaluates it against one or more expressions. The first Optionally, an In its simple form, there is only one expression to evaluate and it immediately follows the
In its generic form, no expression follows the
ReduceThe
PointThe
The key names The point constructed by this function can be saved as a node/relationship property or used within the query, such as in a shortestPathThe
The sole JSON format
The format for a node object in JSON is:
The format for a relationship object in JSON is:
ProceduresProcedures are invoked using the syntax:
Or the variant:
YIELD modifiers are only required if explicitly specified; by default the value in the 'Yields' column will be emitted automatically.
AlgorithmsBFSThe breadth-first-search algorithm accepts 4 arguments:
It can yield two outputs:
IndexingRedisGraph supports single-property indexes for node labels and for relationship type. String, numeric, and geospatial data types can be indexed. Creating an index for a node labelFor a node label, the index creation syntax is:
An old syntax is also supported:
After an index is explicitly created, it will automatically be used by queries that reference that label and any indexed property in a filter.
This can significantly improve the runtime of queries with very specific filters. An index on
An example of utilizing a geospatial index to find
Geospatial indexes
can currently only be leveraged with Creating an index for a relationship typeFor a relationship type, the index creation syntax is:
Then the execution plan for using the index:
This can significantly improve the runtime of queries that traverse super nodes or when we want to start traverse from relationships. Deleting an index for a node labelFor a node label, the index deletion syntax is:
Deleting an index for a relationship typeFor a relationship type, the index deletion syntax is:
Full-text indexingRedisGraph leverages the indexing capabilities of RediSearch to provide full-text indices through procedure calls. Creating a full-text index for a node labelTo construct a full-text index on the
More properties can be added to this index by adding their names to the above set of arguments, or using this syntax again with the additional names.
RediSearch provide 2 index configuration options:
To
construct a full-text index on the
RediSearch provide 3 additional field configuration options:
To construct a full-text index on the
Utilizing a full-text index for a node labelAn index can be invoked to match any whole words contained within:
This CALL clause can be interleaved with other Cypher clauses to perform more elaborate manipulations:
In addition to yielding matching nodes, full-text index scans will return the score of each node. This is the TF-IDF score of the node, which is informed by how many times the search terms appear in the node and how closely grouped they are. This can be observed in the example:
Deleting a full-text index for a node labelFor a node label, the full-text index deletion syntax is:
FeedbackIf you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository. Which two characteristics define Amazon Quantum ledger database Linkedin?Which two characteristics define Amazon Quantum Ledger Database? Key-value data model; transactionally consistent with ACID semantics.
What is popular open source keyPopular Open Source Key-Value Databases. When it comes to popularity, open source key-value databases are king. Among them, Redis and Elasticsearch are the most popular.
What Google NoSQL database should you use?Cloud Bigtable
Highly performant, fully managed NoSQL database service for large analytical and operational workloads. Offers up to 99.999% availability. Processes more than 5 billion requests per second at peak, and with more than 10 Exabytes of data under management. Learn how to migrate from HBase or Cassandra.
Which statement accurately describes global secondary indexes in Dynamodb?A global secondary index contains a selection of attributes from the base table, but they are organized by a primary key that is different from that of the table. The index key does not need to have any of the key attributes from the table. It doesn't even need to have the same key schema as a table.
|