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

我正在寻找如何使用 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域套接字参数已注释掉.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...