首页 \ 问答 \ 如何使用Lua脚本在Redis中传递换行符(How to pass a newline character in Redis with Lua script)

如何使用Lua脚本在Redis中传递换行符(How to pass a newline character in Redis with Lua script)

我使用Lua脚本在Redis数据库中设置记录。 某些记录可能包含换行符。
如何使用Lua设置包含换行符的主体的新记录?

我的代码是:

redis.call("set", "text", "First line\nSecond line" );

但是当我在redis-cli> get“text”中检查这条记录时,我希望它是:

First line
Second line

但我得到:

First line\nSecond line

I set records in Redis database with a Lua script. Some records may contain newline characters.
How can I set a new record with body containing a newline character using Lua?

My code is:

redis.call("set", "text", "First line\nSecond line" );

But when I examine this record in redis-cli> get "text", I'd like it to be:

First line
Second line

But I get:

First line\nSecond line

原文:https://stackoverflow.com/questions/41381428
更新时间:2022-11-26 19:11

最满意答案

会话是特定于用户的。

Servlet上下文本质上是全局的(在该servlet的上下文中),这意味着命中该servlet的所有用户将共享相同的servlet上下文。


Sessions are user specific.

Servlet contexts are essentially global (within the context of that servlet), meaning all users who hit that servlet will share the same servlet context.

相关问答

更多
  • 首先说一下session是如何使用的。其实很简单,第一步是要获取到session对象,然后第二部就是对数据添加、删除、获取操作了。 这里先说说session的寿命问题,session的寿命是可以在web.xml当中设置的,单位是分钟。比如如果寿命是120分钟,那么当同一个客户在上一次访问以后120分钟内没有再次访问的话session就会被注销,也就是说如果在120分钟内访问过了的话,那么就再延续120分钟。 获取session: 因为session是由服务器自动管理的,因此session的获取不可以直接ne ...
  • 您最好将它作为参数传递给对象的构造函数,或者使用setter方法设置它。 实际上,您可以获得与您的对象相关的上下文属性,并仅通过构造函数/设置器传递它。 例如: YourClass obj = new YourClass((AnotherClass) servletContext.getAttribute("yourAttribute")); 更糟和更复杂的选择是: 创建一个ServletContextListener 使用
  • Java Servlet容器实际上是一个轻度托管的代码容器。 Servlet是具有非常明确的生命周期的组件,并且在容器和组件(也可以包括过滤器)之间也有非常明确的合同。 按照规定,网络应用程序是一个被动反应系统。 它是被动的,因为没有用户定义的线程被严格地允许。 (有些容器可能不会强制执行此限制,但是通过产生自己的线程,您实际上已不在预留范围内,并且可能发生不可预知的行为。) 它是被动的,因为服务器上的活动(在您的代码库中)响应请求而发生,并且这些是针对典型的Servlet应用程序HTTP请求的。 Serv ...
  • 2:在你的一个spring bean上实现ServletContextAware接口,然后对上下文进行必要的修改。 如果需要,可以在@PostConstruct注释方法中执行此操作,因为在更新servletcontext时,bean已完成。 Take 2: Implement the ServletContextAware interface on one of your spring beans and just do the necessary modifications to the context. ...
  • 我的解决方案是直接访问会话状态存储。 例: (用于SQL)直接选择查询到带有表的ASPState数据库(ASPStateTempApplications,ASPStateTempSessions) My solution is direct access to storage of Session State. example: (for SQL) direct select query to ASPState database with tables(ASPStateTempApplications, A ...
  • 您可以将实例模式设置为PerSession。 然后,实现OperationContract的对象成为会话对象。 You can set the Instance mode to PerSession. And then your object that implements the OperationContract becomes the session object.
  • 会话是特定于用户的。 Servlet上下文本质上是全局的(在该servlet的上下文中),这意味着命中该servlet的所有用户将共享相同的servlet上下文。 Sessions are user specific. Servlet contexts are essentially global (within the context of that servlet), meaning all users who hit that servlet will share the same servlet c ...
  • 这是在Restlet 2.0之前做到这一点的方式(实际上我认为他们改变了大约2.0-M5左右)。 无论如何,你现在的方式是: ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes().get( "org.restlet.ext.servlet.ServletContext" ); 希望有所帮助。 This was the way to do it before R ...
  • 您应该使用ServletContextListener来在基于servlet的应用程序上执行编程配置。 @WebListener public class Config implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { ServletContext servletContext = event.getServlet ...
  • 所以我接受了@Kayaman的建议。 并尝试限制对象在各自层中的使用,即使用表示层中的上下文和数据访问层中的Hibernate Session 。 我将来自Controller的调用传递给DAO,并将所需的对象存储在DAO中的全局映射中,这些映射后来被称为进一步的进程。 最后将信号返回到Presentation层。 So I took @Kayaman's advice. And tried to limit the use of objects in their respective layers i.e ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。