加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在Haskell中使用hedis通过Unix域套接字连接到redis服务器?

发布时间:2020-12-16 01:15:35 所属栏目:安全 来源:网络整理
导读:我正在寻找如何使用 hedis通过Unix域套接字连接到redis服务器,如hackage页面中所宣传的那样: Connect via TCP or Unix Domain Socket: TCP sockets are the default way to connect to a Redis server. For connections to a server on the same machine,Un
我正在寻找如何使用 hedis通过Unix域套接字连接到redis服务器,如hackage页面中所宣传的那样:

Connect via TCP or Unix Domain Socket:
TCP sockets are the default way
to connect to a Redis server. For connections to a server on the same
machine,Unix domain sockets offer higher performance than the
standard TCP connection.

ConnectInfo的构造函数,以及defaultConnectInfo,似乎我们应该填写connectPort,因为它的类型PortID有一个名为UnixSocket的构造函数.但它只显示UnixSocket是一个字符串,没有格式细节等.

那么如何通过Unix域套接字填写connectPort进行连接?谢谢.

更新:我试了一下,发现并不难.以下是我的问候世界.

{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.Trans
import Database.Redis

myConnectInfo :: ConnectInfo
myConnectInfo = defaultConnectInfo { connectPort = UnixSocket "/tmp/redis.sock" }

main :: IO ()
main = do
    conn <- connect myConnectInfo
    runRedis conn $do
        set "hello" "hello"
        set "world" "world"
        hello <- get "hello"
        world <- get "world"
        liftIO $print (hello,world)
我根本不是Haskell用户,我无法测试它,但我会说你必须在这个字符串中提供套接字文件的路径.

代替:

connectPort           = PortNumber 6379

你将会拥有:

connectPort           = UnixSocket "/tmp/redis.sock"

当然,应使用以下参数在服务器端Redis配置文件中声明/tmp/redis.sock:

# Specify the path for the unix socket that will be used to listen for
# incoming connections. There is no default,so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /tmp/redis.sock
unixsocketperm 755

请注意,默认情况下,unix域套接字参数已注释掉.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读