redis - sails有不通过orm直接操作数据库的方案吗?
迷茫
迷茫 2017-04-24 09:12:38
0
3
702

需求是通过redis做一个缓存services
但是在config/connections.js下配置的数据库似乎只能用于orm
不知道有没有现成的方案可以直接操作redis数据库

=======================

分享一下node原生redis库操作

# 创建连接
redis = require('redis').createClient()

# 监听异常
redis.on 'error', (err) ->
  console.log(err)

# 记录值
redis.set(key, value)
# 读取值
redis.get key, (err, data) ->
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
小葫芦

There is no ORM tool similar to DB for redis, but Spring has encapsulation of Redis, you can understand it

迷茫
redis = require('redis').createClient({port:'6379',host:'127.0.0.1',password:123456,db:2});
redis.set('ddd',1111,function(err, rs){
  console.log(err);console.log('=');
  console.log(rs);
});
    
   redis.get('ddd',function(err, rs){
     console.log(err);console.log('=');
     console.log(rs);
   });

Print out

null
=
OK
null
=
1111
伊谢尔伦

expressed that he also wanted to know, because the ORM has a query method, but it is used to execute sql. And after playing with the entire waterline package, the operation feels very similar to the mongo document type nosql. Redis cannot perform low-level operations.

Another question is whether sails supports multiple data sources at the same time

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template