SwiftNIOExtras / swift-nio-redis

A high performance Redis protocol (RESP) implementation for SwiftNIO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use in Vapor project?

vkill opened this issue · comments

commented

Hi

My Vapor project used it's Redis library, that's library name same as this library.

So, how to coexist?

Why would you possibly want to use two Redis libraries? 🤔
And why wouldn't you want to use the included one? 🤔

You can make it work, but it requires you to setup a third helper module with a different name. Essentially you create a "MyXYZ" package, include one of the conflicting packages there, and then re-export the stuff under the new name (do a @_exported import XYZ in MyXYZ). Which you should then be able to import in the main application.

commented

do a @_exported import XYZ in MyXYZ

thanks, I will try it.

commented

Why would you possibly want to use two Redis libraries?

MyLibrary is not remove git package, but I want use swift-nio-redis.

My Package.swift

import PackageDescription

let package = Package(
    name: "QZPrivateBox_api",
    dependencies: [
        .package(url: "https://github.com/apple/swift-nio.git", from: "1.8.0"),
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
        .package(url: "https://github.com/vapor/redis.git", from: "3.0.0-rc"),
        .package(url: "https://github.com/NozeIO/swift-nio-redis.git", .branch("develop")),
    ],
    targets: [
        .target(name: "MyLibrary", dependencies: ["<REDIS>"], path: "Libraries/MyLibrary/Sources"),
        .target(name: "App", dependencies: ["Redis", "Vapor", "MyLibrary"]),
    ]
)

Just drop the

    .package(url: "https://github.com/vapor/redis.git", from: "3.0.0-rc"),

line and you should be done.

commented

Vapor App Package.swift

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "NIOSidekiqExample",
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
        .package(url: "https://github.com/vapor/redis.git", from: "3.0.0-rc.2"),
        .package(url: "https://github.com/user/MyLibrary.git", .branch("master")),
    ],
    targets: [
        .target(name: "App", dependencies: ["Vapor", "Redis", "MyLibrary"]),
        .target(name: "AppRun", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App"])
    ]
)

MyLibrary Package.swift

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
         .package(url: "https://github.com/NozeIO/swift-nio-redis.git", .branch("develop")),
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: ["Redis"]),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]),
    ]
)

When I swift build Vapor App, the error message is 'Redis' /Users/user/path/.build/checkouts/redis.git--22716008034766659: error: multiple targets named 'Redis'

So, I recommend use one library name "NIORedis" and one target name "NIORedis".

Yes, again, drop:

    .package(url: "https://github.com/vapor/redis.git", from: "3.0.0-rc.2"),

Wy do you include it, if you don't want to use it?

commented

Wy do you include it

We need use Vapor Redis In Vapor App.

you don't want to use it?

In library, the Vapor Redis is too heavy.

commented

Can you merge #3 first ?

Hm, sorry, I don't understand any of this. You want to use it, but then you don't want to use it. Just choose one and stick to it.

So, I recommend use one library name "NIORedis" and one target name "NIORedis".

Not going to happen. NIORedis is the protocol implementation and Redis the client. That seems exactly right.

Looking at your Package.swift, that looks right to me. You may want to file an issue against Swift Package Manager, I think this should be supported if it isn't.

commented

You may want to file an issue against Swift Package Manager

Yes, I think this is SPM issue, and the solution status is WIP

commented

NIORedis is the protocol implementation and Redis the client. That seems exactly right.

Yes, you are right.