有没有办法在 jedis 中传递 redis 命令,而不使用这些函数? [英] Is there a way to pass redis commands in jedis, without using the functions?

查看:58
本文介绍了有没有办法在 jedis 中传递 redis 命令,而不使用这些函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试构建一个控制台来处理 redis 查询.但是,在后端我们需要使用 Jedis.因此,作为输入给出的命令需要使用 Jedis 进行处理.例如,在 redis-cli 中,我们使用keys *".同样,我们在 Jedis 中使用 jedis.keys(" * ").我不知道如何将keys *"转换为jedis.keys(*").请告诉我一些建议....

We are trying to build a console to process redis queries. But, in the back end we need to use Jedis. So, the commands, given as the inputs needs to be processed using Jedis. For example, in redis-cli, we use " keys * ". For the same we use jedis.keys(" * ") in Jedis. I have no idea, how to convert " keys * " into jedis.keys(" * "). Kindly tell me some suggestions....

推荐答案

我找到了解决这个问题的方法.有一个名为 eval() 的函数.我们可以使用它,如下所示.

I have found a way for this. There is a function named eval(). We can use that for this as shown below.

`Scanner s=new Scanner(System.in);String query=s.nextLine();
 String[] q=query.split(" ");
 String cmd='\''+q[0]+'\'';
 for(int i=1;i<q.length;i++)
 cmd+=",\'"+q[i]+'\'';
 System.out.println(j.eval("return redis.call("+cmd+")"));`

这篇关于有没有办法在 jedis 中传递 redis 命令,而不使用这些函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆