데이터 구조에 대한 쿼리
데이터 구조가 있는 경우 캐시에서 쿼리할 수 있습니다. 검색 가능한 속성 데이터 구조 생성 중에 이들과 연결됩니다. 이러한 검색 가능한 속성은 다음과 같습니다.
사전 조건
- 모든 작업에 필요한 표준 전제 조건에 대해 알아보려면 NCache 클라이언트측 기능은 다음 페이지를 참조하세요. 클라이언트 측 API 전제 조건.
- API 세부 정보는 다음을 참조하세요. 아이캐시, 쿼리 명령, ICacheReader, 검색 서비스, ExecuteReader, 값 가져오기, IDistributedList, 그룹 데이터 가져오기, 필드카운트, IDistributedDictionary, GetByTag.
- 모든 작업에 필요한 표준 전제 조건에 대해 알아보려면 NCache 클라이언트측 기능은 다음 페이지를 참조하세요. 클라이언트 측 API 전제 조건.
- API 세부 정보는 다음을 참조하세요. 캐시, 쿼리 명령, 캐시 리더, getSearchService, 실행 리더, getFieldCount, 값을 얻다, 분산 목록, getGroupData, DataStructure속성, 분산 맵, getByTag.
- 모든 작업에 필요한 표준 전제 조건에 대해 알아보려면 NCache 클라이언트측 기능은 다음 페이지를 참조하세요. 클라이언트 측 API 전제 조건.
- API 세부 정보는 다음을 참조하세요. 캐시, 쿼리 명령, 검색 서비스, getSearchService, 실행 리더, getFieldCount, 값을 얻다, getGroupData, 캐시 리더, DataStructure속성, getByTag.
- 모든 작업에 필요한 표준 전제 조건에 대해 알아보려면 NCache 클라이언트측 기능은 다음 페이지를 참조하세요. 클라이언트 측 API 전제 조건.
- API 세부 정보는 다음을 참조하세요. 캐시, 쿼리 명령, 캐시 리더, 실행 판독기, 검색 서비스, get_search_service, DataStructure속성, get_field_count, get_value, get_group_data, get_by_tag.
그룹별로 데이터 구조 검색
SQL 쿼리
다음 코드 샘플은 지정된 그룹과 연결된 캐시에서 모든 항목을 가져옵니다. 전자. 그룹은 다음을 사용하여 연결할 수 있습니다. DataTypeAttributes
데이터 구조 생성 중 클래스.
중대한
- 그룹에 대해 여러 목록이 지정된 경우 해당 데이터 구조가 유사하면 모든 목록이 하나의 결과로 반환됩니다.
- 예를 들어 여러 캐시 항목의 경우
CacheItem
목록이 동일한 그룹에 속해 있으면 데이터가 적절하게 처리되는지 확인해야 합니다.
// Preconditions: Cache is already connected
// Items with groups exist in cache
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Search for items with group
// Provide Fully Qualified Name (FQN) of your custom class
string query = "SELECT ProductID FROM FQN.Customer WHERE $Group$ = ?";
/// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
// Providing parameters for query
queryCommand.Parameters.Add("$Group$", "Electronics");
// Executing QueryCommand through ICacheReader
ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand);
// Check if the result set is not empty
if (reader.FieldCount > 0)
{
while (reader.Read())
{
string ProductID = reader.GetValue<string>(1);
// Perform operations
}
}
else
{
// Null query result set retrieved
}
// Preconditions: Cache is already connected
// Items with groups exist in cache
// Custom class is query indexed through NCache Management Center or config.ncconf
// Search for items with group
// Provide Fully Qualified Name (FQN) of your custom class
String query = "SELECT productID FROM FQN.Customer WHERE $Group$ = ?";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
// Providing parameters for query
queryCommand.getParameters().put("$Group$", "Electronics");
// Executing QueryCommand through CacheReader
CacheReader reader = cache.getSearchService().executeReader(queryCommand);
// Check if the result set is not empty
if (reader.getFieldCount() > 0) {
while (reader.read()) {
String productID = reader.getValue(1, String.class);
// Perform operations
}
} else {
// Null query result set retrieved
}
// This is an async method
// Preconditions: Cache is already connected
// Items with groups exist in cache
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Search for items with group
// Provide Fully Qualified Name (FQN) of your custom class
var query = "SELECT productID FROM FQN.Customer WHERE $Group$ = ?";
/// Use QueryCommand for query execution
var queryCommand = new ncache.QueryCommand(query);
// Providing parameters for query
let map = new Map();
var parameters = map.set("$Group$", "Electronics");
queryCommand.setParameters(parameters);
// Executing QueryCommand through CacheReader
var searchService = await this.cache.getSearchService();
var reader = await searchService.executeReader(queryCommand);
// Check if the result set is not empty
if (reader.getFieldCount() > 0) {
while (reader.read()) {
var productID = reader.getValue(1, Number());
// Perform operations
}
} else {
// Null query result set retrieved
}
# Preconditions: Cache is already connected
# Items with groups exist in cache
# Custom class is query indexed through NCache Management Center or config.ncconf
# Search for items with group
# Provide Fully Qualified Name (FQN) of your custom class
query = "SELECT product_id FROM FQN.Customer WHERE $Group$ = ?"
# Use QueryCommand for query execution
query_command = ncache.QueryCommand(query)
# Providing parameters for query
parameters = {"$Group$": "Electronics"}
query_command.set_parameters(parameters)
# Executing QueryCommand through CacheReader
search_service = cache.get_search_service()
reader = search_service.execute_reader(query_command)
# Check if the result set is not empty
if reader.get_field_count() > 0:
while reader.read():
product_id = reader.get_value(str, 1)
# Perform operations
else:
# None query result set retrieved
print("Query result is None")
그룹 API
다음 코드 샘플은 지정된 그룹과 연결된 캐시에서 모든 목록을 가져옵니다. 전자. 그룹은 다음을 사용하여 연결할 수 있습니다. DataTypeAttributes
데이터 구조 생성 중 클래스.
// List with this group already exists in cache
string groupName = "Electronics";
IDictionary<string, IDistributedList<Product>> result = cache.SearchService.GetGroupData<IDistributedList<Product>>(groupName);
if (result != null && result.Count > 0)
{
// Iterate over list
foreach (var item in result)
{
foreach (var i in item.Value)
{
// Perform operations
}
}
}
else
{
// No data against the group found
}
// Precondition: Cache is already connected
// List with this group already exists in the cache
String groupName = "Electronics";
Map<String, DistributedList<Product>> result = cache.getSearchService().getGroupData(groupName);
if (result != null && result.size() > 0) {
// Iterate over list
for (var item : result.entrySet()) {
// Perform operations
}
} else {
// No data against the group found
}
// This is an async method
// Precondition: Cache is already connected
// List with this group already exists in the cache
var groupName = "Electronics";
var result = await (
await this.cache.getSearchService()
).getGroupData(groupName);
if (result != null && result.size() > 0) {
// Iterate over list
for (var item in result.entrySet()) {
// Perform operations
}
} else {
// No data against the group found
}
# Precondition: Cache is already connected
# List with this group already exists in the cache
group_name = "Electronics"
result = cache.get_search_service().get_group_data(group_name)
if result is not None and len(result) > 0:
# Iterate over list
for item in result:
# Perform operations
print(item)
else:
# No data against the group found
print("No data found")
주의 사항
작업이 안전하도록 하려면 에 설명된 대로 응용 프로그램 내에서 잠재적인 예외를 처리하는 것이 좋습니다. 처리 실패.
SQL 쿼리
다음 코드 샘플은 지정된 태그와 연결된 캐시에서 항목을 가져옵니다. 스테인리스 강. 다음을 사용하여 태그를 연결할 수 있습니다. DataTypeAttributes
데이터 구조 생성 중 클래스.
// Items are already present in the cache with tags
// Custom class is query indexed through NCache Management Center or config.ncconf
// Search for items with tags
// Use the Fully Qualified Name (FQN) of your own custom class
string query = "Select $Value$ FROM FQN.Product WHERE $Tag$ = ?";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("$Tag$", "Stainless Steel");
// Executing query
ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand);
// Check if result set is not empty
if (reader.FieldCount > 0)
{
while (reader.Read())
{
// Get the value of the result set
Product result = reader.GetValue<Product>(1);
}
}
else
{
// Null query result set retrieved
}
// Pre-conditions: Cache is already connected
// Items are already present in the cache with tags
// Custom class is query indexed through NCache Management Center or config.ncconf
// Search for items with tags
// Use the Fully Qualified Name (FQN) of your own custom class
String query = "Select $Value$ FROM FQN.Product WHERE $Tag$ = ?";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
queryCommand.getParameters().put("$Tag$", "Stainless Steel");
// Executing query
CacheReader reader = cache.getSearchService().executeReader(queryCommand);
// Check if result set is not empty
if (reader.getFieldCount() > 0) {
while (reader.read()) {
// Get the value of the result set
Product result = reader.getValue(1, Product.class);
}
} else {
// Null query result set retrieved
}
// This is an async method
// Pre-conditions: Cache is already connected
// Items are already present in the cache with tags
// Custom class is query indexed through NCache Management Center or config.ncconf
// Search for items with tags
// Use the Fully Qualified Name (FQN) of your own custom class
var query = "Select $Value$ FROM FQN.Product WHERE $Tag$ = ?";
// Use QueryCommand for query execution
var queryCommand = new ncache.QueryCommand(query);
var map = new Map();
var parameters = map.set("$Tag$", "Stainless Steel");
queryCommand.setParameters(parameters);
// Executing query
var searchService = await this.cache.getSearchService();
var reader = await searchService.executeReader(queryCommand);
// Check if result set is not empty
if (reader.getFieldCount() > 0) {
while (reader.read()) {
// Get the value of the result set
var result = reader.getValue(1, ncache.JsonDataType.Object);
// Perform operations
}
} else {
// Null query result set retrieved
}
# Pre-conditions: Cache is already connected
# Items are already present in the cache with tags
# Custom class is query indexed through NCache Management Center or config.ncconf
# Search for items with tags
# Use the Fully Qualified Name (FQN) of your own custom class
query = "Select $Value$ FROM FQN.Product WHERE $Tag$ = ?"
# Use QueryCommand for query execution
query_command = ncache.QueryCommand(query)
parameters = {"$Tag$": "Stainless Steel"}
query_command.set_parameters(parameters)
# Executing query
search_service = cache.get_search_service()
reader = search_service.execute_reader(query_command)
# Check if result set is not empty
if reader.get_field_count() > 0:
while reader.read():
# Get the value of the result set
result = reader.get_value(Product, 1)
# Perform operations
else:
# Null query result set retrieved
print("Query result is None")
태그 API
다음 코드 샘플은 지정된 태그와 연결된 캐시에서 모든 사전 인스턴스를 가져옵니다. 스테인리스 강. 태그는 다음을 사용하여 연결할 수 있습니다. DataTypeAttributes
데이터 구조 생성 중 클래스.
// Items against this tag exist in cache
Tag tag = new Tag("Stainless Steel");
// Get dictionary against tag
IDictionary<string, IDistributedDictionary<string, Product>> result = cache.SearchService.GetByTag<IDistributedDictionary<string, Product>>(tag);
if (result != null && result.Count > 0)
{
foreach (var item in result)
{
// Perform operations
}
}
else
{
// Dictionary does not exist against tag
}
// Precondition: Cache is already connected
// Items against this tag already exist in the cache
Tag tag = new Tag("Stainless steel");
// Get map against tag
Map<String, DistributedMap<String, Product>> result = cache.getSearchService().getByTag(tag);
if (result != null && result.size() > 0) {
for (var item : result.entrySet()) {
// Perform operations
}
} else {
// Dictionary does not exist against tag
}
// This is an async method
// Precondition: Cache is already connected
// Items against this tag already exist in the cache
var tag = [new ncache.Tag("Stainless steel")];
// Get map against tag
var result = await (await this.cache.getSearchService()).getByTag(tag);
if (result != null && result.size() > 0) {
for (var item in result.entrySet()) {
// Perform operations
}
} else {
// Dictionary does not exist against tag
}
# Precondition: Cache is already connected
# Items against this tag already exist in the cache
tag = ncache.Tag("Stainless steel")
# Get map against tag
result = cache.get_search_service().get_by_tag(tag)
if result is not None and len(result) > 0:
for item in result:
# Perform operations
print(item)
else:
# Dictionary does not exist against tag
print("Dictionary not found")
NCache 를 사용하여 $DataType$
지정된 명명된 태그가 있는 모든 데이터 구조를 가져오는 키워드입니다. 다음 코드는 명명된 태그를 사용하여 목록이 추가되었다고 가정합니다. 할인 가치가있는 0.4 쿼리를 사용하여 가져옵니다.
// Data Structures exist with NamedTag Discount and value 0.4
// Create query
string query = "SELECT * FROM $DataType$ WHERE Discount = 0.4";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
// Execute Query to search cache
ICacheReader queryResult = cache.SearchService.ExecuteReader(queryCommand);
// queryResult contains all the keys and metadata of result
if (queryResult.FieldCount > 0)
{
while (queryResult.Read())
{
// Key of list can be fetched through
queryResult.GetValue<DistributedList>(1);
}
}
else
{
// Null query result set retrieved
}
// Pre-conditions: Cache is already connected
// Data Structures exist with NamedTag "Discount" and value 0.4
// Create query
String query = "SELECT * FROM $DataType$ WHERE Discount = 0.4";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
// Execute Query to search cache
CacheReader queryResult = cache.getSearchService().executeReader(queryCommand);
// queryResult contains all the keys and metadata of result
if (queryResult.getFieldCount() > 0) {
while (queryResult.read()) {
// Key of list can be fetched through
queryResult.getValue(0, DistributedList.class);
// Perform operations
}
} else {
// Null query result set retrieved
}
// This is an async method
// Pre-conditions: Cache is already connected
// Data Structures exist with NamedTag "Discount" and value 0.4
// Create query
var query = "SELECT * FROM $DataType$ WHERE Discount = 0.4";
// Use QueryCommand for query execution
var queryCommand = new ncache.QueryCommand(query);
// Execute Query to search cache
var searchService = await this.cache.getSearchService();
var queryResult = await searchService.executeReader(queryCommand);
// queryResult contains all the keys and metadata of result
if (queryResult.getFieldCount() > 0) {
while (queryResult.read()) {
// Key of list can be fetched through
queryResult.getValue(0, Number());
// Perform operations
}
} else {
// Null query result set retrieved
}
# Pre-conditions: Cache is already connected
# Data Structures exist with NamedTag "Discount" and value 0.4
# Create query
query = "SELECT * FROM $DataType$ WHERE discount = 0.4"
query_command = ncache.QueryCommand(query)
# Execute Query to search cache
search_service = cache.get_search_service()
query_result = search_service.execute_reader(query_command)
# queryResult contains all the keys and metadata of result
if query_result.get_field_count() > 0:
while query_result.read():
# Key of list can be fetched through
query_result.get_value(int, 1)
# Perform operations
else:
# No data containing the named tag(s) exist
print("Data not found")
추가 자료
NCache 에서 데이터 구조를 쿼리하기 위한 샘플 애플리케이션을 제공합니다. GitHub의.
도 참조
.그물: Alachisoft.NCache.클라이언트.데이터 유형 네임 스페이스.
자바 : COM.alachisoft.ncache.client.데이터구조 네임 스페이스.
Node.js : 데이터 구조 관리자 클래스입니다.
파이썬 : ncache.client.데이터구조 클래스입니다.