本文整理汇总了Java中redis.clients.jedis.SortingParams类的典型用法代码示例。如果您正苦于以下问题:Java SortingParams类的具体用法?Java SortingParams怎么用?Java SortingParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SortingParams类属于redis.clients.jedis包,在下文中一共展示了SortingParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sort
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public RedisValue<List<String>> sort(final CacheKey cacheKey, final String key, final SortingParams sortingParameters) {
Collection<byte[]> params = sortingParameters.getParams();
String[] paramList = new String[params.size() + 1];
paramList[0] = key;
int i = 1;
for (byte[] p : params) {
try {
paramList[i++] = new String(p, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
final String localKey = concat("sort", paramList);
RedisValue<?> res = cacheWrapper.get(cacheKey, localKey, new Callable<RedisValue<?>>() {
@Override
public RedisValue<?> call() throws Exception {
return provider.sort(cacheKey, key, sortingParameters);
}
});
return (RedisValue<List<String>>) res;
}
示例2: sort
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Override
public RedisValue<List<String>> sort(final CacheKey cacheKey, final String key, final SortingParams sortingParameters) {
Collection<byte[]> params = sortingParameters.getParams();
String[] actualParams = new String[params.size() + 1];
actualParams[0] = key;
int i = 1;
for (byte[] p : params) {
try {
actualParams[i++] = new String(p, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
concat("sort", actualParams);
RedisValue<List<String>> valueImpl = new RedisValue<List<String>>();
appendCommand(new PipelineCommand<List<String>>(valueImpl) {
@Override
public Response<List<String>> run() {
return ((RedisValue<List<String>>) pipelineProvider.sort(cacheKey, key, sortingParameters)).getResponse();
}
});
return valueImpl;
}
示例3: shouldReturnEmptyQueryOnEmptyResultOfSort
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldReturnEmptyQueryOnEmptyResultOfSort() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(new ArrayList<String>());
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams()), getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(0, terms.size());
}
示例4: shouldAddTermsFromSort
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSort() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams()), getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例5: shouldAddTermsFromSortAlgorithmAlpha
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortAlgorithmAlpha() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("algorithm")).thenReturn("alpha");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().alpha()), getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例6: shouldAddTermsFromSortOrderAsc
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortOrderAsc() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("order")).thenReturn("asc");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().asc()), getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例7: shouldAddTermsFromSortOrderDesc
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortOrderDesc() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("order")).thenReturn("desc");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().desc()), getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例8: shouldAddTermsFromSortLimit
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortLimit() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("limit")).thenReturn("100");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().limit(0, 100)),
getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例9: shouldAddTermsFromSortOffset
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortOffset() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("offset")).thenReturn("100");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().limit(100, 0)),
getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例10: shouldAddTermsFromSortLimitAndOffset
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortLimitAndOffset() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("offset")).thenReturn("100");
when(localParamsMock.get("limit")).thenReturn("1000");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().limit(100, 1000)),
getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例11: shouldAddTermsFromSortWithByClause
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortWithByClause() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("by")).thenReturn("foo_*");
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().by("foo_*")),
getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例12: shouldAddTermsFromSortWithSingleGetClause
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void shouldAddTermsFromSortWithSingleGetClause() throws SyntaxError, IOException {
when(localParamsMock.get("command")).thenReturn("sort");
when(localParamsMock.get("key")).thenReturn("simpleKey");
when(localParamsMock.get("get")).thenReturn("get_*");
when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "get").iterator());
when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
when(requestMock.getSchema()).thenReturn(schema);
when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
final Query query = redisQParser.parse();
final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
verify(jedisMock).sort(eq("simpleKey"), argument.capture());
Assert.assertEquals(getSortingParamString(new SortingParams().get("get_*")),
getSortingParamString(argument.getValue()));
IndexSearcher searcher = new IndexSearcher(new MultiReader());
final Set<Term> terms = extractTerms(searcher, query);
Assert.assertEquals(2, terms.size());
}
示例13: sortDesc
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void sortDesc() {
jedis.lpush("foo", "3");
jedis.lpush("foo", "2");
jedis.lpush("foo", "1");
SortingParams sp = new SortingParams();
sp.desc();
List<String> result = jedis.sort("foo", sp);
List<String> expected = new ArrayList<String>();
expected.add("3");
expected.add("2");
expected.add("1");
assertEquals(expected, result);
// Binary
jedis.lpush(bfoo, b3);
jedis.lpush(bfoo, b2);
jedis.lpush(bfoo, b1);
SortingParams bsp = new SortingParams();
bsp.desc();
List<byte[]> bresult = jedis.sort(bfoo, bsp);
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(b3);
bexpected.add(b2);
bexpected.add(b1);
assertByteArrayListEquals(bexpected, bresult);
}
示例14: sortLimit
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void sortLimit() {
for (int n = 10; n > 0; n--) {
jedis.lpush("foo", String.valueOf(n));
}
SortingParams sp = new SortingParams();
sp.limit(0, 3);
List<String> result = jedis.sort("foo", sp);
List<String> expected = new ArrayList<String>();
expected.add("1");
expected.add("2");
expected.add("3");
assertEquals(expected, result);
// Binary
jedis.rpush(bfoo, new byte[] { (byte) '4' });
jedis.rpush(bfoo, new byte[] { (byte) '3' });
jedis.rpush(bfoo, new byte[] { (byte) '2' });
jedis.rpush(bfoo, new byte[] { (byte) '1' });
SortingParams bsp = new SortingParams();
bsp.limit(0, 3);
List<byte[]> bresult = jedis.sort(bfoo, bsp);
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(b1);
bexpected.add(b2);
bexpected.add(b3);
assertByteArrayListEquals(bexpected, bresult);
}
示例15: sortAlpha
import redis.clients.jedis.SortingParams; //导入依赖的package包/类
@Test
public void sortAlpha() {
jedis.lpush("foo", "1");
jedis.lpush("foo", "2");
jedis.lpush("foo", "10");
SortingParams sp = new SortingParams();
sp.alpha();
List<String> result = jedis.sort("foo", sp);
List<String> expected = new ArrayList<String>();
expected.add("1");
expected.add("10");
expected.add("2");
assertEquals(expected, result);
// Binary
jedis.lpush(bfoo, b1);
jedis.lpush(bfoo, b2);
jedis.lpush(bfoo, b10);
SortingParams bsp = new SortingParams();
bsp.alpha();
List<byte[]> bresult = jedis.sort(bfoo, bsp);
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(b1);
bexpected.add(b10);
bexpected.add(b2);
assertByteArrayListEquals(bexpected, bresult);
}